Skip to content

fix: inject trace context headers per-request instead of at client construction#870

Open
ctiliescuuipath wants to merge 2 commits into
mainfrom
fix/per-request-trace-context-headers
Open

fix: inject trace context headers per-request instead of at client construction#870
ctiliescuuipath wants to merge 2 commits into
mainfrom
fix/per-request-trace-context-headers

Conversation

@ctiliescuuipath
Copy link
Copy Markdown
Contributor

@ctiliescuuipath ctiliescuuipath commented May 21, 2026

Summary

  • Move W3C trace context header injection from build_uipath_headers() (called once at client init) to per-request hooks in each transport, so headers reflect the active OTEL span at call time
  • Legacy OpenAI/Bedrock/Vertex: inject in transport handle_request / handle_async_request
  • New clients: inject via _TraceContextHeadersCallback using the dynamic-headers ContextVar
  • Add tests for the new callback and _ensure_trace_context_callback helper

Test plan

  • Verify test_trace_context_callback.py passes
  • Confirm legacy OpenAI, Bedrock, and Vertex transports include trace context headers per-request
  • Confirm new client path injects headers via the callback + ContextVar

🤖 Generated with Claude Code

Development Package

  • Use uipath pack --nolock to get the latest dev build from this PR (requires version range).
  • Add this package as a dependency in your pyproject.toml:
[project]
dependencies = [
  # Exact version:
  "uipath-langchain==0.11.4.dev1008704671",

  # Any version from PR
  "uipath-langchain>=0.11.4.dev1008700000,<0.11.4.dev1008710000"
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath-langchain = { index = "testpypi" }

[tool.uv]
override-dependencies = [
    "uipath-langchain>=0.11.4.dev1008700000,<0.11.4.dev1008710000",
]

…nstruction

Move W3C trace context header injection from `build_uipath_headers()`
(called once at client init) to per-request hooks in each transport, so
headers reflect the active OTEL span at call time.

- Legacy OpenAI/Bedrock/Vertex: inject in transport `handle_request`
- New clients: inject via `_TraceContextHeadersCallback` + dynamic headers ContextVar
- Remove trace context from shared `build_uipath_headers()`

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ntextVar

Tests were calling a non-existent get_headers() method. Updated to call
_merge_headers() and verify results via the ContextVar, matching the
actual callback implementation. Also fixed mypy variance error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
70.6% Coverage on New Code (required ≥ 90%)

See analysis details on SonarQube Cloud

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant