Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 660
feat(dramatiq): Support span streaming#6273
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,11 +6,13 @@ | ||
| from sentry_sdk.consts import OP, SPANSTATUS | ||
| from sentry_sdk.integrations import DidNotEnable, Integration | ||
| from sentry_sdk.integrations._wsgi_common import request_body_within_bounds | ||
| from sentry_sdk.traces import SegmentSource | ||
| from sentry_sdk.tracing import ( | ||
| BAGGAGE_HEADER_NAME, | ||
| SENTRY_TRACE_HEADER_NAME, | ||
| TransactionSource, | ||
| ) | ||
| from sentry_sdk.tracing_utils import has_span_streaming_enabled | ||
| from sentry_sdk.utils import ( | ||
| AnnotatedValue, | ||
| capture_internal_exceptions, | ||
| @@ -114,7 +116,8 @@ def before_enqueue( | ||
| } | ||
| def before_process_message(self, broker: "Broker", message: "Message[R]") -> None: | ||
| integration = sentry_sdk.get_client().get_integration(DramatiqIntegration) | ||
| client = sentry_sdk.get_client() | ||
| integration = client.get_integration(DramatiqIntegration) | ||
| if integration is None: | ||
| return | ||
| @@ -129,21 +132,35 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non | ||
| # start new trace in case of retrying | ||
| sentry_headers = {} | ||
| transaction = continue_trace( | ||
| sentry_headers, | ||
| name=message.actor_name, | ||
| op=OP.QUEUE_TASK_DRAMATIQ, | ||
| source=TransactionSource.TASK, | ||
| origin=DramatiqIntegration.origin, | ||
| ) | ||
| transaction.set_status(SPANSTATUS.OK) | ||
| sentry_sdk.start_transaction( | ||
| transaction, | ||
| name=message.actor_name, | ||
| op=OP.QUEUE_TASK_DRAMATIQ, | ||
| source=TransactionSource.TASK, | ||
| ) | ||
| transaction.__enter__() | ||
| if has_span_streaming_enabled(client.options): | ||
| sentry_sdk.traces.continue_trace(sentry_headers) | ||
| span = sentry_sdk.traces.start_span( | ||
| name=message.actor_name, | ||
| attributes={ | ||
| "sentry.op": OP.QUEUE_TASK_DRAMATIQ, | ||
| "sentry.origin": DramatiqIntegration.origin, | ||
| "sentry.span.source": SegmentSource.TASK.value, | ||
| }, | ||
| parent_span=None, | ||
| ) | ||
| message._sentry_span_ctx = span | ||
| else: | ||
| transaction = continue_trace( | ||
| sentry_headers, | ||
| name=message.actor_name, | ||
| op=OP.QUEUE_TASK_DRAMATIQ, | ||
| source=TransactionSource.TASK, | ||
| origin=DramatiqIntegration.origin, | ||
| ) | ||
| transaction.set_status(SPANSTATUS.OK) | ||
| sentry_sdk.start_transaction( | ||
| transaction, | ||
| name=message.actor_name, | ||
| op=OP.QUEUE_TASK_DRAMATIQ, | ||
| source=TransactionSource.TASK, | ||
| ) | ||
| transaction.__enter__() | ||
| message._sentry_span_ctx = transaction | ||
| def after_process_message( | ||
| self, | ||
| @@ -161,8 +178,8 @@ def after_process_message( | ||
| throws = message.options.get("throws") or actor.options.get("throws") | ||
| scope_manager = message._scope_manager | ||
| transaction = sentry_sdk.get_current_scope().transaction | ||
| if not transaction: | ||
| span_ctx = getattr(message, "_sentry_span_ctx", None) | ||
| if span_ctx is None: | ||
| return None | ||
| is_event_capture_required = ( | ||
| @@ -172,7 +189,7 @@ def after_process_message( | ||
| ) | ||
| if not is_event_capture_required: | ||
| # normal transaction finish | ||
| transaction.__exit__(None, None, None) | ||
| span_ctx.__exit__(None, None, None) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The canonical way to do this in span first would just be | ||
| scope_manager.__exit__(None, None, None) | ||
| return | ||
| @@ -186,7 +203,7 @@ def after_process_message( | ||
| ) | ||
| sentry_sdk.capture_event(event, hint=hint) | ||
| # transaction error | ||
| transaction.__exit__(type(exception), exception, None) | ||
| span_ctx.__exit__(type(exception), exception, None) | ||
| scope_manager.__exit__(type(exception), exception, None) | ||
| after_skip_message = after_process_message | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.