Skip to content

POtel implementation base branch #3152

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

Draft
wants to merge 352 commits into
base: master
Choose a base branch
from
Draft

POtel implementation base branch #3152

wants to merge 352 commits into from

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Jun 10, 2024

Full state of CI: #3744

Contains:

Simple test

import sentry_sdk
from time import sleep

sentry_sdk.init(
    debug=True,
    traces_sample_rate=1.0,
    _experiments={"otel_powered_performance": True},
)

with sentry_sdk.start_span(description="sentry request"):
    sleep(0.1)
    with sentry_sdk.start_span(description="sentry db"):
        sleep(0.5)
        with sentry_sdk.start_span(description="sentry redis"):
            sleep(0.2)
    with sentry_sdk.start_span(description="sentry http"):
        sleep(1)

References

Misc

In OTel, this:

with tracer.start_as_current_span("parent") as parent:
    with tracer.start_span("child1"):
        pass
    with tracer.start_span("child2"):
        pass

is equivalent to

from opentelemetry import trace, context

parent = tracer.start_span("parent")

# Creates a Context object with parent set as current span
ctx = trace.set_span_in_context(parent)

# Set as the implicit current context
token = context.attach(ctx)

# Child will automatically be a child of parent
child1 = tracer.start_span("child1")
child1.end()

# Child will automatically be a child of parent
child2 = tracer.start_span("child2")
child2.end()

# Don't forget to detach or parent will remain the parent above this call stack
context.detach(token)
parent.end()

@sl0thentr0py sl0thentr0py requested a review from sentrivana June 10, 2024 19:00
@sl0thentr0py sl0thentr0py force-pushed the potel-base branch 2 times, most recently from f7f153c to 28effd6 Compare June 11, 2024 11:43
@sl0thentr0py sl0thentr0py force-pushed the potel-base branch 2 times, most recently from 16f9341 to 951477f Compare June 25, 2024 15:16
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 84.41940% with 318 lines in your changes missing coverage. Please review.

Project coverage is 84.80%. Comparing base (c2d5a76) to head (f5fb6e7).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/aws_lambda.py 11.11% 48 Missing ⚠️
sentry_sdk/tracing.py 80.32% 37 Missing and 11 partials ⚠️
sentry_sdk/opentelemetry/utils.py 81.48% 27 Missing and 18 partials ⚠️
sentry_sdk/opentelemetry/span_processor.py 82.14% 13 Missing and 17 partials ⚠️
sentry_sdk/integrations/gcp.py 0.00% 27 Missing ⚠️
sentry_sdk/tracing_utils.py 79.72% 10 Missing and 5 partials ⚠️
sentry_sdk/integrations/ray.py 7.14% 13 Missing ⚠️
sentry_sdk/opentelemetry/sampler.py 91.66% 7 Missing and 4 partials ⚠️
sentry_sdk/utils.py 86.11% 5 Missing and 5 partials ⚠️
sentry_sdk/integrations/tornado.py 75.86% 4 Missing and 3 partials ⚠️
... and 24 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3152      +/-   ##
==========================================
+ Coverage   80.67%   84.80%   +4.13%     
==========================================
  Files         142      144       +2     
  Lines       15982    14728    -1254     
  Branches     2729     2343     -386     
==========================================
- Hits        12893    12490     -403     
+ Misses       2232     1523     -709     
+ Partials      857      715     -142     
Files with missing lines Coverage Δ
sentry_sdk/__init__.py 100.00% <100.00%> (ø)
sentry_sdk/_compat.py 84.21% <ø> (-1.84%) ⬇️
sentry_sdk/_init_implementation.py 100.00% <100.00%> (+23.33%) ⬆️
sentry_sdk/ai/monitoring.py 88.73% <100.00%> (+2.43%) ⬆️
sentry_sdk/ai/utils.py 85.00% <100.00%> (+7.72%) ⬆️
sentry_sdk/api.py 95.34% <100.00%> (+15.77%) ⬆️
sentry_sdk/client.py 84.90% <100.00%> (+5.36%) ⬆️
sentry_sdk/consts.py 99.59% <100.00%> (+6.15%) ⬆️
sentry_sdk/debug.py 95.00% <ø> (+3.69%) ⬆️
sentry_sdk/envelope.py 82.98% <100.00%> (+3.08%) ⬆️
... and 84 more

... and 42 files with indirect coverage changes

@sl0thentr0py sl0thentr0py changed the title Skeletons for new POTEL components New POTEL base branch Jul 9, 2024
@sl0thentr0py sl0thentr0py changed the title New POTEL base branch potel implementation base branch Jul 9, 2024
@antonpirker antonpirker changed the title potel implementation base branch POtel implementation base branch Aug 5, 2024
@sentrivana sentrivana removed their request for review August 28, 2024 09:12
sentrivana and others added 18 commits October 23, 2024 13:31
This moves the creation of breadcrumbs for outgoing HTTP requests from the `maybe_create_breadcrumbs_from_span` into the integrations.
It is possible to use the return value of `sentry_sdk.init` as a context manager; however, this functionality has not been maintained for a long time, and it does not seem to be documented anywhere.

So, we are deprecating this functionality, and we will remove it in the next major release.

Closes #3282
BREAKING CHANGE: `sentry_sdk.init` now returns `None` instead of a context manager.
* Don't default to OK span status for UNSET, this breaks older behavior
* Set transaction name manually on scope after isolation (we should
  generally do this everywhere)
…3748)

If this option is on, we will only create a new underlying otel span if
there's an active valid parent, otherwise we will just return an invalid
`NonRecordingSpan` (`INVALID_SPAN`).

All internal integration child `start_span` calls have been modified so that
now we will only create spans if there is an active root span
(transaction) active.
sentrivana and others added 30 commits April 28, 2025 16:13
Introduce the convention of underscore-prefixed span attributes. These
won't be sent to Sentry and are meant for internal SDK usage.

Changed `flag.count` to internal. Looked through the rest of the attrs
we're setting and that stuff requires a big comprehensive cleanup
altogether to make stuff align with OTel. Didn't touch anything else for
now.

Closes #4329
Revert changing the default of `traces_sample_rate` done in
#4240
Store feature flags on the isolation scope, that is the correct place. 

I also checked back with Colton about the behavior of feature flags, and
having the flags on the isolation scope (meaning: one set of flags per
request-response cycle) is the expected behavior.
…eader (#4356)

Since we don't automatically have unsampled spans running, this caused a
change in behavior when an upstream sampling decision needs to be
propagated further downstream.

### Explanation of problem
When an incoming trace has `sampled` set to 0 (`trace_id-span_id-0`),
in the past we would propagate this since we would have an active
span/transaction running but just not sampled, so downstream would also
receive `trace_id-span_id-0` from that active span.
Now, we actually don't have an active span since we don't sample (just
how otel works), so instead of sending the `trace_id-span_id-0` as
before, we would have sent `trace_id-other_span_id` from the
`propagation_context` instead.
This would cause the downstream service to not receive the `-0` flag and
would thus sample independently, which is a regression.
In some cases FastAPI emits an exception that has as `__cause__` an
ExceptionGroup that contains a single excpetion. That single exepction
is the original exception. This PR prevents an infinite loop by trying
to add this construct in the `exception.values` field.

It also introduces an hard upper limit of chained/nested transaction, to
never run into an infinite loop.
This PR also needs an update of the docs to make sure people use the top
level API. See this docs issue:
getsentry/sentry-docs#13592
To preserve behavior form 2.x
Not using plain strings, but always use `SPANDATA`. Follow up to this
PR: #4373
…correct in context manager regardless of source of span (#4439)

closes #3509
We don't use the `client` parameter in the `Scope`'s constructor,
perhaps we can remove it and simplify the API. It is still possible to
set the client with `Scope.set_client`.

BREAKING CHANGE: `sentry_sdk.Scope` no longer has a `client` parameter.

<!-- Describe your PR here -->

---

Thank you for contributing to `sentry-python`! Please add tests to
validate your changes, and lint your code using `tox -e linters`.

Running the test suite on your PR might require maintainer approval.
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.

6 participants