Skip to content

Cleanup meta references on flush #4420

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

Open
wants to merge 1 commit into
base: potel-base
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion sentry_sdk/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
get_profile_context,
get_sentry_meta,
set_sentry_meta,
delete_sentry_meta,
)
from sentry_sdk.profiler.continuous_profiler import (
try_autostart_continuous_profiler,
Expand Down Expand Up @@ -173,6 +174,7 @@ def _flush_root_span(self, span):
# TODO-neel-potel sort and cutoff max spans

sentry_sdk.capture_event(transaction_event)
self._cleanup_references([span] + collected_spans)

def _append_child_span(self, span):
# type: (ReadableSpan) -> None
Expand Down Expand Up @@ -253,7 +255,6 @@ def _root_span_to_transaction_event(self, span):
profile.__exit__(None, None, None)
if profile.valid():
event["profile"] = profile
set_sentry_meta(span, "profile", None)

return event

Expand Down Expand Up @@ -314,6 +315,11 @@ def _common_span_transaction_attributes_as_json(self, span):

return common_json

def _cleanup_references(self, spans):
# type: (List[ReadableSpan]) -> None
for span in spans:
delete_sentry_meta(span)

def _log_debug_info(self):
# type: () -> None
import pprint
Expand Down
8 changes: 8 additions & 0 deletions sentry_sdk/opentelemetry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ def set_sentry_meta(span, key, value):
span._sentry_meta = sentry_meta # type: ignore[union-attr]


def delete_sentry_meta(span):
# type: (Union[AbstractSpan, ReadableSpan]) -> None
try:
del span._sentry_meta # type: ignore[union-attr]
except AttributeError:
pass


def get_profile_context(span):
# type: (ReadableSpan) -> Optional[dict[str, str]]
if not span.attributes:
Expand Down
Loading