Skip to content
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

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

Merged
merged 3 commits into from
May 3, 2024

Conversation

alexmojaki
Copy link
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.

Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

cloudflare-workers-and-pages bot commented May 3, 2024

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 enabled auto-merge (squash) May 3, 2024 17:04
@alexmojaki alexmojaki merged commit 73a1314 into main May 3, 2024
11 checks passed
@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