Skip to content

OpenTelemetry tracing support #234

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

Merged
merged 2 commits into from
Mar 27, 2025
Merged

OpenTelemetry tracing support #234

merged 2 commits into from
Mar 27, 2025

Conversation

cretz
Copy link
Member

@cretz cretz commented Mar 20, 2025

What was changed

  • Moved resolving string from workflow/signal/query/update/activity definition to before interceptor instead of after (technically a backwards incompatible change)
  • Added Temporalio::Contrib::OpenTelemetry module
    • Includes TracingInterceptor class for tracing
    • Includes Workflow module with helpers for replay-safe span creation
  • Added concept of Temporalio::Workflow.storage akin to Fiber#storage where arbitrary data can be stored on a workflow
    • Needed by the workflow helpers for OTel so they can store workflow-specific state, but may be used by other users doing similar type of stateful workflow helpers
  • Added several tests which required a lot of effort on OTel testing harness/helpers
  • Added lots of README information

Checklist

  1. Closes [Feature Request] OpenTelemetry tracing #189

@cretz cretz requested a review from a team March 20, 2025 22:43
Comment on lines +1083 to +1084
# ... assumes my_otel_tracer_provider is a tracer provider created by the user
my_tracer = my_otel_tracer_provider.tracer('my-otel-tracer')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe an example of one that someone would use would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I should just change this to

Suggested change
# ... assumes my_otel_tracer_provider is a tracer provider created by the user
my_tracer = my_otel_tracer_provider.tracer('my-otel-tracer')
my_tracer = OpenTelemetry.tracer_provider.tracer('my-otel-tracer')

Per https://opentelemetry.io/docs/languages/ruby/instrumentation/#acquiring-a-tracer. I guess most people configure the global instead of creating a tracing provider.

Comment on lines +15 to +16
# We are intentionally not pinning OTel versions here so that CI tests the latest. This also means that the OTel
# contrib library also does not require specific versions, we are relying on the compatibility rigor of OTel.
Copy link
Member

Choose a reason for hiding this comment

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

Good luck lol

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 The problem is that Ruby doesn't have a concept of "optional dependency constraints" so I can't put a constraint on users' OTel library, I can only fail to require it or add advanced validation to check the OTel version which I don't want to do. So this is the best way to at least make sure that we always work with the latest. If there was enough concern about breaking support for older OTel API versions, we could make a separate GH step to only test with a specific oldest OTel API version.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we do want to make this an option (and I also opened temporalio/sdk-python#794). I will update this PR.

Comment on lines +431 to +435

# Do nothing if there is no span on the context. We do not want orphan spans coming from workflows, so we
# require a parent (i.e. a current).
# TODO(cretz): This matches Python behavior but not .NET behavior (which will create no matter what), is that
# ok?
Copy link
Member

Choose a reason for hiding this comment

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

Why would there be no span? Something like this is running inside a workflow that was started from somewhere not using OTel?

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like this is running inside a workflow that was started from somewhere not using OTel?

Exactly. So if you start a workflow from CLI, then there is no stable span on the headers of start-workflow which means no stable parent. It's hard to decide which approach is best. With the Python approach we don't have orphaned spans, but we just don't have any spans if they didn't use an OTel friendly client. But with the .NET approach we have orphaned spans that don't have clear siblings or overarching workflow parent. I have seen slight complaints about both, but nothing significant.

Open to suggestions here. I could make it an option, though I just chose the "no OTel if didn't start with it, meaning no orphans" currently as I thought that was the better approach.

# @param exception [Exception, nil] Exception to record on the span.
# @param even_during_replay [Boolean] Set to true to record this span even during replay. Most users should
# never set this.
# @return [OpenTelemetry::Trace::Span, nil] Span if one was created. WARNING: It is UNSAFE to use this value.
Copy link
Member

Choose a reason for hiding this comment

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

Why return anything at all then?

Copy link
Member Author

@cretz cretz Mar 21, 2025

Choose a reason for hiding this comment

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

Because technically there is value in using it if you do it safely. For instance we use the result in the method right above this one and I don't want to necessarily prevent others from writing similar things if they know what they are doing. For example, some people may want to log the span ID only if the span was created (i.e. non-replay) which is ok.

@cretz cretz merged commit 7f746cf into temporalio:main Mar 27, 2025
6 checks passed
@cretz cretz deleted the otel-tracing branch March 27, 2025 17:07
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.

[Feature Request] OpenTelemetry tracing
2 participants