fix(hermes): preserve provider response IDs - #247
Conversation
SummaryIntroduces provider response ID capture for Hermes LLM spans via a thread-local FindingsNo blocking issues. One minor note:
Code Quality Highlights
Automated review by github-manager-bot |
89e6c5f to
54650a2
Compare
ralf0131
left a comment
There was a problem hiding this comment.
Summary
LGTM — This PR correctly implements provider-first response ID extraction for Hermes instrumentation. The implementation:
- Well-designed utility module —
response_id.pyprovides clean abstractions for response ID extraction with proper field ordering and error handling - Robust thread isolation — Thread-local storage correctly isolates concurrent requests, with proper cleanup in finally blocks
- Correct priority handling — DashScope
request_id> OpenAI-compatibleid> framework response ID - Graceful degradation — Telemetry never breaks the model call, even with read-only provider resources
- Comprehensive tests — Excellent coverage including streaming, retries, thread isolation, error handling, and fallback scenarios
The dependency version alignment (~= 1.39.1) is appropriate for LoongSuite's release strategy.
Automated review by github-manager-bot
ralf0131
left a comment
There was a problem hiding this comment.
LGTM. Clean fix that correctly prefers provider response IDs over framework-generated ones.
Highlights:
response_id.pyutility is well-designed: proper normalization (bool rejection, whitespace trimming), supports both Mapping and attribute access, handles lazy-load SDK exceptions gracefullyProviderClientWrappercleanly intercepts the OpenAI-compatible client to capture provider IDs without disrupting the call chain- Thread-safe retry isolation with per-attempt response ID tracking
- Good test coverage including edge cases (raising properties, transport IDs, empty strings)
Automated review by github-manager-bot
ralf0131
left a comment
There was a problem hiding this comment.
Summary
Fixes gen_ai.response.id to prefer provider-supplied identifiers (including DashScope request_id) over Hermes's synthetic response ID. Introduces a shared response_id.py helper in util-genai and a ProviderClientWrapper for invocation-local ID capture with proper thread isolation via threading.local().
Findings
- [Info] The priority system (
request_id>id>response_id) is well-documented and the streaming trailer edge case (laterequest_idreplacing earlier chunkid) is correctly handled with the priority counter. - [Info] Good fail-open behavior: read-only provider resources (slots/descriptors) gracefully fall back without breaking the model call.
Suggestions
- The comprehensive test matrix (streaming, retry, thread isolation, error paths, stale attempt prevention) provides strong confidence. The OTel dependency alignment (1.39.1/0.60b1) is a good housekeeping addition.
Automated review by github-manager-bot
|
This PR has conflicts with the git fetch origin
git checkout fix/hermes-provider-response-id
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
ralf0131
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed after new commits (HEAD changed from 89e6c5f6 to 54650a2f).
This PR correctly preserves provider response IDs in Hermes instrumentation:
Key changes:
- Adds shared
util-genaihelperresolve_response_id()for provider-first extraction with framework fallback - Handles DashScope
request_idwith higher priority than OpenAI-compatibleid(correct for Alibaba Cloud scenarios) - Thread-local attempt isolation for retry scenarios (
_attempt_response_id_store) - Transparent stream proxy observes chunks without modifying them
- Aligns OTel dependencies with LoongSuite 0.7.0 release set (
~= 1.39.1/~= 0.60b1)
Code quality:
- Well-structured with clear separation of concerns
- Comprehensive test coverage including streaming and retry scenarios
- Proper handling of edge cases (missing provider ID, thread isolation)
main. Please rebase to resolve conflicts before merging.
LGTM.
Automated review by github-manager-bot
ralf0131
left a comment
There was a problem hiding this comment.
Summary
This PR introduces a shared response_id utility in util-genai and wires it into the Hermes instrumentation to prefer provider-supplied response IDs (including DashScope request_id) over the synthetic Hermes framework ID for gen_ai.response.id. The design is clean, thread-safe, and well-tested.
A few minor observations below.
Findings
- [Info]
wrappers.py—_ProviderResponseAttempt.record()uses athreading.Lockfor every call. Since the critical section is tiny (just a comparison + assignment), consider whether the lock overhead matters in high-throughput streaming scenarios. Likely fine, but worth a comment explaining the choice. - [Info]
wrappers.py:452—provider_response_capture = _ProviderResponseIdCapture()is created unconditionally even when the provider doesn't expose any ID. This is harmless but could be lazily initialized if profiling shows it matters. - [Info]
pyproject.toml— The shift from range constraints (>= 1.37.0, < 1.40) to compatible-release (~= 1.39.1) is intentionally narrower. This is fine for alignment with LoongSuite 0.7.0, but downstream consumers upgrading from older OTel versions will need to bump their dependencies. The CHANGELOG entry covers this well.
Suggestions
- The
_PROVIDER_ATTEMPTand_PROVIDER_CAPTUREthread-locals are module-level. Consider adding a brief docstring comment explaining the lifecycle (created per-invocation, reset in__call__) to help future maintainers understand the threading model. - The
extract_response_idfunction's broadexcept Exceptioncatch is appropriate for telemetry code (must never break the model call), but a# nosecor comment explaining the rationale would satisfy strict linters.
Overall: well-structured change with good test coverage across sync, streaming, retry, and error paths. The priority system for DashScope request_id > OpenAI id is correctly implemented.
Automated review by github-manager-bot
Description
This PR makes the Hermes instrumentation prefer the model provider's operation/request identifier for
gen_ai.response.idinstead of the synthetic response identifier produced by Hermes.It adds a shared
util-genaihelper for provider-first response-ID extraction with framework fallback, then uses that helper in Hermes as the first consumer. Hermes observes request-local OpenAI-compatiblechat.completions.createresponses and streaming chunks, isolates retry attempts across worker threads, propagates the selected identifier to LLM and aggregate AGENT spans, and falls back to the Hermes response identifier when the provider does not expose one.For providers such as DashScope,
request_idintentionally has higher priority than the OpenAI-compatible completionid. A later streaming usage trailer carryingrequest_idcan therefore replace an earlier chunkid. Transport-only metadata such as_request_idand HTTP headers is not read implicitly.The Hermes package is also aligned with the OpenTelemetry release set used by LoongSuite 0.7.0: compatible-release floors of API/SDK 1.39.1 and instrumentation/semantic-conventions 0.60b1, with the exact set pinned in tests.
Fixes # (N/A)
Type of change
How Has This Been Tested?
tox -e precommitpyright util/opentelemetry-util-genai/src/opentelemetry/util/genai/response_id.pypytest -q util/opentelemetry-util-genai/tests/test_response_id.py instrumentation-loongsuite/loongsuite-instrumentation-hermes-agent/tests/test_telemetry_spec.pyDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
Validation Evidence
Spec and Scope
request_id,id, orresponse_id; fall back to the Hermes response ID only when no provider value is available.Local Checks
response_id.pyreports 0 errors, 0 warnings, and 0 information messages.Real E2E Matrix
stream-*fallback.Telemetry and Weaver
CI
typecheck, which reported the two Pyright Unknown-type errors fixed by this update.