Skip to content

Commit 5349ca7

Browse files
authored
Prevent logged warning when span is double-ended at interpreter shutdown (#704)
1 parent 5eced1c commit 5349ca7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

logfire/_internal/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,15 @@ def _exit_open_spans(): # type: ignore[reportUnusedFunction] # pragma: no cove
944944
# OTEL registers its own atexit callback in the tracer/meter providers to shut them down.
945945
# Registering this callback here after the OTEL one means that this runs first.
946946
# Otherwise OTEL would log an error "Already shutdown, dropping span."
947+
# The reason that spans may be lingering open is that they're in suspended generator frames.
948+
# Apart from here, they will be ended when the generator is garbage collected
949+
# as the interpreter shuts down, but that's too late.
947950
for span in list(OPEN_SPANS):
951+
# TODO maybe we should be recording something about what happened here?
948952
span.end()
953+
# Interpreter shutdown may trigger another call to .end(),
954+
# which would log a warning "Calling end() on an ended span."
955+
span.end = lambda *_, **__: None # type: ignore
949956

950957
self._initialized = True
951958

0 commit comments

Comments
 (0)