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

..03-May-2022-

.github/H30-Apr-2021-215153

config/H30-Apr-2021-2,0511,476

crossdock/H30-Apr-2021-3,4322,728

idl/H30-Apr-2021-

internal/H30-Apr-2021-1,389957

log/H30-Apr-2021-1,414936

metrics/prometheus/H30-Apr-2021-3715

rpcmetrics/H30-Apr-2021-802519

scripts/H30-Apr-2021-11176

testutils/H30-Apr-2021-512333

thrift/H30-Apr-2021-3,8702,916

thrift-gen/H30-Apr-2021-6,5625,644

transport/H30-Apr-2021-891606

travis/H30-Apr-2021-3720

utils/H30-Apr-2021-1,5711,021

x/H30-Apr-2021-729490

zipkin/H30-Apr-2021-424316

.gitignoreH A D30-Apr-2021150 1615

.gitmodulesH A D30-Apr-202176 43

.travis.ymlH A D30-Apr-20212.6 KiB5747

CHANGELOG.mdH A D30-Apr-202113.3 KiB376241

CODEOWNERSH A D30-Apr-202137 31

CONTRIBUTING.mdH A D30-Apr-20215.7 KiB171127

DCOH A D30-Apr-20211.4 KiB3827

Gopkg.lockH A D30-Apr-20218.2 KiB302275

Gopkg.tomlH A D30-Apr-2021568 3224

LICENSEH A D30-Apr-202111.1 KiB202169

MakefileH A D30-Apr-20214 KiB135107

README.mdH A D30-Apr-202115.1 KiB325254

RELEASE.mdH A D30-Apr-2021644 1311

baggage_setter.goH A D30-Apr-20212.4 KiB7854

baggage_setter_test.goH A D30-Apr-20213.9 KiB12693

constants.goH A D30-Apr-20214.1 KiB10732

constants_test.goH A D30-Apr-20211,020 3013

contrib_observer.goH A D30-Apr-20212.2 KiB5719

doc.goH A D30-Apr-2021938 251

glide.lockH A D30-Apr-20212.9 KiB106105

glide.yamlH A D30-Apr-2021714 3130

header.goH A D30-Apr-20212.7 KiB6630

header_test.goH A D30-Apr-20211.8 KiB5131

interop.goH A D30-Apr-20211.5 KiB5629

jaeger_tag.goH A D30-Apr-20212.5 KiB8553

jaeger_thrift_span.goH A D30-Apr-20215 KiB182152

jaeger_thrift_span_test.goH A D30-Apr-202114.8 KiB425380

logger.goH A D30-Apr-20211.7 KiB5418

logger_test.goH A D30-Apr-20211.1 KiB4121

metrics.goH A D30-Apr-20216.9 KiB12042

metrics_test.goH A D30-Apr-20211.4 KiB4828

observer.goH A D30-Apr-20212.8 KiB8951

observer_test.goH A D30-Apr-20212.8 KiB11080

process.goH A D30-Apr-20211,013 309

propagation.goH A D30-Apr-202110.4 KiB326242

propagation_test.goH A D30-Apr-202111.9 KiB342270

reference.goH A D30-Apr-2021834 246

reporter.goH A D30-Apr-20219.8 KiB323207

reporter_options.goH A D30-Apr-20212.4 KiB7233

reporter_test.goH A D30-Apr-202111.9 KiB391324

sampler.goH A D30-Apr-202118.1 KiB517338

sampler_remote.goH A D30-Apr-202110.9 KiB359252

sampler_remote_options.goH A D30-Apr-20215.2 KiB160106

sampler_remote_test.goH A D30-Apr-202120 KiB602492

sampler_test.goH A D30-Apr-202114.6 KiB425349

sampler_v2.goH A D30-Apr-20213.2 KiB9450

sampler_v2_test.goH A D30-Apr-20218.4 KiB226171

span.goH A D30-Apr-202113.2 KiB504345

span_allocator.goH A D30-Apr-20211.4 KiB5729

span_allocator_test.goH A D30-Apr-20211.2 KiB4929

span_context.goH A D30-Apr-202112.1 KiB419275

span_context_test.goH A D30-Apr-20216.6 KiB235202

span_test.goH A D30-Apr-202111.5 KiB415344

tracer.goH A D30-Apr-202114.3 KiB494382

tracer_bench_test.goH A D30-Apr-20215.4 KiB199152

tracer_options.goH A D30-Apr-20215.7 KiB183119

tracer_test.goH A D30-Apr-202116.9 KiB521430

transport.goH A D30-Apr-20211.5 KiB399

transport_udp.goH A D30-Apr-20216 KiB194135

transport_udp_test.goH A D30-Apr-20218.5 KiB279225

zipkin.goH A D30-Apr-20212.3 KiB7850

zipkin_test.goH A D30-Apr-20212.6 KiB6944

zipkin_thrift_span.goH A D30-Apr-20219.4 KiB330271

zipkin_thrift_span_test.goH A D30-Apr-202110.8 KiB392340

README.md

1[![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![OpenTracing 1.0 Enabled][ot-img]][ot-url]
2
3# Jaeger Bindings for Go OpenTracing API
4
5Instrumentation library that implements an
6[OpenTracing Go](https://github.com/opentracing/opentracing-go) Tracer for Jaeger (https://jaegertracing.io).
7
8**IMPORTANT**: The library's import path is based on its original location under `github.com/uber`. Do not try to import it as `github.com/jaegertracing`, it will not compile. We might revisit this in the next major release.
9  * :white_check_mark: `import "github.com/uber/jaeger-client-go"`
10  * :x: `import "github.com/jaegertracing/jaeger-client-go"`
11
12## How to Contribute
13
14Please see [CONTRIBUTING.md](CONTRIBUTING.md).
15
16## Installation
17
18We recommended using a dependency manager like [dep](https://golang.github.io/dep/)
19and [semantic versioning](http://semver.org/) when including this library into an application.
20For example, Jaeger backend imports this library like this:
21
22```toml
23[[constraint]]
24  name = "github.com/uber/jaeger-client-go"
25  version = "2.17"
26```
27
28If you instead want to use the latest version in `master`, you can pull it via `go get`.
29Note that during `go get` you may see build errors due to incompatible dependencies, which is why
30we recommend using semantic versions for dependencies.  The error  may be fixed by running
31`make install` (it will install `dep` if you don't have it):
32
33```shell
34go get -u github.com/uber/jaeger-client-go/
35cd $GOPATH/src/github.com/uber/jaeger-client-go/
36git submodule update --init --recursive
37make install
38```
39
40## Initialization
41
42See tracer initialization examples in [godoc](https://godoc.org/github.com/uber/jaeger-client-go/config#pkg-examples)
43and [config/example_test.go](./config/example_test.go).
44
45### Environment variables
46
47The tracer can be initialized with values coming from environment variables, if it is
48[built from a config](https://pkg.go.dev/github.com/uber/jaeger-client-go/config?tab=doc#Configuration.NewTracer)
49that was created via [FromEnv()](https://pkg.go.dev/github.com/uber/jaeger-client-go/config?tab=doc#FromEnv).
50None of the env vars are required and all of them can be overridden via direct setting
51of the property on the configuration object.
52
53Property| Description
54--- | ---
55JAEGER_SERVICE_NAME | The service name.
56JAEGER_AGENT_HOST | The hostname for communicating with agent via UDP (default `localhost`).
57JAEGER_AGENT_PORT | The port for communicating with agent via UDP (default `6831`).
58JAEGER_ENDPOINT | The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. If specified, the agent host/port are ignored.
59JAEGER_USER | Username to send as part of "Basic" authentication to the collector endpoint.
60JAEGER_PASSWORD | Password to send as part of "Basic" authentication to the collector endpoint.
61JAEGER_REPORTER_LOG_SPANS | Whether the reporter should also log the spans" `true` or `false` (default `false`).
62JAEGER_REPORTER_MAX_QUEUE_SIZE | The reporter's maximum queue size (default `100`).
63JAEGER_REPORTER_FLUSH_INTERVAL | The reporter's flush interval, with units, e.g. `500ms` or `2s` ([valid units][timeunits]; default `1s`).
64JAEGER_REPORTER_ATTEMPT_RECONNECTING_DISABLED | When true, disables udp connection helper that periodically re-resolves the agent's hostname and reconnects if there was a change (default `false`).
65JAEGER_REPORTER_ATTEMPT_RECONNECT_INTERVAL | Controls how often the agent client re-resolves the provided hostname in order to detect address changes ([valid units][timeunits]; default `30s`).
66JAEGER_SAMPLER_TYPE | The sampler type: `remote`, `const`, `probabilistic`, `ratelimiting` (default `remote`). See also https://www.jaegertracing.io/docs/latest/sampling/.
67JAEGER_SAMPLER_PARAM | The sampler parameter (number).
68JAEGER_SAMPLER_MANAGER_HOST_PORT | (deprecated) The HTTP endpoint when using the `remote` sampler.
69JAEGER_SAMPLING_ENDPOINT | The URL for the sampling configuration server when using sampler type `remote` (default `http://127.0.0.1:5778/sampling`).
70JAEGER_SAMPLER_MAX_OPERATIONS | The maximum number of operations that the sampler will keep track of (default `2000`).
71JAEGER_SAMPLER_REFRESH_INTERVAL | How often the `remote` sampler should poll the configuration server for the appropriate sampling strategy, e.g. "1m" or "30s" ([valid units][timeunits]; default `1m`).
72JAEGER_TAGS | A comma separated list of `name=value` tracer-level tags, which get added to all reported spans. The value can also refer to an environment variable using the format `${envVarName:defaultValue}`.
73JAEGER_DISABLED | Whether the tracer is disabled or not. If `true`, the `opentracing.NoopTracer` is used (default `false`).
74JAEGER_RPC_METRICS | Whether to store RPC metrics, `true` or `false` (default `false`).
75
76By default, the client sends traces via UDP to the agent at `localhost:6831`. Use `JAEGER_AGENT_HOST` and
77`JAEGER_AGENT_PORT` to send UDP traces to a different `host:port`. If `JAEGER_ENDPOINT` is set, the client sends traces
78to the endpoint via `HTTP`, making the `JAEGER_AGENT_HOST` and `JAEGER_AGENT_PORT` unused. If `JAEGER_ENDPOINT` is
79secured, HTTP basic authentication can be performed by setting the `JAEGER_USER` and `JAEGER_PASSWORD` environment
80variables.
81
82### Closing the tracer via `io.Closer`
83
84The constructor function for Jaeger Tracer returns the tracer itself and an `io.Closer` instance.
85It is recommended to structure your `main()` so that it calls the `Close()` function on the closer
86before exiting, e.g.
87
88```go
89tracer, closer, err := cfg.NewTracer(...)
90defer closer.Close()
91```
92
93This is especially useful for command-line tools that enable tracing, as well as
94for the long-running apps that support graceful shutdown. For example, if your deployment
95system sends SIGTERM instead of killing the process and you trap that signal to do a graceful
96exit, then having `defer closer.Close()` ensures that all buffered spans are flushed.
97
98### Metrics & Monitoring
99
100The tracer emits a number of different metrics, defined in
101[metrics.go](metrics.go). The monitoring backend is expected to support
102tag-based metric names, e.g. instead of `statsd`-style string names
103like `counters.my-service.jaeger.spans.started.sampled`, the metrics
104are defined by a short name and a collection of key/value tags, for
105example: `name:jaeger.traces, state:started, sampled:y`. See [metrics.go](./metrics.go)
106file for the full list and descriptions of emitted metrics.
107
108The monitoring backend is represented by the `metrics.Factory` interface from package
109[`"github.com/uber/jaeger-lib/metrics"`](https://github.com/jaegertracing/jaeger-lib/tree/master/metrics).  An implementation
110of that interface can be passed as an option to either the Configuration object or the Tracer
111constructor, for example:
112
113```go
114import (
115    "github.com/uber/jaeger-client-go/config"
116    "github.com/uber/jaeger-lib/metrics/prometheus"
117)
118
119    metricsFactory := prometheus.New()
120    tracer, closer, err := config.Configuration{
121        ServiceName: "your-service-name",
122    }.NewTracer(
123        config.Metrics(metricsFactory),
124    )
125```
126
127By default, a no-op `metrics.NullFactory` is used.
128
129### Logging
130
131The tracer can be configured with an optional logger, which will be
132used to log communication errors, or log spans if a logging reporter
133option is specified in the configuration. The logging API is abstracted
134by the [Logger](logger.go) interface. A logger instance implementing
135this interface can be set on the `Config` object before calling the
136`New` method.
137
138Besides the [zap](https://github.com/uber-go/zap) implementation
139bundled with this package there is also a [go-kit](https://github.com/go-kit/kit)
140one in the [jaeger-lib](https://github.com/jaegertracing/jaeger-lib) repository.
141
142## Instrumentation for Tracing
143
144Since this tracer is fully compliant with OpenTracing API 1.0,
145all code instrumentation should only use the API itself, as described
146in the [opentracing-go](https://github.com/opentracing/opentracing-go) documentation.
147
148## Features
149
150### Reporters
151
152A "reporter" is a component that receives the finished spans and reports
153them to somewhere. Under normal circumstances, the Tracer
154should use the default `RemoteReporter`, which sends the spans out of
155process via configurable "transport". For testing purposes, one can
156use an `InMemoryReporter` that accumulates spans in a buffer and
157allows to retrieve them for later verification. Also available are
158`NullReporter`, a no-op reporter that does nothing, a `LoggingReporter`
159which logs all finished spans using their `String()` method, and a
160`CompositeReporter` that can be used to combine more than one reporter
161into one, e.g. to attach a logging reporter to the main remote reporter.
162
163### Span Reporting Transports
164
165The remote reporter uses "transports" to actually send the spans out
166of process. Currently the supported transports include:
167  * [Jaeger Thrift](https://github.com/jaegertracing/jaeger-idl/blob/master/thrift/agent.thrift) over UDP or HTTP,
168  * [Zipkin Thrift](https://github.com/jaegertracing/jaeger-idl/blob/master/thrift/zipkincore.thrift) over HTTP.
169
170### Sampling
171
172The tracer does not record all spans, but only those that have the
173sampling bit set in the `flags`. When a new trace is started and a new
174unique ID is generated, a sampling decision is made whether this trace
175should be sampled. The sampling decision is propagated to all downstream
176calls via the `flags` field of the trace context. The following samplers
177are available:
178  1. `RemotelyControlledSampler` uses one of the other simpler samplers
179     and periodically updates it by polling an external server. This
180     allows dynamic control of the sampling strategies.
181  1. `ConstSampler` always makes the same sampling decision for all
182     trace IDs. it can be configured to either sample all traces, or
183     to sample none.
184  1. `ProbabilisticSampler` uses a fixed sampling rate as a probability
185     for a given trace to be sampled. The actual decision is made by
186     comparing the trace ID with a random number multiplied by the
187     sampling rate.
188  1. `RateLimitingSampler` can be used to allow only a certain fixed
189     number of traces to be sampled per second.
190
191#### Delayed sampling
192
193Version 2.20 introduced the ability to delay sampling decisions in the life cycle
194of the root span. It involves several features and architectural changes:
195  * **Shared sampling state**: the sampling state is shared across all local
196    (i.e. in-process) spans for a given trace.
197  * **New `SamplerV2` API** allows the sampler to be called at multiple points
198    in the life cycle of a span:
199    * on span creation
200    * on overwriting span operation name
201    * on setting span tags
202    * on finishing the span
203  * **Final/non-final sampling state**: the new `SamplerV2` API allows the sampler
204    to indicate if the negative sampling decision is final or not (positive sampling
205    decisions are always final). If the decision is not final, the sampler will be
206    called again on further span life cycle events, like setting tags.
207
208These new features are used in the experimental `x.TagMatchingSampler`, which
209can sample a trace based on a certain tag added to the root
210span or one of its local (in-process) children. The sampler can be used with
211another experimental `x.PrioritySampler` that allows multiple samplers to try
212to make a sampling decision, in a certain priority order.
213
214### Baggage Injection
215
216The OpenTracing spec allows for [baggage][baggage], which are key value pairs that are added
217to the span context and propagated throughout the trace. An external process can inject baggage
218by setting the special HTTP Header `jaeger-baggage` on a request:
219
220```sh
221curl -H "jaeger-baggage: key1=value1, key2=value2" http://myhost.com
222```
223
224Baggage can also be programatically set inside your service:
225
226```go
227if span := opentracing.SpanFromContext(ctx); span != nil {
228    span.SetBaggageItem("key", "value")
229}
230```
231
232Another service downstream of that can retrieve the baggage in a similar way:
233
234```go
235if span := opentracing.SpanFromContext(ctx); span != nil {
236    val := span.BaggageItem("key")
237    println(val)
238}
239```
240
241### Debug Traces (Forced Sampling)
242
243#### Programmatically
244
245The OpenTracing API defines a `sampling.priority` standard tag that
246can be used to affect the sampling of a span and its children:
247
248```go
249import (
250    "github.com/opentracing/opentracing-go"
251    "github.com/opentracing/opentracing-go/ext"
252)
253
254span := opentracing.SpanFromContext(ctx)
255ext.SamplingPriority.Set(span, 1)
256```
257
258#### Via HTTP Headers
259
260Jaeger Tracer also understands a special HTTP Header `jaeger-debug-id`,
261which can be set in the incoming request, e.g.
262
263```sh
264curl -H "jaeger-debug-id: some-correlation-id" http://myhost.com
265```
266
267When Jaeger sees this header in the request that otherwise has no
268tracing context, it ensures that the new trace started for this
269request will be sampled in the "debug" mode (meaning it should survive
270all downsampling that might happen in the collection pipeline), and the
271root span will have a tag as if this statement was executed:
272
273```go
274span.SetTag("jaeger-debug-id", "some-correlation-id")
275```
276
277This allows using Jaeger UI to find the trace by this tag.
278
279### Zipkin HTTP B3 compatible header propagation
280
281Jaeger Tracer supports Zipkin B3 Propagation HTTP headers, which are used
282by a lot of Zipkin tracers. This means that you can use Jaeger in conjunction with e.g. [these OpenZipkin tracers](https://github.com/openzipkin).
283
284However it is not the default propagation format, see [here](zipkin/README.md#NewZipkinB3HTTPHeaderPropagator) how to set it up.
285
286## SelfRef
287
288Jaeger Tracer supports an additional [span reference][] type call `Self`, which was proposed
289to the OpenTracing Specification (https://github.com/opentracing/specification/issues/81)
290but not yet accepted. This allows the caller to provide an already created `SpanContext`
291when starting a new span. The `Self` reference bypasses trace and span id generation,
292as well as sampling decisions (i.e. the sampling bit in the `SpanContext.flags` must be
293set appropriately by the caller).
294
295The `Self` reference supports the following use cases:
296  * the ability to provide externally generated trace and span IDs
297  * appending data to the same span from different processes, such as loading and continuing spans/traces from offline (ie log-based) storage
298
299Usage requires passing in a `SpanContext` and the `jaeger.Self` reference type:
300```
301span := tracer.StartSpan(
302    "continued_span",
303    jaeger.SelfRef(yourSpanContext),
304)
305...
306defer span.Finish()
307```
308
309## License
310
311[Apache 2.0 License](LICENSE).
312
313
314[doc-img]: https://godoc.org/github.com/uber/jaeger-client-go?status.svg
315[doc]: https://godoc.org/github.com/uber/jaeger-client-go
316[ci-img]: https://travis-ci.org/jaegertracing/jaeger-client-go.svg?branch=master
317[ci]: https://travis-ci.org/jaegertracing/jaeger-client-go
318[cov-img]: https://codecov.io/gh/jaegertracing/jaeger-client-go/branch/master/graph/badge.svg
319[cov]: https://codecov.io/gh/jaegertracing/jaeger-client-go
320[ot-img]: https://img.shields.io/badge/OpenTracing--1.0-enabled-blue.svg
321[ot-url]: http://opentracing.io
322[baggage]: https://github.com/opentracing/specification/blob/master/specification.md#set-a-baggage-item
323[timeunits]: https://golang.org/pkg/time/#ParseDuration
324[span reference]: https://github.com/opentracing/specification/blob/1.1/specification.md#references-between-spans
325