Skip to content
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

fix: Add runtime context #410

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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