First version of the tracing library
[ric-plt/tracelibgo.git] / README.md
1 # Tracing helper library
2
3 The library creates a configured tracer instance.
4
5 ToDO: configuration...
6
7 ## Usage
8
9 Create a tracer instance and set it as a global tracer:
10
11 ```go
12 import (
13                 "github.com/opentracing/opentracing-go"
14         "gerrit.o-ran-sc.org/ric-plt/tracelibgo/pkg/tracelibgo"
15         ...
16 )
17
18 tracer, closer := tracelibgo.CreateTracer("my-service-name")
19 defer closer.Close()
20 opentracing.SetGlobalTracer(tracer)
21 ```
22
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.
26
27 ```go
28         carrier := make(map[string]string)
29         opentracing.GlobalTracer().Inject(
30                         span.Context(),
31                         opentracing.TextMap,
32                         opentracing.TextMapCarrier(carrier))
33         b, err := json.Marshal(carrier) // b is a []byte and contains serilized span context
34 ```
35
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.
38
39 ```go
40         var carrier map[string]string
41         err = json.Unmarshal(data, &carrier) // data is []byte containing serialized span context
42         if err != nil {
43                 ...
44         }
45         context, err := opentracing.GlobalTracer().Extract(opentracing.TextMap, opentracing.TextMapCarrier(carrier))
46         if err != nil {
47                 ...
48         }
49         span := opentracing.GlobalTracer().StartSpan("go test span", opentracing.ChildOf(context))
50 ```
51
52 ## Unit testing
53
54  GO111MODULE=on go mod download
55  go test ./pkg/tracelibgo
56
57 ## License
58
59 See [LICENSES.txt](LICENSES.txt) file.