Skip to content

Propagate opentelemetry spans across remote connections.#74

Open
rread wants to merge 1 commit inton0-computer:mainfrom
rread:rread/tracing
Open

Propagate opentelemetry spans across remote connections.#74
rread wants to merge 1 commit inton0-computer:mainfrom
rread:rread/tracing

Conversation

@rread
Copy link

@rread rread commented Oct 16, 2025

The current span context is extracted and serialized with the message, and deserialized in read_request_raw() and saved in thread local storage. The generated RemoteService now creates a new span based on the message variant name, and sets the new span's parent to the extracted context.

Fixes #71

Copy link
Member

@Frando Frando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The feature sounds useful.

  • With this PR the wire format of a protocol changes based on feature flags for irpc. We can't do this unfortunately: You would never want your wire messages to change because some dependency enabled a feature on irpc which will - due to feature unification - affect all crates in the workspace dependency tree. So, we need a different approach here. I'll have to do some thinking how best to do this.

  • The PR makes the code generation dependant on feature flags on the proc macro crate. I think this is a no-go: Due to feature unification you can never know for sure if and where a feature got enabled. So this should be based on configuration via attributes on the rpc_requests macro instead.

  • The opentelemetry integration should be behind a separate feature use-tracing-opentelemetry or similar

@rread
Copy link
Author

rread commented Jan 15, 2026

Thanks for your review. I updated this to make OpenTelemetry span propagation opt-in per service instead of being globally enabled via feature flags.

Changes

  • Added span_propagation attribute to the rpc_requests macro - services that want span context propagation now need to explicitly opt in: #[rpc_requests(message = MyMessage, span_propagation)]
  • Moved OpenTelemetry deps behind a new use-tracing-opentelemetry feature instead of bundling them with rpc
  • Wire format is now controlled per-service via Service::SPAN_PROPAGATION - services without span_propagation skip the context wrapper
  • Removed the spans and rpc feature flags from irpc-derive - the generated code now calls a helper function that handles the cfg logic internally

@rread rread force-pushed the rread/tracing branch 2 times, most recently from a13164a to dcc2dd5 Compare January 20, 2026 21:17
@rread rread requested a review from Frando January 27, 2026 13:41
Adds a new `rpc_request` feature `span_propagation` and a newcrate
feature `use-tracing-opentelemetry`.When enalbed, the current span
context is extracted and serialized with the message,and deserialized in
`read_request_raw()` and saved in thread localstorage.  The generated
`RemoteService` creates a new span based onthe message variant name, and
sets the new span's parent to theextracted context.
@rread
Copy link
Author

rread commented Jan 30, 2026

Fixed the CI errors.

@jgrund
Copy link

jgrund commented Feb 9, 2026

Any chance this can make the next release? I'd like to use this to get distributed traces of my app

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support trace context propagation for rpc

3 participants