Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A client request which sends tracestate header to JAX-RS API does not result in tracestate being propagated with TextMapPropagator #30271

Open
JDUNNIN opened this issue Nov 21, 2024 · 2 comments
Labels
in:MicroProfile/Telemetry Needs member attention release bug This bug is present in a released version of Open Liberty

Comments

@JDUNNIN
Copy link

JDUNNIN commented Nov 21, 2024

Describe the bug
A clear and concise description of what the bug is.

If there is a stack trace, please include the FULL stack trace (without any [internal classes] lines in it). To find the full stack trace, you may need to check in $WLP_OUTPUT_DIR/messages.log

Related to issue #30260

Calling a JAX-RS API with headers baggage=userId=alice,serverNode=DF%2028,isProduction=false and tracestate=rojo=00f067aa0ba902b7,congo=t61rcWkgMzE (doc examples), I can see the headers on the inbound request to the server, but when TextMapPropagator is called, only baggage and the created traceparent are provided.

Some trace entries in server to support this:

Request headers:
{accept-encoding=[gzip], baggage=[userId=alice,serverNode=DF%2028,isProduction=false], connection=[Keep-Alive], content-type=[application/json], Host=[localhost:33957], tracestate=[rojo=00f067aa0ba902b7,congo=t61rcWkgMzE], User-Agent=[okhttp/4.7.2]}
...
OTEL: InvocationBuilderSetter.set called for key traceparent
OTEL: Adding header traceparent with value 00-857639bc42c761bd3527bb40961b68ef-a0b00a20de2b8e06-01
OTEL: InvocationBuilderSetter.set called for key baggage
OTEL: Adding header baggage with value isProduction=false,serverNode=DF%2028,userId=Alice
// debug
OTEL: Span.current().getSpanContext().getTraceState(): ArrayBasedTraceState{entries=[]}

The Java code in use within the JAX-RS API:


import io.openliberty.microprofile.telemetry.spi.OpenTelemetryAccessor;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;

...

            TextMapPropagator textMapPropagator = OpenTelemetryAccessor.getOpenTelemetryInfo().getOpenTelemetry().getPropagators().getTextMapPropagator();
            textMapPropagator.inject(Context.current(), builder, TEXT_MAP_SETTER);

            builder.post(payload)

...
    private static class InvocationBuilderSetter implements TextMapSetter<Builder> {
        @SuppressWarnings("null")
        @Override
        public void set(Builder carrier, String key, String value) {
            Tr.debug(tc, "OTEL: InvocationBuilderSetter.set called for key {0}", key);
            if (carrier == null) {
                return;
            }
            carrier.header(key, value);
            Tr.debug(tc, "OTEL: Adding header {0} with value {1}", key, value);
        }
    }

If it is of use, we create our spans using:

            this.span = openTelemetry.getTracer(PRODUCT_SCOPE_NAME)
                    .spanBuilder(this.name)
                    .setSpanKind(this.spanKind).startSpan();
            this.scope = this.span.makeCurrent();

Steps to Reproduce
Steps to reproduce the bug

  • Deploy a JAX-RS API and have it use a TextMapPropagator to call .inject(...).
  • Send a request with described headers
  • See in trace tracestate is not called as part of inject as expected.

Expected behavior
A clear and concise description of what you expected to happen.

When a client request includes tracestate header, this should be set in the context for spans

Diagnostic information:

  • OpenLiberty Version: WebSphere Application Server 24.0.0.9 (with temp iFix OLGH28891 related to OTEL accessor methods)
  • Affected feature(s) [mpTelemetry-2.0]
  • Java Version: IBM Semeru Runtime Open Edition (17.0.12+7)
  • server.xml configuration (WITHOUT sensitive information like passwords)
  • If it would be useful, upload the messages.log file found in $WLP_OUTPUT_DIR/messages.log

Additional context
Add any other context about the problem here.

@JDUNNIN JDUNNIN added the release bug This bug is present in a released version of Open Liberty label Nov 21, 2024
@Azquelt
Copy link
Member

Azquelt commented Nov 21, 2024

Here's how I believe it should work whenever the w3c trace propagator is enabled:

  • When receiving the request via servlet or Jakarta REST, the tracestate header should be parsed and stored as a TraceState object in the SpanContext
    • use Span.current().getSpanContext().getTraceState() to check that this happens
  • When creating a new span, the TraceState should be copied from the parent context
    • after creating a new span, Span.current().getSpanContext().getTraceState() should still contain the data
    • can't find where in the spec this is explicitly stated, but the Java implementation does appear to be doing this
  • When making a request, the TraceState object should be serialized into a tracestate header
    • if the request is made via MP Rest Client or Jakarta REST Client, then liberty should do this automatically and the header should be seen on the outgoing request
    • if the user is manually calling the TextMapPropagator as Jack is here, their TextMapSetter should be called with key="tracestate" and value = the serialized TraceState object.

@Azquelt Azquelt moved this from New to Backlog in MicroProfile UK Nov 21, 2024
@JDUNNIN
Copy link
Author

JDUNNIN commented Nov 22, 2024

Confirmed that at the earliest point in our code, before we do anything with Spans etc, calling Span.current().getSpanContext().getTraceState() still shows an empty array for entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:MicroProfile/Telemetry Needs member attention release bug This bug is present in a released version of Open Liberty
Projects
Status: Backlog
Development

No branches or pull requests

3 participants