-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Sentry SDK and use it to capture traces for debugging performance problems.
- Loading branch information
Showing
6 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Setup code for Sentry.io trace.""" | ||
|
||
from typing import Any | ||
|
||
|
||
def enable_telemetry() -> None: | ||
"""Turn on upload of trace telemetry to Sentry, to allow performance | ||
debugging of deployed server. | ||
""" | ||
try: | ||
import sentry_sdk | ||
except ImportError: | ||
return | ||
|
||
# Configuration will be pulled from SENTRY_* environment variables | ||
# (see https://docs.sentry.io/platforms/python/configuration/options/). | ||
# If SENTRY_DSN is not present, telemetry is disabled. | ||
sentry_sdk.init( | ||
enable_tracing=True, traces_sampler=_decide_whether_to_sample_trace | ||
) | ||
|
||
|
||
def _decide_whether_to_sample_trace(context: dict[str, Any]) -> float: | ||
asgi_scope = context.get("asgi_scope") | ||
if asgi_scope is not None: | ||
# Do not log health check endpoint. | ||
if asgi_scope.get("path") == "/": | ||
return 0 | ||
|
||
return 1 |