1 # Tracing helper library
3 The library creates a configured tracer instance.
8 Create a tracer instance and set it as a global tracer:
12 "github.com/opentracing/opentracing-go"
13 "gerrit.o-ran-sc.org/ric-plt/tracelibgo/pkg/tracelibgo"
17 tracer, closer := tracelibgo.CreateTracer("my-service-name")
19 opentracing.SetGlobalTracer(tracer)
22 Serialize span context to a byte array that can be sent
23 to another component via some messaging. For example, using
24 the RMR library. The serialization uses JSON format.
27 carrier := make(map[string]string)
28 opentracing.GlobalTracer().Inject(
31 opentracing.TextMapCarrier(carrier))
32 b, err := json.Marshal(carrier) // b is a []byte and contains serilized span context
35 Extract a span context from byte array and create a new child span from it.
36 The serialized span context is got, for example, from the RMR library.
39 var carrier map[string]string
40 err = json.Unmarshal(data, &carrier) // data is []byte containing serialized span context
44 context, err := opentracing.GlobalTracer().Extract(opentracing.TextMap, opentracing.TextMapCarrier(carrier))
48 span := opentracing.GlobalTracer().StartSpan("go test span", opentracing.ChildOf(context))
53 The trace library currently supports only [Jaeger](https://www.jaegertracing.io/) [golang client](https://github.com/jaegertracing/jaeger-client-go) tracer implementation.
54 The configuration is done using environment variables:
56 | environment variable | values | default |
57 | ---------------------------- |------------------------------------ | -------------- |
58 | TRACING_ENABLED | 1, true, 0, false | false |
59 | TRACING_JAEGER_SAMPLER_TYPE | const, propabilistic, ratelimiting | const |
60 | TRACING_JAEGER_SAMPLER_PARAM | float | 0.001 |
61 | TRACING_JAEGER_AGENT_ADDR | IP addr[:port] | 127.0.0.1:6831 |
62 | TRACING_JAEGER_LOG_LEVEL | all, error, none | none |
64 Meaning of the configuration variables is described in Jaeger web pages.
65 By default a no-op tracer is created.
70 GO111MODULE=on go mod download
71 go test ./pkg/tracelibgo
75 See [LICENSES.txt](LICENSES.txt) file.