Skip to content

Close spans when process shuts down before the exporter shuts down and drops them - #108

Merged
alexmojaki merged 3 commits into
mainfrom
alex/spans-atexit
May 3, 2024
Merged

alexmojaki merged 3 commits into
mainfrom
alex/spans-atexit

Conversation

@alexmojaki

Copy link
Copy Markdown
Contributor

Without this PR, this script:

import logfire

def stream():
    with logfire.span('span'):
        yield 1
        yield 2

s = stream()
next(s)

logs an error: "Already shutdown, dropping span."

This PR registers exiting the span context managers with atexit. This happens after the tracer provider is initialized, where OTEL registers its own shutdown (and thus the shutdown of the span processors and exporters) with atexit. Since atexit runs the callbacks in reverse order of registration, that means the spans will be closed by atexit before the exporters shut down.

@codecov

codecov Bot commented May 3, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 3, 2024 •

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: de050c3
Status: ✅  Deploy successful!
Preview URL: https://4193ba5f.logfire-docs.pages.dev
Branch Preview URL: https://alex-spans-atexit.logfire-docs.pages.dev

View logs

@alexmojaki
alexmojaki force-pushed the alex/spans-atexit branch from f6396e5 to de050c3 Compare May 3, 2024 17:04
@alexmojaki
alexmojaki enabled auto-merge (squash) May 3, 2024 17:04
@alexmojaki
alexmojaki merged commit 73a1314 into main May 3, 2024
@alexmojaki
alexmojaki deleted the alex/spans-atexit branch May 3, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants