Official Content

In OpenTelemetry, Baggage is contextual information that is passed between spans.
It’s a key-value store that resides alongside span context in a trace, making values available to any span created within that trace.

As stated in the Opentelemetry documentation, common use cases of the Baggage include information that’s only accessible further up a stack, such as account Identification, User IDs, Product IDs, and origin IPs, etc. Passing these down your stack allows you to add them to your Spans in downstream services to make it easier to filter when searching in your Observability backend.

Example

Use the CreateSpan method of Tracer to create the parent Span.
The AddBaggage method should be invoked using the Span object previously obtained. It returns a TraceContext that should be used to propagate the information. 

Parent procedure:

&span = Tracer.CreateSpan("TestBaggageParent procedure")
&context =  &span.AddBaggage("PropertyToBaggage","ValueToBaggage") //&Context is of TraceContext External Object
//Do something else
testbaggageChild(&context)
&span.End()

 

TestBaggageChild procedure:

parm(&Context)

&span = Tracer.CreateSpan("TestBaggageChild procedure",&context,SpanKind.Client) //Create Span passing &Context
//Do something else
&value = &span.GetBaggageItem("PropertyToBaggage")

&span.End()

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant