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

Not able to propagate baggage in OpenTracingSpan #6970

Closed
RickyFrost opened this issue Jun 8, 2023 · 5 comments · Fixed by #6987
Closed

Not able to propagate baggage in OpenTracingSpan #6970

RickyFrost opened this issue Jun 8, 2023 · 5 comments · Fixed by #6987
Assignees
Labels
3.x Issues for 3.x version branch bug Something isn't working P2 tracing
Milestone

Comments

@RickyFrost
Copy link

I'm not able to propagate baggage items when opentracing is used in io.helidon.tracing.

Environment Details

  • Helidon: v3.2.1 SE
  • JDK version: 17.0.5
  • OS: Oracle Linux 7
  • Docker version (if applicable): n/a

Problem Description

Even though the baggage item I add to the span is retrievable from the span, it doesn't propagate to the remote endpoint.
See sample test code below.

Steps to reproduce

@Test void baggageCanaryMinimal() {
    final var tracer = io.helidon.tracing.Tracer.global();
    final var span = tracer.spanBuilder("baggageCanaryMinimal").start();
    try {
        // Set baggage and confirm that it's known in the span
        span.baggage("fubar", "1");
        assertEquals("1", span.baggage("fubar").orElseThrow());

        // Inject the span (context) into the consumer
        final var consumer = HeaderConsumer
            .create(new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
        tracer.inject(span.context(), HeaderProvider.empty(), consumer);

        // Confirm that baggage was NOT propagated (the bug)
        final var allKeys = consumer.keys().toString();
        assertTrue(allKeys.contains("fubar") // this fails!
            , () -> "No injected baggage-fubar found in "+allKeys);

    } catch (final Exception x) {
        span.end(x);
    } finally {
        span.end();
    }
}
@RickyFrost
Copy link
Author

The reason seems to be that OpenTracingSpan holds a final for the 'context' as it existed at that time in the constructor. So all baggage added to the span is never seen in the outdated context, even though it's retrievable with span.baggage("key") because that call asks the delegate.

But if I add a span.activate() and use Span.current().orElseThrow().context() then it works as expected. The reason is that a new OpenTracingSpan is created by Span.current, so it now uses the most recent context.

@barchetta barchetta added bug Something isn't working tracing 3.x Issues for 3.x version branch P2 labels Jun 8, 2023
@barchetta
Copy link
Member

This looks related to PR #6692

@RickyFrost
Copy link
Author

I agree if by related you mean, before 6692 we couldn't put and get baggage at all. Now with this latest finding above you can find baggage on the Span that you added to a OpenTracingSpan. But the bug is that the baggage you can see doesn't get propagated unless you somehow acquire a newly created OpenTracingSpan. And the easiest way to do that is to activate the span, then call Span.current(), and not depend on the context() from the old Span where you actually created it.

@RickyFrost
Copy link
Author

The reason this issue actually involves a bug in OpenTracingSpan is because I can't get helidon-tracing-jaeger to work for me, see #7009

As a workaround I'm using the following set of dependencies to "actually" use opentracing, not pseudo-opentracing that bridges to opentelemetry.

        <dependency>
            <groupId>io.helidon.tracing</groupId>
            <artifactId>helidon-tracing-opentracing</artifactId>
        </dependency>
        <dependency>
            <groupId>io.helidon.tracing</groupId>
            <artifactId>helidon-tracing-tracer-resolver</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jaegertracing</groupId>
            <artifactId>jaeger-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentracing</groupId>
            <artifactId>opentracing-api</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentracing</groupId>
            <artifactId>opentracing-util</artifactId>
        </dependency>

@RickyFrost
Copy link
Author

RickyFrost commented Jun 15, 2023

This issue is NOT fixed when using the dependencies above. Should I file a new issue for when jaeger-client is in use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch bug Something isn't working P2 tracing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants