diff --git a/sentry_sdk/integrations/opentelemetry/consts.py b/sentry_sdk/integrations/opentelemetry/consts.py index 6409d2822d..a71e304cf5 100644 --- a/sentry_sdk/integrations/opentelemetry/consts.py +++ b/sentry_sdk/integrations/opentelemetry/consts.py @@ -28,3 +28,4 @@ class SentrySpanAttribute: MEASUREMENT = "sentry.measurement" TAG = "sentry.tag" NAME = "sentry.name" + CONTEXT = "sentry.context" diff --git a/sentry_sdk/integrations/opentelemetry/potel_span_processor.py b/sentry_sdk/integrations/opentelemetry/potel_span_processor.py index 63a9acb9db..0076743245 100644 --- a/sentry_sdk/integrations/opentelemetry/potel_span_processor.py +++ b/sentry_sdk/integrations/opentelemetry/potel_span_processor.py @@ -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)} diff --git a/sentry_sdk/integrations/opentelemetry/utils.py b/sentry_sdk/integrations/opentelemetry/utils.py index fcfec97f5c..cf1e461c37 100644 --- a/sentry_sdk/integrations/opentelemetry/utils.py +++ b/sentry_sdk/integrations/opentelemetry/utils.py @@ -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() diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 1c3cb5b3f0..1ca79f6c14 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -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): @@ -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: