fix(observability): support langfuse_otel in litellm handler and add opentelemetry dependencies - #2709
Conversation
PR Summary by QodoPin Langfuse 2.59.7 for LiteLLM callback compatibility
AI Description
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Duplicate Langfuse callbacks registered
|
…opentelemetry dependencies
2a12c5f to
c2dcad2
Compare
| litellm.success_callback = get_settings().litellm.success_callback | ||
| success_cb = get_settings().litellm.success_callback | ||
| if isinstance(success_cb, list): | ||
| success_cb = ["langfuse_otel" if c == "langfuse" else c for c in success_cb] |
There was a problem hiding this comment.
2. Duplicate langfuse callbacks registered 🐞 Bug ≡ Correctness
Mapping each entry independently turns ["langfuse", "langfuse_otel"] into two langfuse_otel entries, causing duplicate tracing callbacks and duplicate Langfuse events. The same defect affects success, failure, and service callback lists.
Agent Prompt
## Issue description
Callback normalization replaces every legacy `langfuse` entry independently, so configurations containing both legacy and OTel callback names produce duplicate `langfuse_otel` registrations.
## Issue Context
Normalize each callback collection so non-Langfuse callbacks are preserved while legacy entries are removed and exactly one `langfuse_otel` entry remains. Apply this consistently to success, failure, and service callbacks, and add coverage for mixed and repeated entries.
## Fix Focus Areas
- pr_agent/algo/ai_handlers/litellm_ai_handler.py[151-164]
- tests/unittest/test_mosaico_env_bridge.py[89-108]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit c2dcad2 |
Summary
Enables seamless Langfuse v3 tracing via OpenTelemetry (
langfuse_otel) across PR-Agent by adding required OpenTelemetry dependencies and supportinglangfuse_otelmetadata inLiteLLMAIHandler.Motivation & Problem
langfuse==3.14.5(required by MOSAICO's direct tracing APIs such asget_client,propagate_attributes, andstart_as_current_observation).sdk_integrationCrash: In Langfuse v3, the legacy callback["langfuse"]in LiteLLM raisesTypeError: Langfuse.__init__() got an unexpected keyword argument 'sdk_integration'.langfuse_otel, LiteLLM requires OpenTelemetry packages (opentelemetry-api,opentelemetry-sdk,opentelemetry-exporter-otlp), andLiteLLMAIHandlerpreviously only injected PR metadata (trace_name,tags,trace_metadata) when"langfuse"was in callbacks, omitting"langfuse_otel".Solution
opentelemetry-api==1.28.0,opentelemetry-sdk==1.28.0, andopentelemetry-exporter-otlp==1.28.0torequirements.txt."langfuse"callback entries to"langfuse_otel"during handler initialization, ensuring backwards compatibility for users configuringLITELLM.SUCCESS_CALLBACK: ["langfuse"].add_litellm_callbacksto inject trace metadata (command,pr_url,tags) for"langfuse_otel"callbacks.