-
Notifications
You must be signed in to change notification settings - Fork 9
Make compatible with sentry sdk 3.0.0 #39
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
Make compatible with sentry sdk 3.0.0 #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates pytest-sentry for compatibility with Sentry SDK 3.0.0 by migrating legacy scope and transaction APIs to the new OpenTelemetry-based implementations.
- Swapped out
sentry_sdk.Scope
forPotelScope
and updateduse_scope
imports. - Refactored
_start_transaction
to usecontinue_trace
andstart_span
context managers. - Bumped
sentry-sdk
requirement to>=3.0.0a1
.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/test_scope.py | Replaced sentry_sdk.Scope usage with PotelScope as Scope and updated scope checks. |
tests/test_envvars.py | Updated use_scope import to sentry_sdk.opentelemetry.scope.use_scope . |
setup.cfg | Updated sentry-sdk dependency to >=3.0.0a1 . |
pytest_sentry.py | Adjusted imports for new scope APIs, refactored transaction start logic, and modified scope resolution to set clients. |
Comments suppressed due to low confidence (4)
pytest_sentry.py:259
- Mutating the current scope and returning it can cause client configuration to leak between tests. Instead, construct and return a fresh Scope instance with the desired client (e.g.,
return Scope(client=Client(marker_value))
).
scope.set_client(Client(marker_value))
pytest_sentry.py:264
- Mutating the current scope and returning it can cause client configuration to leak between tests. Instead, construct and return a fresh Scope instance with the desired client (e.g.,
return Scope(client=Client(**marker_value))
).
scope.set_client(Client(**marker_value))
pytest_sentry.py:269
- Mutating the current scope and returning it can cause client configuration to leak between tests. Instead, construct and return a fresh Scope instance with the desired client (e.g.,
return Scope(client=marker_value)
).
scope.set_client(marker_value)
pytest_sentry.py:166
- Using
start_span
instead ofstart_transaction
may produce a Span rather than a Transaction, potentially breaking the intended use of Sentry transactions. Consider usingsentry_sdk.start_transaction
to maintain transaction semantics.
with sentry_sdk.start_span(**kwargs) as root_span:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use top level api everywhere pls
Co-authored-by: Neel Shah <[email protected]>
addressed all requested changes.
If you wonder how the trace of a pytest testsuite looks like: I have set This is the test suite: The screenshot shows:
|
Update the codebase so it works with `Sentry Python SDK 3.0.0 alpha`. Sentry SDK 3.0.0 has some backwards incompatibilities and uses Opentelementry under the hood to create spans. ### What this PR does: - replace `sentry_sdk.start_transaction()` with `sentry_sdk.start_span()` - replace `span.set_data()` with `span.set_attribute()` - replace `scope.transaction` with `scope.root_span` - replace `Span.containing_transaction` with `Span.root_span` - replace `custom_sampling_context` with `attributes` parameter - replace `sentry_sdk.scope.get_*_scope()` with `sentry_sdk.get_*_scope()` - replace one `scope.add_attachment()` with `sentry_sdk.add_attachment()` - change one `continue_trace()` to the new context manager. - update `traces_sampler` to use new `sampling_context` format - added a few tests See also the migration guide: https://docs.sentry.io/platforms/python/migration/2.x-to-3.x --- ### Related, but split out into separate PRs: - make sure `traces_sampler` works the same as before (check for `sample_rate`): #93011 - make **all** `get_isolation_scope` calls use the top-level API. Currently, some calls where we `from sentry_sdk import Scope` then call `Scope.get_isolation_scope` still need to be converted to the top-level API: #93307 - check `event["measurements"]` places if those can be removed (because SDK does not support measurements anymore): #92718 - change set_span_data() to set_span_attribute() but check for value NOT be a dict: #92946 - replace `with sentry_sdk.init(dsn=...)` with `with sentry_sdk.new_scope() as scope: scope.set_client(sentry_sdk.Client(dsn=...))` in `src/sentry/runner/main.py`: #92944 - remove `propagate_hub=True` from `ThreadingIntegration`: #93016 - remove minimetrics from the sentry codebase, because the metrics product was never released: #93595 - getsentry/getsentry#17553 - getsentry/devenv#194 - getsentry/devservices#277 - getsentry/pytest-sentry#39 - getsentry/sentry-docs#13939 --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Daniel Szoke <[email protected]> Co-authored-by: Daniel Szoke <[email protected]> Co-authored-by: Ivana Kellyer <[email protected]> Co-authored-by: Neel Shah <[email protected]>
Update the codebase so it works with `Sentry Python SDK 3.0.0 alpha`. Sentry SDK 3.0.0 has some backwards incompatibilities and uses Opentelementry under the hood to create spans. ### What this PR does: - replace `sentry_sdk.start_transaction()` with `sentry_sdk.start_span()` - replace `span.set_data()` with `span.set_attribute()` - replace `scope.transaction` with `scope.root_span` - replace `Span.containing_transaction` with `Span.root_span` - replace `custom_sampling_context` with `attributes` parameter - replace `sentry_sdk.scope.get_*_scope()` with `sentry_sdk.get_*_scope()` - replace one `scope.add_attachment()` with `sentry_sdk.add_attachment()` - change one `continue_trace()` to the new context manager. - update `traces_sampler` to use new `sampling_context` format - added a few tests See also the migration guide: https://docs.sentry.io/platforms/python/migration/2.x-to-3.x --- ### Related, but split out into separate PRs: - make sure `traces_sampler` works the same as before (check for `sample_rate`): #93011 - make **all** `get_isolation_scope` calls use the top-level API. Currently, some calls where we `from sentry_sdk import Scope` then call `Scope.get_isolation_scope` still need to be converted to the top-level API: #93307 - check `event["measurements"]` places if those can be removed (because SDK does not support measurements anymore): #92718 - change set_span_data() to set_span_attribute() but check for value NOT be a dict: #92946 - replace `with sentry_sdk.init(dsn=...)` with `with sentry_sdk.new_scope() as scope: scope.set_client(sentry_sdk.Client(dsn=...))` in `src/sentry/runner/main.py`: #92944 - remove `propagate_hub=True` from `ThreadingIntegration`: #93016 - remove minimetrics from the sentry codebase, because the metrics product was never released: #93595 - getsentry/getsentry#17553 - getsentry/devenv#194 - getsentry/devservices#277 - getsentry/pytest-sentry#39 - getsentry/sentry-docs#13939 --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Daniel Szoke <[email protected]> Co-authored-by: Daniel Szoke <[email protected]> Co-authored-by: Ivana Kellyer <[email protected]> Co-authored-by: Neel Shah <[email protected]>
NOTE: When this PR is released,
pytest-sentry
is not compatible toSDK 2.x
anymore!This PR:
pytest-sentry
compatible with Sentry Python SDK 3.0.0Preview: https://github.com/getsentry/pytest-sentry/tree/antonpirker/make-compatible-with-sentry-sdk-3.0.0