Skip to content

Commit

Permalink
fix: Add runtime context
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jul 5, 2019
1 parent 4bd78ad commit 79e99ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions sentry_sdk/integrations/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from sentry_sdk.utils import Event


_installed_modules = None


Expand Down
18 changes: 18 additions & 0 deletions sentry_sdk/integrations/stdlib.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 79e99ac

Please sign in to comment.