Quarkus Opentelemetry Baggage

399 Views Asked by At

I am trying to add some custom information to the opentelemetry baggage but not finding it in the Jaeger UI as part of the information shown. Is there anyway i can configure Quarkus opentelemetry to send custom data from the baggage? Or is there anyway this can be included by default?

I have this setting (which is supposed to be the default) in my application.properties. Basically, i am looking to see how i can add a custom id (correlation id or messageId) to the tracing info.

Any idea? Thank you in advance!

2

There are 2 best solutions below

3
Bruno Baptista On

Yes, in Quarkus the Baggage is automatically propagated using the OpenTelemetry default, W3C. Assuming you are using HTTP communication...

There are multiple ways to enrich the baggage. This is one example using Quarkus 3.x:

@Inject
Baggage baggage;

// ...

try (final Scope scope = baggage.toBuilder()
        .put("legumeId", legumeItem.getId()) // some data you need to send
        .build()
        .makeCurrent()) {

    // ... send things to other service
}

On the other side, to retrieve the baggage attributes you can:

@Inject
Baggage baggage;

// ...

log.info("legumeId: {}", baggage.getEntryValue("legumeId"));
// or, to see all the map entries:
baggage.asMap().forEach((k, v) -> log.info("baggage: {}={}", k, v.getValue()));

Please mind OpenTelemetry is a different API from tracing. It's supposed to be used to transport application context data. I'm not sure Jaeger can somehow display it. Most likely it will never arrive there because it's suppose to travel in the headers of the calls between services, not to the collector side.

1
Yuri Shkuro On

Baggage is a runtime concept, it's purpose is to make certain information accessible to the application at different hops of the distributed request. With OpenTelemetry, baggage can work without any tracing being present. If you want baggage to be captured in the traces, you need to do it explicitly via span.setAttribute.