8000 fix: Add runtime context (#410) · etherscan-io/sentry-python@96031fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 96031fb

Browse files
authored
fix: Add runtime context (getsentry#410)
1 parent 4bd78ad commit 96031fb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

sentry_sdk/integrations/modules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from sentry_sdk.utils import Event
1515

16+
1617
_installed_modules = None
1718

1819

sentry_sdk/integrations/stdlib.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
from sentry_sdk.hub import Hub
22
from sentry_sdk.integrations import Integration
3+
from sentry_sdk.scope import add_global_event_processor
34

5+
import sys
6+
import platform
47

58
try:
69
from httplib import HTTPConnection # type: ignore
710
except ImportError:
811
from http.client import HTTPConnection
912

13+
_RUNTIME_CONTEXT = {
14+
"name": platform.python_implementation(),
15+
"version": "%s.%s.%s" % (sys.version_info[:3]),
16+
"build": sys.version,
17+
}
18+
1019

1120
class StdlibIntegration(Integration):
1221
identifier = "stdlib"
@@ -16,6 +25,15 @@ def setup_once():
1625
# type: () -> None
1726
install_httplib()
1827

28+
@add_global_event_processor
29+
def add_python_runtime_context(event, hint):
30+
if Hub.current.get_integration(StdlibIntegration) is not None:
31+
contexts = event.setdefault("contexts", {})
32+
if isinstance(contexts, dict) and "runtime" not in contexts:
33+
contexts["runtime"] = _RUNTIME_CONTEXT
34+
35+
return event
36+
1937

2038
def install_httplib():
2139
# type: () -> None

0 commit comments

Comments
 (0)
0