From 07a3ea38429421e6e9db2083f2c22cd322664561 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 7 Aug 2026 09:14:22 +0200 Subject: [PATCH 1/5] ref(subprocess): Create breadcrumbs directly in integration Move subprocess breadcrumb creation from the centralized `maybe_create_breadcrumbs_from_span` hook into the stdlib integration's `Popen.__init__` wrapper. This makes breadcrumbs work for both legacy spans and streamed spans, and removes the dependency on span internals. --- sentry_sdk/integrations/stdlib.py | 9 +++++++++ sentry_sdk/tracing_utils.py | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 4de3819a77..3e19c06709 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -349,6 +349,15 @@ def sentry_patched_popen_init( else: span.set_tag("subprocess.pid", self.pid) + with capture_internal_exceptions(): + breadcrumb_data = {"subprocess.cwd": cwd} if cwd else {} + sentry_sdk.add_breadcrumb( + type="subprocess", + category="subprocess", + message=description, + data=breadcrumb_data, + ) + return rv subprocess.Popen.__init__ = sentry_patched_popen_init # type: ignore diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 989dee8bc6..6c903cd21d 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -234,14 +234,6 @@ def maybe_create_breadcrumbs_from_span( else: scope.add_breadcrumb(type="http", category="httplib", data=span._data) - elif span.op == "subprocess": - scope.add_breadcrumb( - type="subprocess", - category="subprocess", - message=span.description, - data=span._data, - ) - def _get_frame_module_abs_path(frame: "FrameType") -> "Optional[str]": try: From 2f91234cfd7a39587a1394f3d972f3ca1f069f4e Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 7 Aug 2026 09:18:31 +0200 Subject: [PATCH 2/5] . --- sentry_sdk/integrations/stdlib.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 3e19c06709..c790372b73 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -350,12 +350,15 @@ def sentry_patched_popen_init( span.set_tag("subprocess.pid", self.pid) with capture_internal_exceptions(): - breadcrumb_data = {"subprocess.cwd": cwd} if cwd else {} + data = {} + if cwd: + data["subprocess.cwd"] = cwd + sentry_sdk.add_breadcrumb( type="subprocess", category="subprocess", message=description, - data=breadcrumb_data, + data=data, ) return rv From 0ea13df3a0033f30a8cf71ef80bad292c396e6e0 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 7 Aug 2026 09:46:39 +0200 Subject: [PATCH 3/5] . --- sentry_sdk/integrations/stdlib.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index c790372b73..cacf02e36f 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -342,13 +342,6 @@ def sentry_patched_popen_init( if cwd and isinstance(span, Span): span.set_data("subprocess.cwd", cwd) - rv = old_popen_init(self, *a, **kw) - - if isinstance(span, StreamedSpan): - span.set_attribute(SPANDATA.PROCESS_PID, self.pid) - else: - span.set_tag("subprocess.pid", self.pid) - with capture_internal_exceptions(): data = {} if cwd: @@ -361,6 +354,13 @@ def sentry_patched_popen_init( data=data, ) + rv = old_popen_init(self, *a, **kw) + + if isinstance(span, StreamedSpan): + span.set_attribute(SPANDATA.PROCESS_PID, self.pid) + else: + span.set_tag("subprocess.pid", self.pid) + return rv subprocess.Popen.__init__ = sentry_patched_popen_init # type: ignore From 2f54487a992d04c5345747d8db52abf87f8c610a Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 7 Aug 2026 10:04:48 +0200 Subject: [PATCH 4/5] move even earlier --- sentry_sdk/integrations/stdlib.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index cacf02e36f..d37ac9fb0f 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -305,6 +305,18 @@ def sentry_patched_popen_init( env = None + with capture_internal_exceptions(): + data = {} + if cwd: + data["subprocess.cwd"] = cwd + + sentry_sdk.add_breadcrumb( + type="subprocess", + category="subprocess", + message=description, + data=data, + ) + span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options) span: "Union[Span, StreamedSpan]" if span_streaming: @@ -342,18 +354,6 @@ def sentry_patched_popen_init( if cwd and isinstance(span, Span): span.set_data("subprocess.cwd", cwd) - with capture_internal_exceptions(): - data = {} - if cwd: - data["subprocess.cwd"] = cwd - - sentry_sdk.add_breadcrumb( - type="subprocess", - category="subprocess", - message=description, - data=data, - ) - rv = old_popen_init(self, *a, **kw) if isinstance(span, StreamedSpan): From 4e093aa3a81f7664aa02406917ff611fd6a38210 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Fri, 7 Aug 2026 10:48:55 +0200 Subject: [PATCH 5/5] . --- sentry_sdk/integrations/stdlib.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index d37ac9fb0f..c764605c45 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -305,17 +305,12 @@ def sentry_patched_popen_init( env = None - with capture_internal_exceptions(): - data = {} - if cwd: - data["subprocess.cwd"] = cwd - - sentry_sdk.add_breadcrumb( - type="subprocess", - category="subprocess", - message=description, - data=data, - ) + sentry_sdk.add_breadcrumb( + type="subprocess", + category="subprocess", + message=description, + data={"subprocess.cwd": cwd} if cwd else {}, + ) span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options) span: "Union[Span, StreamedSpan]"