Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 7778e9a

Browse files
fix: Check span recording state before ending process span
Adds a check to verify the subscribe span is still recording before attempting to end the process span in the __exit__ method. This prevents errors when the span has already been terminated or is no longer active. This fix ensures proper cleanup of OpenTelemetry spans during subscriber callback execution and prevents potential errors in the context manager exit flow.
1 parent e6294a1 commit 7778e9a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

google/cloud/pubsub_v1/open_telemetry/subscribe_opentelemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __enter__(self) -> trace.Span:
205205
return self.start_process_span()
206206

207207
def __exit__(self, exc_type, exc_val, traceback):
208-
if self._process_span:
208+
if self._process_span and self._subscribe_span.is_recording():
209209
self.end_process_span()
210210

211211

0 commit comments

Comments
 (0)