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 |
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.