You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ulric Qin 70e2cefd98
go mod vendor
4 years ago
..
lightstep/rand go mod vendor 4 years ago
.gitignore go mod vendor 4 years ago
.gitmodules go mod vendor 4 years ago
CHANGELOG.md go mod vendor 4 years ago
Gopkg.lock go mod vendor 4 years ago
Gopkg.toml go mod vendor 4 years ago
LICENSE go mod vendor 4 years ago
Makefile go mod vendor 4 years ago
README.md go mod vendor 4 years ago
VERSION go mod vendor 4 years ago
collector_client.go go mod vendor 4 years ago
collector_client_custom.go go mod vendor 4 years ago
collector_client_grpc.go go mod vendor 4 years ago
collector_client_http.go go mod vendor 4 years ago
event_handlers.go go mod vendor 4 years ago
events.go go mod vendor 4 years ago
go.mod go mod vendor 4 years ago
go.sum go mod vendor 4 years ago
meta_events.go go mod vendor 4 years ago
options.go go mod vendor 4 years ago
propagation.go go mod vendor 4 years ago
propagation_b3.go go mod vendor 4 years ago
propagation_binary.go go mod vendor 4 years ago
propagation_lightstep.go go mod vendor 4 years ago
propagation_stack.go go mod vendor 4 years ago
propagation_text.go go mod vendor 4 years ago
proto_converter.go go mod vendor 4 years ago
proto_logencoder.go go mod vendor 4 years ago
raw_span.go go mod vendor 4 years ago
report_buffer.go go mod vendor 4 years ago
span.go go mod vendor 4 years ago
tag_version.sh go mod vendor 4 years ago
tracer.go go mod vendor 4 years ago
tracer_0_14.go go mod vendor 4 years ago
tracer_helpers.go go mod vendor 4 years ago
util.go go mod vendor 4 years ago
version.go go mod vendor 4 years ago

README.md

lightstep-tracer-go

Circle CI MIT license GoDoc

The LightStep distributed tracing library for Go.

Looking for the LightStep OpenCensus exporter? Check out the lightstepoc package.

Installation

$ go get 'github.com/lightstep/lightstep-tracer-go'

API Documentation

Godoc: https://godoc.org/github.com/lightstep/lightstep-tracer-go

Initialization: Starting a new tracer

To initialize a tracer, configure it with a valid Access Token and optional tuning parameters. Register the tracer as the OpenTracing global tracer so that it will become available to your installed instrumentation libraries.

import (
  "github.com/opentracing/opentracing-go"
  "github.com/lightstep/lightstep-tracer-go"
)

func main() {
  lightstepTracer := lightstep.NewTracer(lightstep.Options{
    AccessToken: "YourAccessToken",
  })

  opentracing.SetGlobalTracer(lightstepTracer)
}

Instrumenting Code: Using the OpenTracing API

All instrumentation should be done through the OpenTracing API, rather than using the lightstep tracer type directly. For API documentation and advice on instrumentation in general, see the opentracing godocs and the opentracing website.

Flushing and Closing: Managing the tracer lifecycle

As part of managing your application lifecycle, the lightstep tracer extends the opentracing.Tracer interface with methods for manual flushing and closing. To access these methods, you can take the global tracer and typecast it to a lightstep.Tracer. As a convenience, the lightstep package provides static methods which perform the typecasting.

import (
  "context"
  "github.com/opentracing/opentracing-go"
  "github.com/lightstep/lightstep-tracer-go"
)

func shutdown(ctx context.Context) {
  // access the running tracer
  tracer := opentracing.GlobalTracer()
    
  // typecast from opentracing.Tracer to lightstep.Tracer
  lsTracer, ok := tracer.(lightstep.Tracer)
  if (!ok) { 
    return 
  }
  lsTracer.Close(ctx)

  // or use static methods
  lightstep.Close(ctx, tracer)
}

Event Handling: Observing the LightStep tracer

In order to connect diagnostic information from the lightstep tracer into an application's logging and metrics systems, inject an event handler using the OnEvent static method. Events may be typecast to check for errors or specific events such as status reports.

import (
  "example/logger"
  "example/metrics"
  "github.com/lightstep/lightstep-tracer-go"
)

logAndMetricsHandler := func(event lightstep.Event){
  switch event := event.(type) {
  case EventStatusReport:
    metrics.Count("tracer.dropped_spans", event.DroppedSpans())
  case ErrorEvent:
    logger.Error("LS Tracer error: %s", event)
  default:
    logger.Info("LS Tracer info: %s", event)
  }
}

func main() {
  // setup event handler first to catch startup errors
  lightstep.SetGlobalEventHandler(logAndMetricsHandler)
  
  lightstepTracer := lightstep.NewTracer(lightstep.Options{
    AccessToken: "YourAccessToken",
  })

  opentracing.SetGlobalTracer(lightstepTracer)
}

Event handlers will receive events from any active tracers, as well as errors in static functions. It is suggested that you set up event handling before initializing your tracer to catch any errors on initialization.

Advanced Configuration: Transport and Serialization Protocols

By following the above configuration, the tracer will send information to LightStep using HTTP and Protocol Buffers which is the recommended configuration. If there are no specific transport protocol needs you have, there is no need to change this default.

There are two options for transport protocols:

  • Protocol Buffers over HTTP - The recommended and default solution.
  • Protocol Buffers over GRPC - This is a more advanced solution that might be desirable if you already have gRPC networking configured.

You can configure which transport protocol the tracer uses using the UseGRPC and UseHttp flags in the options.