Skip to content

fix(runner): framework-agnostic observability naming + MLflow trace IDs#1283

Merged
jeremyeder merged 5 commits intoambient-code:mainfrom
etirelli:fix/observability-naming-mlflow-trace-ids
Apr 10, 2026
Merged

fix(runner): framework-agnostic observability naming + MLflow trace IDs#1283
jeremyeder merged 5 commits intoambient-code:mainfrom
etirelli:fix/observability-naming-mlflow-trace-ids

Conversation

@etirelli
Copy link
Copy Markdown
Contributor

@etirelli etirelli commented Apr 10, 2026

Summary

Follow-up to the merged MLflow observability work: main landed the integration before these two commits could ship. This PR restores them.

1. Framework-agnostic tracing names (Langfuse + MLflow)

  • Turn trace / span name: claude_interactionllm_interaction
  • Langfuse tags: claude-coderunner:<RUNNER_TYPE> (from RUNNER_TYPE)
  • Session metrics span: Claude Code - Session MetricsSession Metrics
  • Metrics source metadata: claude-code-metricsambient-runner-metrics
  • Module docs updated so observability is described as runner-wide, not Claude-only.

Migration: Existing Langfuse dashboards, alerts, or saved views that filter on the old trace name or tags need to be updated to the new values.

2. MLflow-only: trace IDs for middleware and feedback

When OBSERVABILITY_BACKENDS=mlflow (no Langfuse turn), the runner now:

  • Exposes mlflow.get_active_trace_id() via ObservabilityManager.get_current_trace_id()
  • Syncs last_trace_id after start_turn so AG-UI trace events, corrections, and /feedback resolution behave like the Langfuse path.

Testing

  • pytest (runner): test_observability, test_observability_metrics, test_observability_mlflow_integration, test_privacy_masking (101 tests in local run)

Commits

  • refactor(runner): framework-agnostic observability naming (Gage review) (cherry-picked)
  • fix(runner): expose MLflow trace ids when Langfuse is off (cherry-picked)

Summary by CodeRabbit

  • New Features

    • Runner type is captured and included in observability metadata and span attributes.
  • Changes

    • Turn traces renamed vendor‑neutrally to "llm_interaction".
    • Session metrics span renamed to "Session Metrics" and source to "ambient-runner-metrics"; runner_type added.
    • Middleware event name changed to "ambient:trace_id" and reflects Langfuse or MLflow trace id.
  • Bug Fixes

    • Improved trace correlation and trace-id resolution between Langfuse and MLflow backends.
  • Documentation

    • README updated to document turn trace naming and runner type tagging.
  • Tests

    • Updated and added tests validating tagging, naming, and MLflow/Langfuse trace behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d3a9f891-e69b-42fd-8b11-7e82ac8b922e

📥 Commits

Reviewing files that changed from the base of the PR and between 1609635 and 9785493.

📒 Files selected for processing (9)
  • components/runners/ambient-runner/README.md
  • components/runners/ambient-runner/ambient_runner/middleware/tracing.py
  • components/runners/ambient-runner/ambient_runner/mlflow_observability.py
  • components/runners/ambient-runner/ambient_runner/observability.py
  • components/runners/ambient-runner/tests/test_observability.py
  • components/runners/ambient-runner/tests/test_observability_metrics.py
  • components/runners/ambient-runner/tests/test_observability_mlflow_integration.py
  • components/runners/ambient-runner/tests/test_privacy_masking.py
  • components/runners/ambient-runner/tests/test_tracing_middleware.py

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


📝 Walkthrough

Walkthrough

Vendor-specific observability artifacts were replaced with neutral ambient-runner naming: turn traces now use llm_interaction, runner-type tagging (runner:<type>) added to Langfuse tags and span metadata, MLflow trace-id correlation/fallback added, and session/metrics span names/constants standardized.

Changes

Cohort / File(s) Summary
Core Observability Implementation
components/runners/ambient-runner/ambient_runner/observability.py, components/runners/ambient-runner/ambient_runner/mlflow_observability.py
Introduced vendor-neutral constants (TURN_TRACE_NAME="llm_interaction", session metrics constants); added runner-type slugging and propagation (runner:<slug> / ambient.runner_type); added MLflow↔Langfuse trace-id correlation and _sync_last_trace_id_from_mlflow(); MLflowSessionTracer.initialize() now accepts runner_type.
Middleware
components/runners/ambient-runner/ambient_runner/middleware/tracing.py
Changed emitted CustomEvent name from ambient:langfuse_trace to ambient:trace_id; updated docstring to reflect Langfuse/MLflow as possible trace sources.
Documentation
components/runners/ambient-runner/README.md
Documented that turn traces use llm_interaction and that RUNNER_TYPE appears as runner:<type> in Langfuse tags and span metadata.
Unit Tests
components/runners/ambient-runner/tests/test_observability.py, components/runners/ambient-runner/tests/test_observability_metrics.py, components/runners/ambient-runner/tests/test_privacy_masking.py, components/runners/ambient-runner/tests/test_tracing_middleware.py
Updated expectations to llm_interaction, session metrics name/source and added runner_type metadata; middleware test expects ambient:trace_id.
Integration / Trace-id Tests
components/runners/ambient-runner/tests/test_observability_mlflow_integration.py
Added tests for trace-id resolution: prefer Langfuse trace when active, fall back to MLflow active trace when Langfuse inactive, and _sync_last_trace_id_from_mlflow() updates last_trace_id.

Sequence Diagram(s)

sequenceDiagram
  participant Runner as Runner
  participant ObsMgr as ObservabilityManager
  participant Langfuse as Langfuse
  participant MLflow as MLflow

  Runner->>ObsMgr: start_turn()
  alt Langfuse creates turn trace
    ObsMgr->>Langfuse: create turn trace (name: "llm_interaction", metadata: {"runner_type": slug})
    Langfuse-->>ObsMgr: turn.trace_id
    ObsMgr->>MLflow: optionally emit/associate span (include ambient.runner_type)
    ObsMgr-->>Runner: return turn context (trace_id from Langfuse)
  else Langfuse not producing turn
    ObsMgr->>MLflow: get_active_trace_id()
    MLflow-->>ObsMgr: mlflow_trace_id
    ObsMgr->>ObsMgr: _sync_last_trace_id_from_mlflow() -> set last_trace_id
    ObsMgr->>MLflow: create/associate turn span (use constants, include ambient.runner_type)
    ObsMgr-->>Runner: return turn context (trace_id from MLflow)
  end
Loading
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format (fix(runner): ...) and accurately describes the main changes: framework-agnostic observability naming and MLflow trace ID support.
Performance And Algorithmic Complexity ✅ Passed All new operations execute in O(1) time with environment variable reads and single API calls at reasonable frequencies; no loops, N+1 patterns, or unbounded buffers detected.
Security And Secret Handling ✅ Passed PR contains observability-only changes (trace naming, MLflow attributes, Langfuse tags). No hardcoded secrets, tokens, or sensitive credentials found. RUNNER_TYPE parameter used exclusively in non-security-critical observability paths.
Kubernetes Resource Safety ✅ Passed PR modifies only Python source code and documentation in components/runners/ambient-runner/; no Kubernetes manifests or infrastructure configuration files are affected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/runners/ambient-runner/ambient_runner/observability.py`:
- Around line 442-446: The documentation in tracing.py that describes the
"Langfuse trace ID" is outdated and the event name ambient:langfuse_trace is
misleading because get_current_trace_id() in observability.py can return either
a Langfuse or MLflow ID; update the comment/text around lines 45-46 to state the
event carries a trace ID from either Langfuse or MLflow depending on active
backend, and either rename the event to ambient:trace_id (and update all usages
and tests) or add an explicit note that ambient:langfuse_trace is historical but
may contain MLflow IDs; ensure you also update any middleware docs and
references that assume only Langfuse IDs and adjust observability.py emit points
to use the new event name if renamed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 97bae982-5f00-4d3b-b381-e08c25151ab5

📥 Commits

Reviewing files that changed from the base of the PR and between 5768e12 and 40179a8.

📒 Files selected for processing (7)
  • components/runners/ambient-runner/README.md
  • components/runners/ambient-runner/ambient_runner/mlflow_observability.py
  • components/runners/ambient-runner/ambient_runner/observability.py
  • components/runners/ambient-runner/tests/test_observability.py
  • components/runners/ambient-runner/tests/test_observability_metrics.py
  • components/runners/ambient-runner/tests/test_observability_mlflow_integration.py
  • components/runners/ambient-runner/tests/test_privacy_masking.py

@Gkrumbach07
Copy link
Copy Markdown
Contributor

ignore the two test failures, not real

@Gkrumbach07 Gkrumbach07 added the ambient-code:managed PR managed by AI automation label Apr 10, 2026
@ambient-code ambient-code bot force-pushed the fix/observability-naming-mlflow-trace-ids branch from 3541d01 to 1609635 Compare April 10, 2026 19:17
@ambient-code
Copy link
Copy Markdown
Contributor

ambient-code bot commented Apr 10, 2026

Automated fixes applied

1. CodeRabbit review comment addressed — renamed ambient:langfuse_traceambient:trace_id

  • Updated event name in tracing.py middleware
  • Updated docstring to clarify the trace ID comes from Langfuse or MLflow depending on the active backend
  • Updated test assertion in test_tracing_middleware.py

2. Merge conflict partially addressed

  • Added _privacy_masking_function alias (from main) and reordered imports to match main's style
  • However, a structural conflict in observability.py remains: the PR adds _runner_type_slug(), TURN_TRACE_NAME, SESSION_METRICS_SPAN_NAME, and SESSION_METRICS_SOURCE between the alias and _TOKEN_KEYS, which git cannot auto-merge
  • A rebase onto main is needed but cannot be pushed to the fork — the GitHub token lacks workflows permission for the fork repository (needed because main includes workflow file changes)

Action needed: The PR author (@etirelli) should rebase this branch onto main to resolve the remaining conflict, or a maintainer can re-create this PR from an origin branch.

CI failures (SDD boundary check, Video Review) are infrastructure issues (GitHub permissions), not code problems — confirmed by maintainer comment.

🤖 Session

Ambient Code Bot and others added 5 commits April 10, 2026 15:20
- Turn traces: llm_interaction; session metrics: Session Metrics
- Langfuse tag runner:<RUNNER_TYPE> instead of claude-code
- Session metric source ambient-runner-metrics + runner_type metadata
- MLflow spans: ambient.runner_type; same span names as Langfuse
- Docs: README + module docstrings

Made-with: Cursor
Use mlflow.get_active_trace_id() for get_current_trace_id and sync
last_trace_id after MLflow-only start_turn so middleware, corrections,
and feedback can correlate runs without Langfuse.

Made-with: Cursor
Re-expand the observability.py header with turn/tool trace hierarchy and
Langfuse/MLflow notes, using vendor-neutral naming (llm_interaction).

Made-with: Cursor
…e_id

The CustomEvent emitted by the tracing middleware can carry either a
Langfuse or MLflow trace ID depending on the active backend. Rename
the event from ambient:langfuse_trace to ambient:trace_id and update
the docstring to reflect this.

Addresses CodeRabbit review comment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… main

Move _privacy_masking_function alias after all imports, matching
main's ordering to prevent merge conflict on observability.py.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jeremyeder jeremyeder force-pushed the fix/observability-naming-mlflow-trace-ids branch from 1609635 to 9785493 Compare April 10, 2026 19:22
@jeremyeder jeremyeder merged commit 3dd8436 into ambient-code:main Apr 10, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ambient-code:managed PR managed by AI automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants