Categorygithub.com/underarmour/lightstep-tracer-go
modulepackage
0.15.1
Repository: https://github.com/underarmour/lightstep-tracer-go.git
Documentation: pkg.go.dev

# README

lightstep-tracer-go

Circle CI MIT license GoDoc

The LightStep distributed tracing library for Go.

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. Regsiter the tracer as the OpenTracing global tracer so that it will become available to your installed intstrumentations 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 managaing 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.OnEvent(logAndMetricsHandler)
  
  lightstepTracer := lightstep.NewTracer(lightstep.Options{
    AccessToken: "YourAccessToken",
  })

  opentracing.SetGlobalTracer(lightstepTracer)
}

Event handlers will recieve 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.

# Packages

No description provided by the author
Package collectorpb is a generated protocol buffer package.
No description provided by the author
No description provided by the author
Code generated by counterfeiter.
Package lightsteppb is a generated protocol buffer package.
No description provided by the author

# Functions

CloseTracer synchronously flushes the tracer, then terminates it.
DEPRECATED: use Close instead.
Flush forces a synchronous Flush.
DEPRECATED: use Flush instead.
GetLightStepAccessToken returns the currently configured AccessToken.
NewChannelOnEvent returns an SetGlobalEventHandler callback handler, and a channel that produces the errors.
NewOnEventLogger logs events using the standard go logger.
NewOnEventLogOneError logs the first error event that occurs.
NewTracer creates and starts a new Lightstep Tracer.
DEPRECATED: For backwards compatibility, NewTracerv0_14 returns a tracer which conforms to the Tracer interface from v0.14.0.
SetGlobalEventHandler sets a global handler to receive tracer events as they occur.

# Constants

BinaryCarrier is used as the format parameter in inject/extract for lighstep binary propagation.
Tag and Tracer Attribute keys.
Tag and Tracer Attribute keys.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
Default Option values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
<- runtime guid, not span guid.
Tag and Tracer Attribute keys.
ParentSpanGUIDKey is the tag key used to record the relationship between child and parent spans.
Tag and Tracer Attribute keys.
Tag and Tracer Attribute keys.
Tag and Tracer Attribute keys.
Note: TracerVersionValue is generated from ./VERSION.
No description provided by the author

# Structs

Endpoint describes a collector or web API host/port and whether or not to use plaintext communication.
No description provided by the author
Options control how the LightStep Tracer behaves.
RawSpan encapsulates all state associated with a (finished) LightStep Span.
SpanContext holds lightstep-specific Span metadata.

# Interfaces

Connection describes a closable connection.
The ErrorEvent type can be used to filter events.
Events are emitted by the LightStep tracer as a reporting mechanism.
EventConnectionError occurs when the tracer fails to maintain it's connection with the Collector.
EventFlushError occurs when a flush fails to send.
EventStartError occurs if the Options passed to NewTracer are invalid, and the Tracer has failed to start.
EventStatusReport occurs on every successful flush.
EventTracerDisabled occurs when a tracer is disabled by either the user or the collector.
EventUnsupportedTracer occurs when a tracer being passed to a helper function fails to typecast as a LightStep tracer.
EventUnsupportedValue occurs when a tracer encounters an unserializable tag or log field.
A SpanRecorder handles all of the `RawSpan` data generated via an associated `Tracer` instance.
Tracer extends the `opentracing.Tracer` interface with methods for manual flushing and closing.
DEPRECATED: Tracerv0_14 matches the Tracer interface from v0.14.0.

# Type aliases

ConnectorFactory is for testing purposes.
EventFlushErrorState lists the possible causes for a flush to fail.
An OnEventHandler can be registered with SetGlobalEventHandler to.
SetParentSpanID is an opentracing.StartSpanOption that sets an explicit parent SpanID.
SetSpanID is a opentracing.StartSpanOption that sets an explicit SpanID.
SetTraceID is an opentracing.StartSpanOption that sets an explicit TraceID.