Skip to content

fix: #2489 lazily initialize tracing globals to avoid import-time fork hazards#2499

Merged
seratch merged 1 commit intomainfrom
fix/tracing-lazy-init-fork-safety
Feb 17, 2026
Merged

fix: #2489 lazily initialize tracing globals to avoid import-time fork hazards#2499
seratch merged 1 commit intomainfrom
fix/tracing-lazy-init-fork-safety

Conversation

@seratch
Copy link
Member

@seratch seratch commented Feb 17, 2026

This pull request fixes import-time tracing side effects that could break fork-based process models by moving tracing bootstrap to lazy, first-use initialization. Importing agents no longer eagerly creates the default BackendSpanExporter (httpx.Client), BatchTraceProcessor threading primitives, or the default provider wiring.

The change updates tracing setup so get_trace_provider() performs one-time lazy bootstrap (provider + default processor + shutdown registration) under locking, while preserving existing public tracing APIs. It also adds regression tests that validate no tracing globals are initialized on import agents, that lazy bootstrap happens on first access, that bootstrap is one-time, and that explicitly setting a custom provider does not force default exporter/processor construction.

This pull request resolves #2489.

@seratch seratch added this to the 0.9.x milestone Feb 17, 2026
@github-actions github-actions bot added bug Something isn't working feature:tracing labels Feb 17, 2026
@seratch seratch merged commit a226a0d into main Feb 17, 2026
9 checks passed
@seratch seratch deleted the fix/tracing-lazy-init-fork-safety branch February 17, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracing module creates httpx.Client and threading primitives at import time (fork safety hazard)

1 participant