-
Notifications
You must be signed in to change notification settings - Fork 5
/
doc.go
51 lines (38 loc) · 1.67 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2020 The Penguin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package tracing helps with the propagation of the tracing span through context
in the system. It does this for operations contained to single node, as well as
across nodes, by injecting special headers.
To use the tracing package, a Tracer instance must be created, which contains
functions for starting new span contexts, injecting them in other data, and
extracting the active span them from the context.
To use the tracing package a Tracer instance must be created:
tracer, tracerCloser, err := tracing.NewTracer(&tracing.Options{
Enabled: true,
Endpoint: "127.0.0.1:6831",
ServiceName: "pen",
})
if err != nil {
// handle error
}
defer tracerCloser.Close()
// ...
The tracer instance contains functions for starting new span contexts, injecting
them in other data, and extracting the active span them from the context:
span, _, ctx := tracer.StartSpanFromContext(ctx, "operation-name", nil)
Once the operation is finished, the open span should be finished:
span.Finish()
The tracing package also provides a function for creating a logger which will
inject a "traceid" field entry to the log line, which helps in finding out which
log lines belong to a specific trace.
To create a logger with trace just wrap an existing logger:
logger := tracing.NewLoggerWithTraceID(ctx, s.logger)
// ...
logger.Info("some message")
Which will result in following log line (if the context contains tracing
information):
time="2015-09-07T08:48:33Z" level=info msg="some message" traceid=ed65818cc1d30c
*/
package tracing