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

Implement set_contexts and fix response context #3630

Merged
merged 1 commit into from
Oct 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading