Skip to content

feat(tracing): derive LLM Ops URL source param from span Source field#1783

Open
saksharthakkar wants to merge 3 commits into
mainfrom
feat/derive-trace-source
Open

feat(tracing): derive LLM Ops URL source param from span Source field#1783
saksharthakkar wants to merge 3 commits into
mainfrom
feat/derive-trace-source

Conversation

@saksharthakkar

@saksharthakkar saksharthakkar commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Motivation

The ?source= query param on the v3 ingest call is what the server persists as Trace.Source (the span body Source is ignored on ingest), but _build_url hardcoded CodedAgents — so every non-coded-agent producer that exports through this SDK (e.g. Agent Builder, which sets uipath.source=1Agents) was mislabeled CodedAgents, corrupting per-product migration/cost attribution on the v2→v3 dashboards. This derives the param from the span's already-resolved SpanSource, so each producer self-labels with no per-repo changes. Supersedes stale PR #1428 (re-implemented cleanly on the current v3 URL + SpanSource StrEnum).

Summary

  • LlmOpsHttpExporter._build_url now reads span_list[0]["Source"] (a SpanSource) and renders its wire string into &source=…, defaulting to CodedAgents when absent (back-compat for coded agents and minimal/fallback span dicts).
  • Import SpanSource alongside SpanStatus from uipath.platform.common._span_utils.
  • v3 endpoint (/api/Traces/v3/spans) unchanged; no server, dependency, or uipath-agents-python changes.
  • Added 4 tests: explicit Agents, explicit CodedAgents, missing-Source default, and an end-to-end guard driving uipath.source=1 through otel_span_to_uipath_span().to_dict()_build_url&source=Agents.

Tests performed

cd packages/uipath && uv run pytest tests/tracing/test_otel_exporters.py (documented via showboat):

  • Source-derivation (3/3 passed): test_build_url_uses_span_source_agents (renders source=Agents, not CodedAgents — the regression guard), test_build_url_uses_span_source_coded_agents, test_build_url_defaults_to_coded_agents_when_source_missing.
  • End-to-end (1/1 passed): test_agent_builder_span_yields_source_agents — real span with uipath.source=1 resolves to Source=Agents and yields &source=Agents.
  • Full exporter file: 35/35 passed, no regressions; _otel_exporters.py coverage 73%.
  • Live run (alpha / joetest / ToBeDeleted): deployed the branch as a hacked-coded agent (editable local SDK), ran a Serverless job → Successful, 4 spans ingested to /api/Traces/v3/spans (200). The trace's agent spans stored Source=Agents, and running the deployed branch's _build_url against that trace emits …&source=Agents (vs &source=CodedAgents for a Source-less span).

OR Test

image

Test plan

  • uv run pytest tests/tracing/test_otel_exporters.py green (35/35)
  • _build_url has no hardcoded source= literal; v3 endpoint intact
  • ruff check / ruff format --check clean on changed files
  • End-to-end: Agent Builder–style span (uipath.source=1) exports as source=Agents
  • Reviewer confirms server persists Trace.Source=Agents from the query param (server-side behavior; out of scope for this diff)

🤖 Generated with Claude Code

https://claude.ai/code/session_0137aKdrnRYUdFg7iY7GmPYM

saksharthakkar and others added 2 commits July 1, 2026 16:13
The ?source= query param is what the server persists as Trace.Source
(the span-body Source is ignored on ingest), but _build_url hardcoded
CodedAgents, mislabeling every non-coded-agent producer that exports
through this SDK (e.g. Agent Builder, which sets uipath.source=1=Agents).
Derive source from span_list[0]['Source'] (SpanSource), defaulting to
CodedAgents. Re-implements the intent of stale PR #1428 on the v3 URL.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137aKdrnRYUdFg7iY7GmPYM
Guards the full attribute->Source->URL path so a future change to the
uipath.source mapping can't silently regress source attribution.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137aKdrnRYUdFg7iY7GmPYM
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jul 1, 2026
@saksharthakkar saksharthakkar changed the title (wip) feat(tracing): derive LLM Ops URL source param from span Source field feat(tracing): derive LLM Ops URL source param from span Source field Jul 1, 2026
Release the LLM Ops trace source-derivation fix in _build_url.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137aKdrnRYUdFg7iY7GmPYM
@saksharthakkar saksharthakkar marked this pull request as ready for review July 1, 2026 23:49
Copilot AI review requested due to automatic review settings July 1, 2026 23:49
@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the LLM Ops HTTP exporter to derive the source query parameter from the span’s resolved Source field (a SpanSource) instead of hardcoding CodedAgents, ensuring traces are attributed to the correct producing product on the server-side Trace.Source.

Changes:

  • Derive &source=... in LlmOpsHttpExporter._build_url() from span_list[0].get("Source"), defaulting to SpanSource.CODED_AGENTS when absent.
  • Add targeted unit + end-to-end-style tests validating explicit Sources and the uipath.source=1 -> Source=Agents -> &source=Agents flow.
  • Bump uipath package version from 2.12.4 to 2.12.5.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/uipath/src/uipath/tracing/_otel_exporters.py Builds v3 ingest URL using the span’s SpanSource for the source query param (with CodedAgents fallback).
packages/uipath/tests/tracing/test_otel_exporters.py Adds regression and end-to-end guard tests for correct source= derivation and defaulting behavior.
packages/uipath/pyproject.toml Version bump to release the tracing attribution fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants