Repository navigation
Conversation
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Haystack 2.x,
OpenAIChatGenerator.run()andOpenAIGenerator.run()return their results as a dict:{"replies": [ChatMessage, ...]}/{"replies": [str, ...]}(verified againsthaystack-ai 2.3.1, the version this repo's lock file pins).The OpenAI wrapper in this instrumentation passed that whole dict to the completion serializer, which does
for index, message in enumerate(choices). Enumerating a dict iterates its keys, so on every Haystack OpenAI call the span recorded:gen_ai.completion.0.content="replies"(the literal key name)So the
haystack.openai.chat/haystack.openai.completionspans never carried what the model actually answered.The fix unpacks the
replieslist before serializing, and for the chat path serializes aChatMessagevia its.contentstring (previously a rawChatMessageobject would have been set as the attribute value, which the OTel API silently drops). Behavior when the wrapped call returns a non-dict is unchanged.Validation
Inside
packages/opentelemetry-instrumentation-haystack(uv-managed,haystack-ai==2.3.1):runreturning a Haystack-shaped result:test_chat_generator_records_reply_content(chat path,ChatMessagereplies)test_generator_records_reply_content(plain generator path, string replies)assert 'replies' == 'Hello there'/assert 'replies' == 'first reply'(red log attached).uv run --no-sync pytest tests/→ 4 passed (2 existing vcr tests + 2 new) (green log attached).uv run --no-sync ruff check .→ All checks passed.git diff --checkclean.AI assistance
This change was prepared with AI coding assistance (bug located by code inspection against the pinned haystack-ai version; tests and fix written and verified locally). The CI workflow does not forbid AI-assisted contributions; disclosing here for transparency.
No public issue tracked this specific defect (the related open issue #1169 reports missing
traceloop.entity.input/outputon the workflow root span, a different facet).Summary by CodeRabbit