X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=README.md;fp=README.md;h=e11effcacf5bbf6268115652915e2f51130e9e46;hb=af41105030e5c1d3f669bdd2bf24d3b7274df639;hp=0000000000000000000000000000000000000000;hpb=87956295b3a222b6b4f946a27efd633175ae7ed4;p=ric-plt%2Ftracelibgo.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..e11effc --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Tracing helper library + +The library creates a configured tracer instance. + +ToDO: configuration... + +## Usage + +Create a tracer instance and set it as a global tracer: + +```go +import ( + "github.com/opentracing/opentracing-go" + "gerrit.o-ran-sc.org/ric-plt/tracelibgo/pkg/tracelibgo" + ... +) + +tracer, closer := tracelibgo.CreateTracer("my-service-name") +defer closer.Close() +opentracing.SetGlobalTracer(tracer) +``` + +Serialize span context to a byte array that can be sent +to another component via some messaging. For example, using +the RMR library. The serialization uses JSON format. + +```go + carrier := make(map[string]string) + opentracing.GlobalTracer().Inject( + span.Context(), + opentracing.TextMap, + opentracing.TextMapCarrier(carrier)) + b, err := json.Marshal(carrier) // b is a []byte and contains serilized span context +``` + +Extract a span context from byte array and create a new child span from it. +The serialized span context is got, for example, from the RMR library. + +```go + var carrier map[string]string + err = json.Unmarshal(data, &carrier) // data is []byte containing serialized span context + if err != nil { + ... + } + context, err := opentracing.GlobalTracer().Extract(opentracing.TextMap, opentracing.TextMapCarrier(carrier)) + if err != nil { + ... + } + span := opentracing.GlobalTracer().StartSpan("go test span", opentracing.ChildOf(context)) +``` + +## Unit testing + + GO111MODULE=on go mod download + go test ./pkg/tracelibgo + +## License + +See [LICENSES.txt](LICENSES.txt) file.