1 # Tracing helper library
3 The library creates a configured tracer instance.
9 Create a tracer instance and set it as a global tracer:
13 "github.com/opentracing/opentracing-go"
14 "gerrit.o-ran-sc.org/ric-plt/tracelibgo/pkg/tracelibgo"
18 tracer, closer := tracelibgo.CreateTracer("my-service-name")
20 opentracing.SetGlobalTracer(tracer)
23 Serialize span context to a byte array that can be sent
24 to another component via some messaging. For example, using
25 the RMR library. The serialization uses JSON format.
28 carrier := make(map[string]string)
29 opentracing.GlobalTracer().Inject(
32 opentracing.TextMapCarrier(carrier))
33 b, err := json.Marshal(carrier) // b is a []byte and contains serilized span context
36 Extract a span context from byte array and create a new child span from it.
37 The serialized span context is got, for example, from the RMR library.
40 var carrier map[string]string
41 err = json.Unmarshal(data, &carrier) // data is []byte containing serialized span context
45 context, err := opentracing.GlobalTracer().Extract(opentracing.TextMap, opentracing.TextMapCarrier(carrier))
49 span := opentracing.GlobalTracer().StartSpan("go test span", opentracing.ChildOf(context))
54 GO111MODULE=on go mod download
55 go test ./pkg/tracelibgo
59 See [LICENSES.txt](LICENSES.txt) file.