• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H14-Nov-2019-

cmd/H14-Nov-2019-

examples/H14-Nov-2019-

lightstep/rand/H14-Nov-2019-

lightstepfakes/H14-Nov-2019-

lightstepoc/H14-Nov-2019-

.gitignoreH A D14-Nov-201933

.gitmodulesH A D14-Nov-2019134

CHANGELOG.mdH A D14-Nov-20194.6 KiB

Gopkg.lockH A D14-Nov-20196.6 KiB

Gopkg.tomlH A D14-Nov-2019523

LICENSEH A D14-Nov-20191 KiB

MakefileH A D14-Nov-2019521

README.mdH A D14-Nov-20194.4 KiB

VERSIONH A D14-Nov-20197

bench_test.goH A D14-Nov-20194.3 KiB

benchmark_test.goH A D14-Nov-2019675

collector_client.goH A D14-Nov-20191.5 KiB

collector_client_custom.goH A D14-Nov-20191 KiB

collector_client_grpc.goH A D14-Nov-20194.1 KiB

collector_client_http.goH A D14-Nov-20195.3 KiB

event_handlers.goH A D14-Nov-20192.5 KiB

event_handlers_test.goH A D14-Nov-20191,014

events.goH A D14-Nov-20197.5 KiB

go.modH A D14-Nov-2019414

go.sumH A D14-Nov-201913.9 KiB

lightstep_tracer_go_suite_test.goH A D14-Nov-2019216

meta_events.goH A D14-Nov-2019699

options.goH A D14-Nov-201911.4 KiB

propagation.goH A D14-Nov-2019327

propagation_b3.goH A D14-Nov-20191.8 KiB

propagation_binary.goH A D14-Nov-20192.6 KiB

propagation_lightstep.goH A D14-Nov-20191.3 KiB

propagation_text.goH A D14-Nov-20192.3 KiB

proto_converter.goH A D14-Nov-20195.8 KiB

proto_logencoder.goH A D14-Nov-20194.9 KiB

proto_logencoder_test.goH A D14-Nov-20194.3 KiB

raw_span.goH A D14-Nov-20192.1 KiB

report_buffer.goH A D14-Nov-20191.8 KiB

span.goH A D14-Nov-20197.2 KiB

tag_version.shH A D14-Nov-2019207

test_utils_test.goH A D14-Nov-20193.3 KiB

tracer.goH A D14-Nov-201912.8 KiB

tracer_0_14.goH A D14-Nov-20191,005

tracer_0_14_test.goH A D14-Nov-20192 KiB

tracer_helpers.goH A D14-Nov-20192.1 KiB

tracer_impl_test.goH A D14-Nov-20193.3 KiB

tracer_test.goH A D14-Nov-201913.6 KiB

tracer_transport_grpc_test.goH A D14-Nov-2019953

tracer_transport_options_test.goH A D14-Nov-2019987

tracer_transport_proto_test.goH A D14-Nov-20191.3 KiB

tracer_transport_test.goH A D14-Nov-201920 KiB

util.goH A D14-Nov-2019814

util_test.goH A D14-Nov-20193 KiB

version.goH A D14-Nov-2019141

README.md

1# lightstep-tracer-go
2
3[![Circle CI](https://circleci.com/gh/lightstep/lightstep-tracer-go.svg?style=shield)](https://circleci.com/gh/lightstep/lightstep-tracer-go)
4[![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
5[![GoDoc](https://godoc.org/github.com/lightstep/lightstep-tracer-go?status.svg)](https://godoc.org/github.com/lightstep/lightstep-tracer-go)
6
7The LightStep distributed tracing library for Go.
8
9**Looking for the LightStep OpenCensus exporter? Check out the [`lightstepoc` package](./lightstepoc).**
10
11## Installation
12
13```
14$ go get 'github.com/lightstep/lightstep-tracer-go'
15```
16
17## API Documentation
18
19Godoc: https://godoc.org/github.com/lightstep/lightstep-tracer-go
20
21## Initialization: Starting a new tracer
22To 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.
23
24```go
25import (
26  "github.com/opentracing/opentracing-go"
27  "github.com/lightstep/lightstep-tracer-go"
28)
29
30func main() {
31  lightstepTracer := lightstep.NewTracer(lightstep.Options{
32    AccessToken: "YourAccessToken",
33  })
34
35  opentracing.SetGlobalTracer(lightstepTracer)
36}
37```
38
39## Instrumenting Code: Using the OpenTracing API
40
41All 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.
42
43- https://godoc.org/github.com/opentracing/opentracing-go
44- http://opentracing.io
45
46## Flushing and Closing: Managing the tracer lifecycle
47
48As 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.
49
50```go
51import (
52  "context"
53  "github.com/opentracing/opentracing-go"
54  "github.com/lightstep/lightstep-tracer-go"
55)
56
57func shutdown(ctx context.Context) {
58  // access the running tracer
59  tracer := opentracing.GlobalTracer()
60
61  // typecast from opentracing.Tracer to lightstep.Tracer
62  lsTracer, ok := tracer.(lightstep.Tracer)
63  if (!ok) {
64    return
65  }
66  lsTracer.Close(ctx)
67
68  // or use static methods
69  lightstep.Close(ctx, tracer)
70}
71```
72
73## Event Handling: Observing the LightStep tracer
74In 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.
75
76```go
77import (
78  "example/logger"
79  "example/metrics"
80  "github.com/lightstep/lightstep-tracer-go"
81)
82
83logAndMetricsHandler := func(event lightstep.Event){
84  switch event := event.(type) {
85  case EventStatusReport:
86    metrics.Count("tracer.dropped_spans", event.DroppedSpans())
87  case ErrorEvent:
88    logger.Error("LS Tracer error: %s", event)
89  default:
90    logger.Info("LS Tracer info: %s", event)
91  }
92}
93
94func main() {
95  // setup event handler first to catch startup errors
96  lightstep.SetGlobalEventHandler(logAndMetricsHandler)
97
98  lightstepTracer := lightstep.NewTracer(lightstep.Options{
99    AccessToken: "YourAccessToken",
100  })
101
102  opentracing.SetGlobalTracer(lightstepTracer)
103}
104```
105
106Event 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.
107
108## Advanced Configuration: Transport and Serialization Protocols
109
110By 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.
111
112There are two options for transport protocols:
113
114- [Protocol Buffers](https://developers.google.com/protocol-buffers/) over HTTP - The recommended and default solution.
115- [Protocol Buffers](https://developers.google.com/protocol-buffers/) over [GRPC](https://grpc.io/) - This is a more advanced solution that might be desirable if you already have gRPC networking configured.
116
117You can configure which transport protocol the tracer uses using the `UseGRPC` and `UseHttp` flags in the options.
118