gcloudtracer

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2017 License: BSD-3-Clause Imports: 14 Imported by: 6

README

GoDoc

gcloud-opentracing

OpenTracing Tracer implementation for GCloud StackDriver in Go. Based on basictracer and implemented Recorder for this propose.

Getting Started

To install gcloud-opentracing, use go get:

go get github.com/lovoo/gcloud-opentracing

or govendor:

govendor fetch github.com/lovoo/gcloud-opentracing

or other tool for vendoring.

Sample Usage

First of all, you need to init Global Tracer with GCloud Tracer:

package main

import (
    "log"

    trace "cloud.google.com/go/trace/apiv1"
    gcloudtracer "github.com/lovoo/gcloud-opentracing"
    opentracing "github.com/opentracing/opentracing-go"
    basictracer "github.com/opentracing/basictracer-go"
    "golang.org/x/net/context"
)

func main() {
    // ...
    client, err := trace.NewClient(context.Background() /*auth options here if necessary*/)
    if err != nil {
      log.Fatalf("error creating a tracing client: %v", err)
    }

    recorder, err := gcloudtracer.NewRecorder(context.Background(), "gcp-project-id", client)
    if err != nil {
      log.Fatalf("error creating a recorder: %v", err)
    }
    defer recorder.Close()

    opentracing.InitGlobalTracer(basictracer.New(recorder))
    // ...
}

Then you can create traces as decribed here. More information you can find on OpenTracing project website.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidProjectID occurs if project identifier is invalid.
	ErrInvalidProjectID = errors.New("invalid project id")
)

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Infof(string, ...interface{})
	Errorf(string, ...interface{})
}

Logger defines an interface to log an error.

type Option

type Option func(o *Options)

Option defines an recorder option.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger returns an Option that specifies a logger of the Recorder.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options contains options for recorder.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder implements basictracer.SpanRecorder interface used to write traces to the GCE StackDriver.

func NewRecorder

func NewRecorder(ctx context.Context, projectID string, c TraceClient, opts ...Option) (*Recorder, error)

NewRecorder creates new GCloud StackDriver recorder.

func (*Recorder) Close added in v0.3.0

func (r *Recorder) Close() error

Close flushes all the recorder traces and closes the client.

func (*Recorder) RecordSpan

func (r *Recorder) RecordSpan(sp basictracer.RawSpan)

RecordSpan writes Span to the GCLoud StackDriver.

type TraceClient added in v0.3.0

type TraceClient interface {
	PatchTraces(context.Context, *pb.PatchTracesRequest, ...gax.CallOption) error
	Close() error
}

TraceClient is the interface of the Google StackDriver Trace client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL