Skip to content

ref(starlette): Use new scopes API #2877

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

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
sentrivana committed Mar 21, 2024
commit 25fdff1ad903942ada1a69d4e94c59b4a51da65a
9 changes: 6 additions & 3 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
AnnotatedValue,
capture_internal_exceptions,
ensure_integration_enabled,
ensure_integration_enabled_async,
event_from_exception,
logger,
parse_version,
Expand Down Expand Up @@ -103,10 +102,12 @@ def _enable_span_for_middleware(middleware_class):
# type: (Any) -> type
old_call = middleware_class.__call__

@ensure_integration_enabled_async(StarletteIntegration, old_call)
async def _create_span_call(app, scope, receive, send, **kwargs):
# type: (Any, Dict[str, Any], Callable[[], Awaitable[Dict[str, Any]]], Callable[[Dict[str, Any]], Awaitable[None]], Any) -> None
integration = sentry_sdk.get_client().get_integration(StarletteIntegration)
if integration is None:
return await old_call(app, scope, receive, send, **kwargs)

middleware_name = app.__class__.__name__

# Update transaction name with middleware name
Expand Down Expand Up @@ -381,12 +382,14 @@ def _sentry_request_response(func):
is_coroutine = _is_async_callable(old_func)
if is_coroutine:

@ensure_integration_enabled_async(StarletteIntegration, old_func)
async def _sentry_async_func(*args, **kwargs):
# type: (*Any, **Any) -> Any
integration = sentry_sdk.get_client().get_integration(
StarletteIntegration
)
if integration is None:
return await old_func(*args, **kwargs)

request = args[0]

_set_transaction_name_and_source(
Expand Down