Skip to content

OpenTelemetry Flow ID propagation does not add the X-Flow-ID request header #1895

Closed

Description

@visheshupadhyay

Description

When FlowIdSpanDecorator is configured with propagateFlowId = true, it is
expected to forward the current OpenTelemetry baggage Flow ID to the downstream
HTTP service using the X-Flow-ID header.

The decorator previously called arguments.withHeader(...), but
RequestArguments is immutable. withHeader(...) returns a new request
instance; it does not modify the original one. Because that returned instance
was discarded, OpenTelemetryPlugin later executed the original request
without the Flow ID header.

The Flow ID was still recorded as a tracing span attribute, which makes the
problem easy to miss: tracing looks correct locally, but the downstream service
does not receive the correlation header.

Expected Behavior

With Flow ID propagation enabled and a Flow ID in the current OpenTelemetry
baggage, the outgoing request should contain exactly the propagated value:

X-Flow-ID: flow-id-value

When propagation is disabled, or no Flow ID exists in baggage, no X-Flow-ID
header should be added.

Actual Behavior

With the current implementation, the outgoing request does not contain an
X-Flow-ID header even when propagation is enabled and baggage contains a
Flow ID.

OpenTelemetry baggage contains flow_id
        ↓
FlowIdSpanDecorator calls RequestArguments.withHeader(...)
        ↓
The returned immutable request is discarded
        ↓
OpenTelemetryPlugin executes the original request
        ↓
The downstream service never receives X-Flow-ID

Possible Fix

Add a request-decoration step that returns RequestArguments:

  1. Add a default decorateRequest(RequestArguments) method to SpanDecorator
    that returns the unchanged request. This keeps existing decorators fully
    compatible.
  2. Let CompositeSpanDecorator pass the request returned by each decorator to
    the next decorator.
  3. Let FlowIdSpanDecorator return arguments.withHeader(...) only when
    propagation is enabled and baggage has a Flow ID.
  4. Execute the final decorated request from OpenTelemetryPlugin.

Steps to Reproduce

  1. Configure OpenTelemetryPlugin with new FlowIdSpanDecorator(true).
  2. Store a Flow ID in the current OpenTelemetry baggage.
  3. Execute a Riptide request through the plugin.
  4. Inspect the RequestArguments received by RequestExecution, or inspect
    the request at the downstream server.
var plugin = new OpenTelemetryPlugin(
        openTelemetry,
        new FlowIdSpanDecorator(true));

var baggage = Baggage.builder()
        .put(ExtensionAttributes.FLOW_ID.getKey(), "flow-id-value")
        .build();

try (var scope = baggage.storeInContext(Context.current()).makeCurrent()) {
    plugin.aroundAsync(execution).execute(arguments).join();
}

Before the fix, the captured outgoing request has no X-Flow-ID header.

Context

Flow IDs are used to correlate work across service boundaries. Without the
header, a downstream service cannot associate an incoming request with the
upstream request trace. This makes debugging distributed requests and tracing
their full path more difficult.

The fix is protected by tests for:

  • Flow ID present and propagation enabled.
  • Flow ID present and propagation disabled.
  • No Flow ID in baggage.
  • Multiple decorators, ensuring each receives the request returned by its
    predecessor.

Environment

  • Version used: Riptide 5.1.3-SNAPSHOT
  • Java version: JDK 21.0.12.
  • Operating system: Windows.
TestRunBeforeBug
Image
TestRunWithBug
Image
TestRunAfterBugFix
Image

Activity

  1. fatroom commented on Nov 3, 2026

    @fatroom
    Contributor

    When propagation is disabled, or no Flow ID exists in baggage, no X-Flow-ID
    header should be added.

    This statement is not correct. Check the rules: https://opensource.zalando.com/restful-api-guidelines/#233

    Relevant quote:
    Note: API-Clients must provide Flow-ID when calling a service or producing events. If no Flow-ID is provided in a request or event, the service must create a new Flow-ID.

    Additionally: for generation of new X-Flow-ID value use span.getSpanContext().getTraceId();

    @visheshupadhyay can you update your fix according to this info?

  2. visheshupadhyay commented on Nov 4, 2026

    @visheshupadhyay
    ContributorAuthor

    Thanks for the clarification and feedback @fatroom ,

    I'll review the referenced guidelines and the current implementation to better understand the expected behavior. I'll also look into the suggested test separation and make the necessary changes based on my findings.

    Appreciate your guidance!

  3. visheshupadhyay commented on Nov 4, 2026

    @visheshupadhyay
    ContributorAuthor

    I have updated the implementation locally so every outgoing request receives an X-Flow-ID.

    • With propagateFlowId=true, the decorator reuses the baggage Flow ID when available; otherwise it uses span.getSpanContext().getTraceId().
    • With propagateFlowId=false, it does not reuse baggage and instead uses the current span trace ID.

    This keeps the outgoing header and the span flow_id attribute aligned, while ensuring clients always provide a Flow ID as required by the guidelines.

    Before I push the update, @fatroom could you please confirm that this is the intended meaning of propagateFlowId=false? I’ll wait for your guidance in case you prefer a different behavior.

  4. fatroom commented on Nov 4, 2026

    @fatroom
    Contributor

    With propagateFlowId=true, the decorator reuses the baggage Flow ID when available; otherwise it uses span.getSpanContext().getTraceId().

    This logic is mostly correct. I would as well recommend to take care about following situation:

    getSpanContext() might return invalid context in case when sdk isn't available. For this context getTraceId will always provide constant value, defeating purpose of the X-Flow-Id. the validity of context can be verified with isValid() method. For such cases X-Flow-Id should be generated randomly.

    propagateFlowId flag should be dropped from code.

  5. visheshupadhyay commented on Nov 4, 2026

    @visheshupadhyay
    ContributorAuthor

    Thanks for the clarification. When you say to drop propagateFlowId, do you mean only from the new OpenTelemetry FlowIdSpanDecorator flow, or should we also remove the existing public Spring configuration properties (tracing.propagate-flow-id / telemetry.propagate-flow-id) and the legacy FlowHttpRequestInterceptor behavior?

  6. fatroom commented on Nov 4, 2026

    @fatroom
    Contributor

    Only telemetry version and corresponding property. Tracing should stay as is.

  7. visheshupadhyay commented on Nov 5, 2026

    @visheshupadhyay
    ContributorAuthor

    Thanks for clarifying the intended scope.

    I updated the implementation so that the existing Tracing.propagateFlowId behavior remains unchanged. The flag is now removed only from the Telemetry/OpenTelemetry path.

    The final Flow ID selection is:

    1. Use the baggage Flow ID when available.
    2. Otherwise use the trace ID when the span context is valid.
    3. Otherwise generate a random UUID when the context is invalid.

    I also added coverage for baggage precedence, valid and invalid contexts, UUID fallback, and ensuring the outgoing X-Flow-ID value matches the span attribute.

    Validation completed successfully for:

    • riptide-opentelemetry tests
    Image
    • riptide-httpclient tests
    Image
    • compilation and packaging for both riptide-opentelemetry and riptide-spring-boot-autoconfigure
    Image

    Please let me know if you would like any further adjustments.

  8. fatroom commented on Nov 18, 2026

    @fatroom
    Contributor

    After internal discussion, we decided that logic from rest guidelines should be left to the caller, not the http client in this case.

    But initial with missing headers is fixed in #1905

  9. visheshupadhyay commented on Nov 18, 2026

    @visheshupadhyay
    ContributorAuthor

    Thanks for the update and for clarifying the architectural direction.
    I understand the decision to keep HTTP header propagation within a dedicated OpenTelemetry propagator and leave Flow ID generation policy to the caller.
    I appreciate the review and guidance throughout the investigation. Glad the original issue is being addressed in #1905!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions