Skip to content
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

POtel implementation base branch #3152

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

POtel implementation base branch #3152

wants to merge 294 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 83.62667% with 307 lines in your changes missing coverage. Please review.

Project coverage is 83.59%. Comparing base (adcfa0f) to head (6584ce0).
Report is 7 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/tracing.py 78.24% 44 Missing and 13 partials ⚠️
sentry_sdk/integrations/aws_lambda.py 11.11% 48 Missing ⚠️
sentry_sdk/integrations/opentelemetry/utils.py 82.00% 25 Missing and 18 partials ⚠️
sentry_sdk/integrations/gcp.py 0.00% 27 Missing ⚠️
...y_sdk/integrations/opentelemetry/span_processor.py 82.46% 10 Missing and 17 partials ⚠️
sentry_sdk/integrations/ray.py 7.14% 13 Missing ⚠️
sentry_sdk/integrations/opentelemetry/sampler.py 91.40% 7 Missing and 4 partials ⚠️
sentry_sdk/integrations/tornado.py 75.86% 4 Missing and 3 partials ⚠️
sentry_sdk/scope.py 86.53% 6 Missing and 1 partial ⚠️
sentry_sdk/utils.py 88.33% 4 Missing and 3 partials ⚠️
... and 20 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3152      +/-   ##
==========================================
+ Coverage   79.54%   83.59%   +4.04%     
==========================================
  Files         142      144       +2     
  Lines       15898    14659    -1239     
  Branches     2721     2324     -397     
==========================================
- Hits        12646    12254     -392     
+ Misses       2388     1687     -701     
+ Partials      864      718     -146     
Files with missing lines Coverage Δ
sentry_sdk/__init__.py 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.57% <100.00%> (+2.46%) ⬆️
sentry_sdk/ai/utils.py 85.00% <100.00%> (+7.72%) ⬆️
sentry_sdk/client.py 84.30% <100.00%> (+5.25%) ⬆️
sentry_sdk/consts.py 99.51% <ø> (+6.65%) ⬆️
sentry_sdk/debug.py 95.00% <ø> (+3.69%) ⬆️
sentry_sdk/envelope.py 85.71% <100.00%> (+3.19%) ⬆️
sentry_sdk/integrations/__init__.py 89.61% <ø> (+12.59%) ⬆️
... and 77 more

... and 48 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
sl0thentr0py and others added 18 commits September 10, 2024 14:02
* add and track underlying root span in a hidden attr `_sentry_root_otel_span` in all subsequent children spans in the span processor on start
* wrap this underlying root otel span in a `POTelSpan` to act as a proxy
* make `POTelSpan` constructor work with explicitly passed in `otel_span`
* implement `__eq__` on `POTelSpan` to make sure proxies to the same
  underlying `_otel_span` are considered the same
Add a new SentrySampler that is used for sampling OpenTelemetry spans the Sentry way (using Sentrys traces_sample_rate and traces_sampler config options)

Fixes #3318
* Remove 3.6 compat

* fix
* use potelscope

* Use POTel use_{isolation_}scope

* use from top level api
…#3519)

Make sure that `op`, `name`, `description` are set correctly on `Span`s and `Transaction`s.
* Add parsed baggage sentry items as items on the `sampling_context.trace_state` in
  `continue_trace`
* Fix sampler to propagate the `trace_state` to children in both sampled
  and dropped cases
* make `iter_headers` work
* make `get_trace_context` work
* add `dynamic_sampling_context` in `trace_context` so that it can be
  picked up by the client and added in the envelope header
sentrivana and others added 30 commits March 21, 2025 09:03
Remove the following deprecated stuff:
- `configure_debug_hub` from `debug.py`
- exported stuff in `profiler/__init__.py` that's not part of public API
and was only exported for backwards compat reasons
- support for `_experiments['profiler_mode']` and
`_experiments['profiles_sample_rate']` which both have non-experimental
top-level options now
- `Transport.capture_event`
- `_FunctionTransport` and support for function transports in general
- `enable_tracing`

---------

Co-authored-by: Anton Pirker <[email protected]>
`InvalidOperation` can occur when using tracing if the `Decimal` class's
global context has been modified to set the precision below 6. This
change fixes this bug by setting a custom context for our `quantize`
call.

Fixes #4177
With the refactoring of the AWS Lambda test suite in `master`. We need
to update the tests in `potel-base` to succeed again.

This also fixes a check in the `stdlib` integration. With local AWS
Lambda we have a DSN that includes a port. This did not work and this PR
makes this work. (This will allow support for self hosted Sentry running
on a specific port too)
Fixing this:

```
==================================== ERRORS ====================================
_________ ERROR collecting tests/integrations/trytond/test_trytond.py __________
ImportError while importing test module '/home/runner/work/sentry-python/sentry-python/tests/integrations/trytond/test_trytond.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.tox/py3.7-trytond-v5.0.9/lib/python3.7/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.tox/py3.7-trytond-v5.0.9/lib/python3.7/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
.tox/py3.7-trytond-v5.0.9/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/integrations/trytond/test_trytond.py:11: in <module>
    from trytond.wsgi import app as trytond_app
.tox/py3.7-trytond-v5.0.9/lib/python3.7/site-packages/trytond/wsgi.py:12: in <module>
    from werkzeug.contrib.fixers import ProxyFix
E   ModuleNotFoundError: No module named 'werkzeug.contrib'
```
This is now part of the Cloud test group
Drop the deprecated `propagate_traces` `init` option in POTel.

Important: The Celery integration also has an option called
`propagate_traces` -- this should remain unchanged.

---------

Co-authored-by: nellaG <[email protected]>
Port `sample_rand` to `potel-base`. See
[spec](https://develop.sentry.dev/sdk/telemetry/traces/#propagated-random-value).

There are now two places where a `sample_rand` might be generated:
- If we're explicitly propagating with `continue_trace`, we'll
[backfill](https://github.com/getsentry/sentry-python/pull/4106/files#diff-7c64294459f5053c93d44e0e33e4e73ffcef0adefcd77ba91f4031aa461a8c42R396-R397)
`sample_rand` on the propagation context like on master, either using
the incoming one or generating a new one from the incoming
`sampled`/`sample_rate`.
- Otherwise, we generate a new `sample_rand` [in the
Sampler](https://github.com/getsentry/sentry-python/pull/4106/files#diff-59aa7195d955e153b5cdd730f888994996a72eaf5e9ea174335ce961841584a9R194-R213).

The generated `sample_rand` is then saved on the trace state.

This change fixes most of the failures in the Common test suite.

Closes #4027

---------

Co-authored-by: Daniel Szoke <[email protected]>
Fixing Celery tests in Potel
- function transports have been removed. removing the related test
- `profiles_sample_rate` is not experimental anymore
- `continuous_profiling_mode` has been removed so only the top level
`profiler_mode` exists. (so the if is not necessary anymore)
Drop:
- setting `Scope.transaction` directly
- old way of setting `failed_request_status_codes`
- setting the `span` argument of `Scope.trace_propagation_meta`
- setting `Scope.user` directly
- trytond<5, falcon<3, django<2 are all more than 5 years old

Closes #4049
Make the `Span` constructor actually fail if it gets unsupported
arguments, as opposed to silently ignoring them, so that folks get
notified early.

Deprecating some of these in
#4244

Closes #4200
Changing the default of `traces_sample_rate` to `0`. This means incoming
traces will be continued, but we will not start traces on our own. (It
used to be set to: never start or continue traces by default)

Refs #4102
BREAKING CHANGE: Remove `Span.containing_transaction`. Use
`Span.root_span` instead.

Closes #4253

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

4 participants