Skip to content

Commit

Permalink
Implement set_contexts and fix response context (#3630)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Oct 8, 2024
1 parent f0703b3 commit 58cd8aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions sentry_sdk/integrations/opentelemetry/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ class SentrySpanAttribute:
MEASUREMENT = "sentry.measurement"
TAG = "sentry.tag"
NAME = "sentry.name"
CONTEXT = "sentry.context"
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,14 @@ def _root_span_to_transaction_event(self, span):
return None

span_data = extract_span_data(span)
(_, description, _, _, _) = span_data
(_, description, _, http_status, _) = span_data

trace_context = get_trace_context(span, span_data=span_data)
contexts = {"trace": trace_context}

if http_status:
contexts["response"] = {"status_code": http_status}

if span.resource.attributes:
contexts[OTEL_SENTRY_CONTEXT] = {"resource": dict(span.resource.attributes)}

Expand Down
3 changes: 3 additions & 0 deletions sentry_sdk/integrations/opentelemetry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ def extract_span_status(span):
if inferred_status:
return (inferred_status, http_status)

if http_status is not None:
return (inferred_status, http_status)

if (
status.description is not None
and status.description in GRPC_ERROR_MAP.values()
Expand Down
8 changes: 5 additions & 3 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ def set_tag(self, key, value):

def set_data(self, key, value):
# type: (str, Any) -> None
# TODO-neel-potel we cannot add dicts here
self.set_attribute(key, value)

def set_attribute(self, key, value):
Expand Down Expand Up @@ -1582,11 +1583,12 @@ def get_profile_context(self):
# type: () -> Optional[ProfileContext]
pass

# transaction/root span methods

def set_context(self, key, value):
# type: (str, Any) -> None
pass
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
# TODO-neel-potel we cannot add dicts here

self.set_attribute(f"{SentrySpanAttribute.CONTEXT}.{key}", value)


if TYPE_CHECKING:
Expand Down

0 comments on commit 58cd8aa

Please sign in to comment.