Skip to content

fix: add namespace, model, and provider to langfuse metadata so we ca…#565

Merged
VVoruganti merged 1 commit intomainfrom
rajat/langfuse-metadata
Apr 20, 2026
Merged

fix: add namespace, model, and provider to langfuse metadata so we ca…#565
VVoruganti merged 1 commit intomainfrom
rajat/langfuse-metadata

Conversation

@Rajat-Ahuja1997
Copy link
Copy Markdown
Collaborator

@Rajat-Ahuja1997 Rajat-Ahuja1997 commented Apr 15, 2026

…n filter

Summary by CodeRabbit

  • Tests

    • Added test coverage for Langfuse span name tracking with metadata validation.
  • New Features

    • Improved LLM call tracking with automatic Langfuse span updates capturing provider, model, and custom naming information per attempt.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2399c4d3-136a-47ad-8e24-028fd6b4f099

📥 Commits

Reviewing files that changed from the base of the PR and between 5a58a41 and 60e725c.

📒 Files selected for processing (3)
  • src/llm/api.py
  • src/llm/runtime.py
  • tests/utils/test_clients.py
✅ Files skipped from review due to trivial changes (1)
  • tests/utils/test_clients.py

Walkthrough

The changes add Langfuse span name tracking to LLM calls by introducing a helper function that conditionally updates Langfuse observations with provider, model, and optional name metadata during plan selection. The LLM API module invokes this helper after choosing an attempt plan, and a test verifies the span update behavior.

Changes

Cohort / File(s) Summary
Langfuse Runtime Integration
src/llm/runtime.py
Added update_current_langfuse_observation helper function that conditionally updates Langfuse span metadata with namespace, provider, model, and optional name. Includes early return if LANGFUSE_PUBLIC_KEY is unset and error handling with debug logging.
LLM Call Plan Tracking
src/llm/api.py
Modified _get_attempt_plan closure in honcho_llm_call to invoke update_current_langfuse_observation after plan generation, passing the selected plan's provider and model along with the optional track_name parameter.
Test Coverage
tests/utils/test_clients.py
Added async test test_track_name_updates_langfuse_span_name that mocks Anthropic client and Langfuse interactions, verifying update_current_span is called with correct name and metadata (namespace, provider, model) when using honcho_llm_call with track_name.

Sequence Diagram(s)

sequenceDiagram
    participant Client as honcho_llm_call
    participant Planner as _get_attempt_plan
    participant Selector as plan_attempt
    participant Updater as update_current_langfuse_observation
    participant Langfuse as Langfuse Client
    participant Settings as Settings Config

    Client->>Planner: invoke for attempt plan
    Planner->>Selector: call plan_attempt(...)
    Selector-->>Planner: return plan{provider, model}
    Planner->>Updater: call with plan.provider, plan.model, name
    Updater->>Settings: check LANGFUSE_PUBLIC_KEY
    Settings-->>Updater: return key status
    alt Key set
        Updater->>Langfuse: call update_current_span(name, metadata)
        Langfuse-->>Updater: ✓ span updated
    else Key not set
        Updater-->>Updater: return early
    end
    Updater-->>Planner: return
    Planner-->>Client: return plan
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Langfuse spans now wear their names with pride,
Provider, model, metadata inside,
When plans are chosen, observations glow,
Tracking whispers of each LLM flow!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding namespace, model, and provider to Langfuse metadata for filtering purposes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rajat/langfuse-metadata

Comment @coderabbitai help to get the list of available commands and usage tips.

@VVoruganti VVoruganti force-pushed the rajat/langfuse-metadata branch from 5a58a41 to 60e725c Compare April 20, 2026 20:20
@VVoruganti VVoruganti merged commit 2c50791 into main Apr 20, 2026
10 checks passed
@VVoruganti VVoruganti deleted the rajat/langfuse-metadata branch April 20, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants