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

# README

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 SetGlobalEventHandler 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 MetricEventStatusReport:
    metrics.Count("tracer.sent_metrics", event.SentMetrics())
  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.

Release

To make a release, do these steps

  1. Run make ver=X.Y.Z version
  2. Update CHANGELOG.md
  3. Merge changes
  4. Run make release_tag

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Code generated by counterfeiter.
Package lightstepoc provides an OpenCensus exporter for sending OpenCensus spans back to LightStep.

# Functions

Close synchronously flushes the tracer, then terminates it.
CloseTracer closes the tracer DEPRECATED: use Close instead.
CreateTracer creates and starts a new Lightstep Tracer.
Flush forces a synchronous Flush.
FlushLightStepTracer flushes the tracer DEPRECATED: use Flush instead.
GetLightStepAccessToken returns the currently configured AccessToken.
GetLightStepReporterID returns the currently configured Reporter ID.
NewEventChannel returns an SetGlobalEventHandler callback handler, and a channel that produces the errors.
NewEventLogger logs events using the standard go logger.
NewEventLogOneError logs the first error event that occurs.
NewTracer creates and starts a new Lightstep Tracer.
NewTracerv0_14 returns a tracer which conforms to the Tracer interface from v0.14.0, for backwards compatibility.
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.
NOTE: these will be deprecated in favour of the constants package.
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.
Default Option values.
Default Option values.
Constant strings corresponding to flush errors.
Constant strings corresponding to flush errors.
Constant strings corresponding to flush errors.
Constant strings corresponding to flush errors.
Constant strings corresponding to flush errors.
<- runtime guid, not span guid.
NOTE: these will be deprecated in favour of the constants package.
operation names for ls meta span events.
No description provided by the author
keys for ls meta span events.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ParentSpanGUIDKey is the tag key used to record the relationship between child and parent spans.
NOTE: these will be deprecated in favour of the constants package.
Tag and Tracer Attribute keys.
Tag and Tracer Attribute keys.
Tag and Tracer Attribute keys.
Note: TracerVersionValue is generated from ./VERSION.
TracerVersionValue provides the current version of the lightstep-tracer-go release.

# Variables

B3Propagator propagates context in the b3 format.
BinaryPropagator propagates context in binary format.
LightStepPropagator propagates context in the LightStep format.

# Structs

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

# Interfaces

Collector encapsulates custom transport of protobuf messages.
Connection describes a closable connection.
The ErrorEvent type can be used to filter events.
An Event is 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.
A EventMissingService occurs when a tracer is initialized without a service name.
EventStartError occurs if the Options passed to NewTracer are invalid, and the Tracer has failed to start.
EventStatusReport occurs on every successful flush.
No description provided by the author
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.
MetricEventStatusReport occurs every time metrics are sent successfully.
Propagator provides the ability to inject/extract different formats of span information.
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.
Tracerv0_14 matches the Tracer interface from v0.14.0 DEPRECATED.

# Type aliases

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