Clone this repo:
  1. a94eddf Merge "RIC:1060: Change in PTL" by Abdul Wahid W · 7 months ago j-release master
  2. 077b2c3 CI: Migrate Sonar Scan job to GHA by Jessica Wagantall · 7 months ago
  3. 876b5ec RIC:1060: Change in PTL by Abdulwahid W · 7 months ago
  4. 33e8974 CI: Add silent prescan SonarCloud job by Jessica Wagantall · 8 months ago
  5. 205853c Removing deprecated functions from readthedocs by czichy · 1 year, 3 months ago i-release

Tracing helper library

The library creates a configured tracer instance.

Usage

Create a tracer instance and set it as a global tracer:

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.

	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.

	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))

Configuration

The trace library currently supports only Jaeger golang client tracer implementation. The configuration is done using environment variables:

environment variablevaluesdefault
TRACING_ENABLED1, true, 0, falsefalse
TRACING_JAEGER_SAMPLER_TYPEconst, propabilistic, ratelimitingconst
TRACING_JAEGER_SAMPLER_PARAMfloat0.001
TRACING_JAEGER_AGENT_ADDRIP addr[:port]127.0.0.1:6831
TRACING_JAEGER_LOG_LEVELall, error, nonenone

Meaning of the configuration variables is described in Jaeger web pages. By default a no-op tracer is created.

Unit testing

GO111MODULE=on go mod download go test ./pkg/tracelibgo

License

See LICENSES.txt file.