Skip to content

[Bug Report]: (OTel) Baggage propagation overwrites current context instead of merging in ProducerEventsHandler #661

@asapbuddy

Description

@asapbuddy

Prerequisites

  • I have searched issues to ensure it has not already been reported

Description

In the current implementation of OpenTelemetryProducerEventsHandler.OnProducerStarted, the code replaces Baggage.Current with the baggage from the newly created Activity.

This means if there was already baggage in Baggage.Current and the new Activity doesn’t have any baggage (or only a subset), the existing values are lost.

According to the OpenTelemetry specification for baggage propagation, baggage should flow with the context and should not be unintentionally discarded. Values from the new activity should be integrated into the current context, not overwrite it entirely.

Steps to reproduce

  1. Set a key/value into Baggage.Current.
  2. Start a Producer that creates a new activity without baggage.
  3. Observe that Baggage.Current is reset and previous entries are lost.

Expected behavior

  • Existing Baggage.Current entries should be preserved.
  • Values coming from Activity.Baggage should be added or overwrite if the same key already exists.
  • Context should consistently propagate across producer boundaries.

Actual behavior

Currently, when a producer activity is started, the implementation overwrites the current baggage with the contents of Activity.Baggage.

  • If Activity.Baggage is empty, Baggage.Current is effectively cleared.
  • Any previously set context in Baggage.Current is lost and does not propagate further.
  • This leads to missing baggage values in downstream services whenever the newly created Activity does not carry its own baggage (for example, when Activity.Recorded = false).

KafkaFlow version

4.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions