-
Notifications
You must be signed in to change notification settings - Fork 658
feat(bottle): Add span streaming support to Bottle integration #6486
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
Changes from 2 commits
30649d5
4d7da81
0d92dd7
472eadb
decefd3
5753f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ | |
| ) | ||
| from sentry_sdk.integrations._wsgi_common import RequestExtractor | ||
| from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware | ||
| from sentry_sdk.tracing import SOURCE_FOR_STYLE | ||
| from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE | ||
| from sentry_sdk.tracing import SOURCE_FOR_STYLE as TRANSACTION_SOURCE_FOR_STYLE | ||
| from sentry_sdk.tracing_utils import has_span_streaming_enabled | ||
|
Check warning on line 15 in sentry_sdk/integrations/bottle.py
|
||
| from sentry_sdk.utils import ( | ||
| capture_internal_exceptions, | ||
| ensure_integration_enabled, | ||
|
|
@@ -100,7 +102,29 @@ | |
| scope.add_event_processor( | ||
| _make_request_event_processor(self, bottle_request, integration) | ||
| ) | ||
| res = old_handle(self, environ) | ||
|
|
||
| if has_span_streaming_enabled(sentry_sdk.get_client().options): | ||
| res = old_handle(self, environ) | ||
|
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. Looks like we can take this line out of the condition bodies since it's the same for both branches
Member
Author
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. Good eye, will make that fix! |
||
|
|
||
| try: | ||
| if integration.transaction_style == "url": | ||
| name = bottle_request.route.rule or "bottle" | ||
| else: | ||
| name = ( | ||
| bottle_request.route.name | ||
| or transaction_from_function(bottle_request.route.callback) | ||
| or "bottle" | ||
| ) | ||
|
|
||
| sentry_sdk.get_current_scope().set_transaction_name( | ||
| name, | ||
| source=SEGMENT_SOURCE_FOR_STYLE[integration.transaction_style], | ||
| ) | ||
| except RuntimeError: | ||
| pass | ||
|
ericapisani marked this conversation as resolved.
Outdated
|
||
|
|
||
| else: | ||
| res = old_handle(self, environ) | ||
|
|
||
| return res | ||
|
|
||
|
|
@@ -119,17 +143,33 @@ | |
| return prepared_callback | ||
|
|
||
| def wrapped_callback(*args: object, **kwargs: object) -> "Any": | ||
| try: | ||
| res = prepared_callback(*args, **kwargs) | ||
| except Exception as exception: | ||
| _capture_exception(exception, handled=False) | ||
| raise exception | ||
|
|
||
| if ( | ||
| isinstance(res, HTTPResponse) | ||
| and res.status_code in integration.failed_request_status_codes | ||
| ): | ||
| _capture_exception(res, handled=True) | ||
| if has_span_streaming_enabled(sentry_sdk.get_client().options): | ||
| with sentry_sdk.traces.start_span(name="bottle"): | ||
|
ericapisani marked this conversation as resolved.
Outdated
|
||
| try: | ||
| res = prepared_callback(*args, **kwargs) | ||
| except Exception as exception: | ||
| _capture_exception(exception, handled=False) | ||
| raise exception | ||
|
Check warning on line 152 in sentry_sdk/integrations/bottle.py
|
||
|
|
||
| if ( | ||
| isinstance(res, HTTPResponse) | ||
| and res.status_code | ||
| in integration.failed_request_status_codes | ||
| ): | ||
| _capture_exception(res, handled=True) | ||
|
Check warning on line 159 in sentry_sdk/integrations/bottle.py
|
||
|
|
||
| else: | ||
| try: | ||
| res = prepared_callback(*args, **kwargs) | ||
| except Exception as exception: | ||
| _capture_exception(exception, handled=False) | ||
| raise exception | ||
|
|
||
| if ( | ||
| isinstance(res, HTTPResponse) | ||
| and res.status_code in integration.failed_request_status_codes | ||
| ): | ||
| _capture_exception(res, handled=True) | ||
|
|
||
| return res | ||
|
|
||
|
|
@@ -185,7 +225,9 @@ | |
| pass | ||
|
|
||
| event["transaction"] = name | ||
| event["transaction_info"] = {"source": SOURCE_FOR_STYLE[transaction_style]} | ||
| event["transaction_info"] = { | ||
| "source": TRANSACTION_SOURCE_FOR_STYLE[transaction_style] | ||
| } | ||
|
|
||
|
|
||
| def _make_request_event_processor( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.