fix(security): isolate Langfuse v3 SDK TracerProvider to prevent cros…#36107
Merged
Merged
Conversation
…s-tenant trace leak Langfuse Python SDK v3 (introduced in #34265) attaches its SpanProcessor to the *global* OpenTelemetry TracerProvider when no explicit tracer_provider is passed. With ext_otel.py already installing a global TracerProvider and FlaskInstrumentor active, every Flask / Celery / SQLAlchemy span emitted by the process — across all tenants — was being exported to the first tenant who configured a workflow-level Langfuse integration. Fix: - Construct an isolated TracerProvider per LangFuseDataTrace instance and pass it via the documented tracer_provider= kwarg so the SDK never touches the global provider. - Add close() / __del__ to shut down the isolated provider when the trace instance is evicted from the LRU cache, avoiding background batch exporter thread leaks on config rotation. Tests: - Regression test asserting Langfuse() receives an isolated TracerProvider distinct from the global one. - Tests for close() shutdown and idempotency. Refs: - langfuse upgrade guide v2 -> v3 (warns about cross-instrumentation capture) - https://github.com/orgs/langfuse/discussions/9136
Contributor
Pyrefly Type Coverage
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…s-tenant trace leak
Langfuse Python SDK v3 (introduced in #34265) attaches its SpanProcessor to the global OpenTelemetry TracerProvider when no explicit tracer_provider is passed. With ext_otel.py already installing a global TracerProvider and FlaskInstrumentor active, every Flask / Celery / SQLAlchemy span emitted by the process — across all tenants — was being exported to the first tenant who configured a workflow-level Langfuse integration.
Fix:
Tests:
Refs:
Important
Fixes #<issue number>.Summary
Screenshots
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods