Skip to content

fix(security): isolate Langfuse v3 SDK TracerProvider to prevent cros…#36107

Merged
GareArc merged 1 commit into
hotfix/1.14.1-fix.1from
fix/langfuse-v3-global-tracer-leak
May 13, 2026
Merged

fix(security): isolate Langfuse v3 SDK TracerProvider to prevent cros…#36107
GareArc merged 1 commit into
hotfix/1.14.1-fix.1from
fix/langfuse-v3-global-tracer-leak

Conversation

@GareArc
Copy link
Copy Markdown
Contributor

@GareArc GareArc commented May 13, 2026

…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:

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

…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
@GareArc GareArc requested a review from QuantumGhost as a code owner May 13, 2026 06:34
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 43.67% +43.67%
Strict coverage 0.00% 43.19% +43.19%
Typed symbols 0 22,043 +22,043
Untyped symbols 0 28,748 +28,748
Modules 0 2551 +2,551

@GareArc GareArc requested a review from zyssyz123 May 13, 2026 06:36
Copy link
Copy Markdown
Contributor

@zyssyz123 zyssyz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 13, 2026
@GareArc GareArc merged commit 7e5c651 into hotfix/1.14.1-fix.1 May 13, 2026
4 checks passed
@GareArc GareArc deleted the fix/langfuse-v3-global-tracer-leak branch May 13, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants