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

Deprectated warning for function sentry_sdk.configure_scope, fix migration for sentry-sdk 2.x #95

Merged
merged 9 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions asgi_correlation_id/extensions/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def set_transaction_id(correlation_id: str) -> None:
The transaction ID is displayed in a Sentry event's detail view,
which makes it easier to correlate logs to specific events.
"""
from sentry_sdk import configure_scope
import sentry_sdk

with configure_scope() as scope:
if sentry_sdk.VERSION >= '2.12.0':
Copy link
Member

Choose a reason for hiding this comment

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

Is 2.12.0 the version where the warning was added, or when the get_isolation_scope function was added? It seems like it would be best to use the version where get_isolation_scope was added, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method get_isolation_scope was added in 2.0 but only in the class Scope, it wasn't added in the init.py, that means we must use sentry_sdk.Scope.get_isolation_scope() to use the method. The warning and the function was added in init.py in version 2.12, that's why I did this.

Copy link
Contributor Author

@imSniff imSniff Aug 14, 2024

Choose a reason for hiding this comment

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

You can check it here:
Added in __init__.py 2.12: https://github.com/getsentry/sentry-python/blob/2.12.0/sentry_sdk/__init__.py
Doesn't added in __init__.py version less than or equal to 2.11: https://github.com/getsentry/sentry-python/blob/2.11.0/sentry_sdk/__init__.py

Added in 2.0 but without the warning and also without being added the symbol in the var __all__ in the __init__.py file (there is also a symbol called isolation_scope in the var __all__ but it's not even a method): https://github.com/getsentry/sentry-python/blob/2.0.0/sentry_sdk/scope.py#L273
Added warning in 2.12 here: https://github.com/getsentry/sentry-python/blob/2.12.0/sentry_sdk/api.py#L223

Choose a reason for hiding this comment

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

Might want to be careful when comparing strings here:

>>> "2.2.0" >= "2.12.0"
True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx, already fixed

scope = sentry_sdk.get_isolation_scope()
scope.set_tag('transaction_id', correlation_id)
else:
with sentry_sdk.configure_scope() as scope:
scope.set_tag('transaction_id', correlation_id)
Loading
Loading