Add Langfuse integration for Temporal workflows#1629
Draft
jannikmaierhoefer wants to merge 1 commit intomainfrom
Draft
Add Langfuse integration for Temporal workflows#1629jannikmaierhoefer wants to merge 1 commit intomainfrom
jannikmaierhoefer wants to merge 1 commit intomainfrom
Conversation
Introduces langfuse.temporal.LangfusePlugin, a Temporal SimplePlugin that enriches the OTel spans produced by temporalio.contrib.opentelemetry with Langfuse session/user/tag/metadata attributes and optional payload captures. The plugin defaults to metadata-only capture, stays sandbox/replay safe, and composes with framework plugins (OpenAIAgentsPlugin, PydanticAIPlugin) rather than replacing them. https://claude.ai/code/session_013bfLpjTrf8qPkTftZHb9Hf
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.
Summary
This PR adds a comprehensive Langfuse integration for Temporal (
temporalio), enabling observability of Temporal workflows and activities through OpenTelemetry spans routed to Langfuse. The integration enriches Temporal spans with Langfuse-specific metadata (session ID, user ID, tags, metadata) and optional input/output payloads.Key Changes
Core Plugin Implementation
langfuse/temporal/plugin.py: MainLangfusePluginclass that extendstemporalio.plugin.SimplePlugin. Registers both the Temporal OpenTelemetry interceptor and a Langfuse enrichment interceptor. Handles client initialization and graceful shutdown with flushing.langfuse/temporal/interceptor.py: Span enrichment interceptor that decorates OpenTelemetry spans with Langfuse attributes. Implements hooks for:Configuration System
langfuse/temporal/config.py: Comprehensive configuration dataclasses:LangfusePluginConfig: Main configuration with sensible defaults (metadata-only by default)CaptureConfig: Controls for payload capture with allowlist/denylist support per workflow/activityTracingConfig: Toggles for which Temporal surfaces produce spansUIEnrichmentConfig: Correlation with Temporal UIFactoryContext: Context passed to user-provided factory callbacks for dynamic metadataSupporting Modules
langfuse/temporal/attributes.py: Centralized OpenTelemetry span attribute key definitions for Langfuse and Temporal metadatalangfuse/temporal/redaction.py: Payload serialization, redaction, and size-limiting utilities. Supports custom redaction callbacks and graceful handling of non-JSON-serializable objectslangfuse/temporal/presets.py: Framework-specific plugin composition helpers for OpenAI Agents SDK and Pydantic AI integrationslangfuse/temporal/__init__.py: Public API exportsTesting
tests/unit/temporal/test_enrichment.py: Unit tests for span enrichment logic with fake spans (no Temporal dependency required)tests/unit/temporal/test_redaction.py: Tests for payload serialization and redactiontests/unit/temporal/test_plugin.py: Plugin instantiation and configuration tests (skipped iftemporalionot installed)tests/unit/temporal/test_config.py: Configuration dataclass validation testsNotable Implementation Details
langfuse.temporalmodule can be imported and tested without Temporal installed.temporalio.workflow.info(). The Langfuse client is used exclusively from the worker process.Falseto prevent accidental export of sensitive data.workflow_idper the trace model requirements.Dependencies
Added optional
temporaldependency group requiringtemporalio>=1.18.0,<2.https://claude.ai/code/session_013bfLpjTrf8qPkTftZHb9Hf