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 377 commits into
base: master
Choose a base branch
from
Draft

POtel implementation base branch #3152

wants to merge 377 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 91.24124% with 175 lines in your changes missing coverage. Please review.

Project coverage is 84.89%. Comparing base (9e1cedd) to head (cd422af).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/aws_lambda.py 26.76% 52 Missing ⚠️
sentry_sdk/integrations/gcp.py 0.00% 35 Missing ⚠️
sentry_sdk/integrations/ray.py 43.47% 13 Missing ⚠️
sentry_sdk/integrations/clickhouse_driver.py 79.54% 5 Missing and 4 partials ⚠️
sentry_sdk/integrations/tornado.py 82.22% 5 Missing and 3 partials ⚠️
sentry_sdk/integrations/asgi.py 89.39% 4 Missing and 3 partials ⚠️
sentry_sdk/integrations/rq.py 86.04% 2 Missing and 4 partials ⚠️
sentry_sdk/integrations/django/__init__.py 91.22% 5 Missing ⚠️
sentry_sdk/integrations/aiohttp.py 93.44% 2 Missing and 2 partials ⚠️
sentry_sdk/integrations/wsgi.py 92.00% 2 Missing and 2 partials ⚠️
... and 21 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3152      +/-   ##
==========================================
+ Coverage   80.63%   84.89%   +4.25%     
==========================================
  Files         156      144      -12     
  Lines       16482    15006    -1476     
  Branches     2802     2376     -426     
==========================================
- Hits        13291    12739     -552     
+ Misses       2308     1539     -769     
+ Partials      883      728     -155     
Files with missing lines Coverage Δ
sentry_sdk/__init__.py 100.00% <100.00%> (ø)
sentry_sdk/_init_implementation.py 100.00% <100.00%> (+23.33%) ⬆️
sentry_sdk/_log_batcher.py 79.76% <100.00%> (+2.11%) ⬆️
sentry_sdk/_lru_cache.py 100.00% <100.00%> (+6.25%) ⬆️
sentry_sdk/_queue.py 62.22% <100.00%> (+3.52%) ⬆️
sentry_sdk/_werkzeug.py 50.00% <100.00%> (+8.06%) ⬆️
sentry_sdk/ai/monitoring.py 88.88% <100.00%> (+2.58%) ⬆️
sentry_sdk/ai/utils.py 85.71% <100.00%> (+8.44%) ⬆️
sentry_sdk/api.py 96.77% <100.00%> (+16.36%) ⬆️
sentry_sdk/attachments.py 100.00% <100.00%> (+6.45%) ⬆️
... and 129 more

... and 1 file 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 November 12, 2024 15:19
- Add support for the sampled flag for start_span and respect it when making sampling decisions.
- Rework sampling_context in traces_sampler to work with span attributes instead. Make sure we still have the same data accessible as now.

We could go one step further and change the format of sampling_context to just be the actual span attributes without any postprocessing into the current format. I kept the format in line with what we have now to make it easier to update.

See #3746
Closes #3739

This is a breaking change since we're removing custom_sampling_context. It'll break multiple integrations until we fix them (see #3746).
Remove explicit trace_id passing
sl0thentr0py and others added 30 commits June 4, 2025 13:52
…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.
Currently, this test only asserts that the `traces_sampler` is called at
least once with the given arguments. However, we would expect it to be
called exactly once.

This PR changes the assertion to assert that the `traces_sampler` was
called exactly one time, and that that call included the given
arguments.

<!-- 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.
If a `TracerProvider` already exists, patch it. `TracerProvider` is a
singleton, so if we aren't the first ones setting it up, we need to use
the existing one.

In tests, reset `TracerProvider` after each test so that we start with a
clean slate and it gets set up anew on init.
- According to our [span
ops](https://develop.sentry.dev/sdk/telemetry/traces/span-operations/#database)
there is no op called just `db`, but we're emitting these from django,
clickhouse, asyncpg and pymongo. Changing to `db.query` instead.
- There was also a breadcrumb with type `db` that's also [officially not
a supported
type](https://develop.sentry.dev/sdk/data-model/event-payloads/breadcrumbs/#breadcrumb-types),
changed it to `query`.

This is intentionally just on `potel-base` since it's technically a
breaking change.
It is not ready yet and i do not want to push dog fooding back again.
extracted from
https://github.com/getsentry/sentry-python/pull/4487/files with lots of
manual fixes

* migrate old style `# type: bla` to inline types
* most importantly use
[`__future__.annotations`](https://peps.python.org/pep-0563/#enabling-the-future-behavior-in-python-3-7)
so that we can simply use forward annotations without wrapping them in
strings like we did before, this simplifies things substantially
* also guard only things that shouldn't be imported under
`TYPE_CHECKING`, in the future it seems we should avoid using
`TYPE_CHECKING` completely
* #4510
* #4522
* #4529
* #4530
* #4532
* #4533
* #4534

closes #2585
Ensure tag values are strings before serializing an event or a
transaction to an `Event` dictionary.

Fixes #4391

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
We currently use an `if self._ctx_token` check to determine if a span
has a `_ctx_token`. However, this check is incorrect, since `_ctx_token`
is only sometimes set. Furthermore, when `_ctx_token` is set, we should
always have a `_ctx_token`.

Therefore, using `hasattr` is what we want.

<!-- 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