Skip to content

Add TraceCorrelation option to ProcessingOptions - #296

Open
entvex wants to merge 1 commit into
apache:masterfrom
entvex:Direct-parent-child-relationship
Open

entvex wants to merge 1 commit into
apache:masterfrom
entvex:Direct-parent-child-relationship

Conversation

@entvex

@entvex entvex commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

When tracing is enabled and LinkTraces = true, the process activity on
the consumer side only links to the message's send activity. Producer
and consumer therefore end up in two separate traces, hence making it is hard to follow
a single message end-to-end.

This PR makes it possible to use the message creation context as the parent of the process activity instead so producer and consumer end up in the same trace.

This is opt-in. Default behavior is unchanged.

It introduces the TraceCorrelation enum (None, Link, Parent) and a ProcessingOptions.TraceCorrelation property that controls how the process activity is correlated with the message's send activity when tracing is enabled:

  • None (default): no correlation, same as before
  • Link: the process activity links to the send activity, matching the OpenTelemetry messaging semantic conventions (same as LinkTraces = true today)
  • Parent: the process activity becomes a child of the send activity, so both end up in the same trace. It additionally links to the send activity.

LinkTraces is kept for backward compatibility and is now a shorthand for TraceCorrelation: true maps to Link and false to None.

DotPulsarActivitySource.StartConsumerActivity now takes a TraceCorrelation instead of a bool and passes a parent context to ActivitySource.StartActivity when required.

Testing

Tests added for both DotPulsarActivitySource and ProcessingOptions. 14 tests in total.

References

https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#message-creation-context-as-parent-of-process-span

Introduce the TraceCorrelation enum (None, Link, Parent) to control
how the process activity is correlated with the message's send
activity when tracing is enabled:

- None (default): no correlation, same as before
- Link: the process activity links to the send activity, matching
  the OpenTelemetry messaging semantic conventions
- Parent: the process activity becomes a child of the send activity,
  so both end up in the same trace, and additionally links to the
  send activity and to the ambient activity (if any)

LinkTraces is kept for backward compatibility and is now a shorthand
for TraceCorrelation: true maps to Link and false to None.

DotPulsarActivitySource.StartConsumerActivity now takes a
TraceCorrelation instead of a bool and passes a parent context to
ActivitySource.StartActivity when required. Tests added for both
DotPulsarActivitySource and ProcessingOptions, and CHANGELOG updated.
@entvex entvex self-assigned this Sep 14, 2026
@entvex entvex added the enhancement New feature or request label Sep 14, 2026

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant