Skip to content

feat(otel): add OpenTelemetry SpanProcessor, Propagator, Extractor #779

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

lcian
Copy link
Member

@lcian lcian commented Apr 30, 2025

Creates a new crate sentry-opentelemetry for integration with OTEL.

The implementation is based on a SpanProcessor that creates and finishes Sentry spans on OTEL span start/end.
There's also a Propagator/Extractor that injects the metadata (e.g. HTTP headers) required for distributed tracing to work.
It's based on our implementation for JS and other SDKs (https://develop.sentry.dev/sdk/telemetry/traces/opentelemetry/).

The goal with this initial version is:

  • support OTEL <> Sentry span conversion and capturing
  • capture OTEL span attributes
  • link any messages/errors captured through the Sentry API to the correct spans, assuming that only the OTEL API is used to manage spans

Feedback appreciated on:

There are some todo items which will be addressed in follow-up PRs (not necessarily in this release).

@lcian lcian marked this pull request as ready for review April 30, 2025 12:52
@lcian
Copy link
Member Author

lcian commented Apr 30, 2025

Seems like Windows CI is getting stuck on test_captures_transaction for some reason. I'll stop it for now.

@lcian lcian linked an issue Apr 30, 2025 that may be closed by this pull request
Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

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

Just gave this a quick glance and left some comments on what I noticed so far.

@lcian
Copy link
Member Author

lcian commented May 2, 2025

Just gave this a quick glance and left some comments on what I noticed so far.

Thank you!

@lcian
Copy link
Member Author

lcian commented May 2, 2025

Apparently we need to put each test in a different file or they will get stuck on Windows.

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

this looks reasonable to me.
Its a bit unfortunate how the lack of "onlyspans" means that you have to still deal with needing access to a TransactionOrSpan object instead of just being able to push finished spans with opaque parent ids into a global span sink.

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

lgtm

[dependencies]
sentry-core = { version = "0.37.0", path = "../sentry-core", features = [
"client",
"release-health"
Copy link
Member

Choose a reason for hiding this comment

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

I still don’t understand why the otel sub-crate depends directly on release-health?

Copy link
Member Author

@lcian lcian May 6, 2025

Choose a reason for hiding this comment

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

You're right it doesn't make much sense.

I was thinking there might be a scenario where someone depends on just sentry-core and sentry-opentelemetry, so I've added it to make sure that release-health is activated.
But actually users are always forced to depend on sentry as well in order to call sentry::init and effectively use the SDK, so they will choose whether to enable release-health when adding the sentry dependency itself.

I actually added this release-health flag to many of the subcrates when introducing this feature flag based on the above though process, see e.g. https://github.com/getsentry/sentry-rust/blob/master/sentry-tracing/Cargo.toml

On the other hand, if we don't do this and people upgrade the dependency without checking the release notes, they might end up without release-health and not know, which is not nice.
See for example https://github.com/rust-lang/crates.io/blob/main/Cargo.toml
if we remove release-health from the subcrates then the feature will be deactivated with a configuration like this.

Could you please advise on what you think is best here? @Swatinem

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.

OpenTelemetry initial support
3 participants