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

..03-May-2022-

.circleci/H14-Nov-2019-2320

cmd/H14-Nov-2019-296249

examples/H14-Nov-2019-152113

lightstep/rand/H14-Nov-2019-280207

lightstepfakes/H14-Nov-2019-6958

lightstepoc/H14-Nov-2019-302206

.gitignoreH A D14-Nov-201933 74

.gitmodulesH A D14-Nov-2019134 43

CHANGELOG.mdH A D14-Nov-20194.6 KiB7658

Gopkg.lockH A D14-Nov-20196.6 KiB259242

Gopkg.tomlH A D14-Nov-2019523 2821

LICENSEH A D14-Nov-20191 KiB2217

MakefileH A D14-Nov-2019521 2816

README.mdH A D14-Nov-20194.4 KiB11885

VERSIONH A D14-Nov-20197 21

bench_test.goH A D14-Nov-20194.3 KiB183155

benchmark_test.goH A D14-Nov-2019675 3529

collector_client.goH A D14-Nov-20191.5 KiB6042

collector_client_custom.goH A D14-Nov-20191 KiB4232

collector_client_grpc.goH A D14-Nov-20194.1 KiB158126

collector_client_http.goH A D14-Nov-20195.3 KiB200152

event_handlers.goH A D14-Nov-20192.5 KiB9857

event_handlers_test.goH A D14-Nov-20191,014 5444

events.goH A D14-Nov-20197.5 KiB331240

go.modH A D14-Nov-2019414 1512

go.sumH A D14-Nov-201913.9 KiB145144

lightstep_tracer_go_suite_test.goH A D14-Nov-2019216 1410

meta_events.goH A D14-Nov-2019699 1611

options.goH A D14-Nov-201911.4 KiB348206

propagation.goH A D14-Nov-2019327 116

propagation_b3.goH A D14-Nov-20191.8 KiB8266

propagation_binary.goH A D14-Nov-20192.6 KiB11298

propagation_lightstep.goH A D14-Nov-20191.3 KiB5846

propagation_text.goH A D14-Nov-20192.3 KiB11195

proto_converter.goH A D14-Nov-20195.8 KiB192169

proto_logencoder.goH A D14-Nov-20194.9 KiB156126

proto_logencoder_test.goH A D14-Nov-20194.3 KiB170133

raw_span.goH A D14-Nov-20192.1 KiB8041

report_buffer.goH A D14-Nov-20191.8 KiB8060

span.goH A D14-Nov-20197.2 KiB303226

tag_version.shH A D14-Nov-2019207 116

test_utils_test.goH A D14-Nov-20193.3 KiB11593

tracer.goH A D14-Nov-201912.8 KiB450312

tracer_0_14.goH A D14-Nov-20191,005 4628

tracer_0_14_test.goH A D14-Nov-20192 KiB7962

tracer_helpers.goH A D14-Nov-20192.1 KiB8467

tracer_impl_test.goH A D14-Nov-20193.3 KiB122100

tracer_test.goH A D14-Nov-201913.6 KiB561434

tracer_transport_grpc_test.goH A D14-Nov-2019953 3023

tracer_transport_options_test.goH A D14-Nov-2019987 5437

tracer_transport_proto_test.goH A D14-Nov-20191.3 KiB5947

tracer_transport_test.goH A D14-Nov-201920 KiB627518

util.goH A D14-Nov-2019814 3322

util_test.goH A D14-Nov-20193 KiB130110

version.goH A D14-Nov-2019141 52

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