From 79e99acad2f5bfe8c3d9c81a9d7d072a55b67226 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 4 Jul 2019 19:45:11 +0200 Subject: [PATCH] fix: Add runtime context --- sentry_sdk/integrations/modules.py | 1 + sentry_sdk/integrations/stdlib.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/sentry_sdk/integrations/modules.py b/sentry_sdk/integrations/modules.py index 4d597e5939..8107773492 100644 --- a/sentry_sdk/integrations/modules.py +++ b/sentry_sdk/integrations/modules.py @@ -13,6 +13,7 @@ from sentry_sdk.utils import Event + _installed_modules = None diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 8b16c73ce4..f9f0449886 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -1,12 +1,21 @@ from sentry_sdk.hub import Hub from sentry_sdk.integrations import Integration +from sentry_sdk.scope import add_global_event_processor +import sys +import platform try: from httplib import HTTPConnection # type: ignore except ImportError: from http.client import HTTPConnection +_RUNTIME_CONTEXT = { + "name": platform.python_implementation(), + "version": "%s.%s.%s" % (sys.version_info[:3]), + "build": sys.version, +} + class StdlibIntegration(Integration): identifier = "stdlib" @@ -16,6 +25,15 @@ def setup_once(): # type: () -> None install_httplib() + @add_global_event_processor + def add_python_runtime_context(event, hint): + if Hub.current.get_integration(StdlibIntegration) is not None: + contexts = event.setdefault("contexts", {}) + if isinstance(contexts, dict) and "runtime" not in contexts: + contexts["runtime"] = _RUNTIME_CONTEXT + + return event + def install_httplib(): # type: () -> None