Skip to content

Conversation

@sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Oct 1, 2025

  • setup external propagation context to fetch trace_id/span_id from otel
  • setup otlp exporter with endpoint and headers taken from DSN
  • setup propagator
  • exporter and propagator are setup by default, can be turned off in case people want to setup manually

Issues

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 90.56604% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.99%. Comparing base (659bd84) to head (75c4163).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/otlp.py 90.38% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4877      +/-   ##
==========================================
+ Coverage   83.92%   83.99%   +0.07%     
==========================================
  Files         179      180       +1     
  Lines       17948    18001      +53     
  Branches     3193     3199       +6     
==========================================
+ Hits        15062    15120      +58     
+ Misses       1913     1908       -5     
  Partials      973      973              
Files with missing lines Coverage Δ
sentry_sdk/consts.py 99.40% <100.00%> (+<0.01%) ⬆️
sentry_sdk/integrations/otlp.py 90.38% <90.38%> (ø)

... and 3 files with indirect coverage changes

@sl0thentr0py sl0thentr0py force-pushed the neel/poc-otlp-integration branch 11 times, most recently from 726b769 to f5923b2 Compare October 31, 2025 15:31
@sl0thentr0py sl0thentr0py changed the title POC OtlpIntegration OTLPIntegration Oct 31, 2025
@sl0thentr0py sl0thentr0py force-pushed the neel/poc-otlp-integration branch from f5923b2 to 525bd76 Compare October 31, 2025 15:34
@linear
Copy link

linear bot commented Oct 31, 2025

@sl0thentr0py
Copy link
Member Author

sl0thentr0py commented Oct 31, 2025

sentry error + sentry log + otlp trace

2025-10-31-162117_hyprshot

@sl0thentr0py sl0thentr0py force-pushed the neel/poc-otlp-integration branch 4 times, most recently from beb8ce0 to 6d60191 Compare November 5, 2025 15:56
@sl0thentr0py sl0thentr0py marked this pull request as ready for review November 5, 2025 16:07
@sl0thentr0py sl0thentr0py requested a review from a team as a code owner November 5, 2025 16:07
@sl0thentr0py
Copy link
Member Author

distributed tracing also works 🎉

image

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

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

Looks good! A few questions just so I understand what's going on better as well.

if dsn:
auth = Dsn(dsn).to_auth(f"sentry.python/{VERSION}")
endpoint = auth.get_api_url(EndpointType.OTLP_TRACES)
headers = {"X-Sentry-Auth": auth.to_header()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we set two headers in the transport and only one here? See

headers.update(
{
"User-Agent": str(self._auth.client),
"X-Sentry-Auth": str(self._auth.to_header()),
}
)

Copy link
Member Author

Choose a reason for hiding this comment

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

return (trace.format_trace_id(ctx.trace_id), trace.format_span_id(ctx.span_id))


def setup_otlp_exporter(dsn=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

When dsn is None, is there any point in setting up the provider and processor?

Not sure if I am missing something because I am not as familiar with OTel. I would have thought if dsn is None we could exit early, maybe with a warning message.

Copy link
Member Author

@sl0thentr0py sl0thentr0py Nov 6, 2025

Choose a reason for hiding this comment

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

they can still manually set env variables as follows:

export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://o0.ingest.sentry.io/api/0/integration/otlp/v1/traces"
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-sentry-auth=sentry sentry_key=examplePublicKey"

which will be picked up by otel internally when initializing the exporter. Leaving it open as an option just in case someone has a complicated ops setup.

Copy link
Member Author

Choose a reason for hiding this comment

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

we'll iterate on the DX here once we get some feedback/complaints/confusion

assert propagator is original_propagator


def test_otel_propagation_context(sentry_init):
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb Nov 6, 2025

Choose a reason for hiding this comment

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

When running this test I see the message below. I'm trying to find where this is coming from.

Failed to export span batch code: 404, reason: You should be really using o*.ingest.sentry.io domains.

Copy link
Member Author

Choose a reason for hiding this comment

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

mocked

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

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

🚀

{py3.7,py3.9,py3.12,py3.13,py3.14,py3.14t}-opentelemetry

# OpenTelemetry with OTLP
{py3.7,py3.9,py3.12,py3.13,py3.14,py3.14t}-otlp
Copy link
Contributor

Choose a reason for hiding this comment

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

Last thing that'd be good before merging.

Since pip install "opentelemetry-distro[otlp]" also pulls in grpcio, and grpcio does not distribute free-threading wheels, these new tests take like 17 mins to run in CI on free-threading 3.14.

https://github.com/getsentry/sentry-python/actions/runs/19139690916/job/54701021577?pr=4877

So I suggest we do not run the new test suite on 3.14t.

Also, as an fyi: for running populate_tox.py, I add a uv command for running it with the new pre-requisites to the README in https://github.com/getsentry/sentry-python/pull/5076/files

That said, in this case you can just edit tox.jinja and tox.ini manually, since it's just removing a single version.

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.

Implement OtlpIntegration for Python SDK

3 participants