feat: Emit OTEL attributes for AgentCore Evaluation support#368
Merged
jesseturner21 merged 3 commits intomainfrom Mar 26, 2026
Merged
feat: Emit OTEL attributes for AgentCore Evaluation support#368jesseturner21 merged 3 commits intomainfrom
jesseturner21 merged 3 commits intomainfrom
Conversation
Add _emit_invocation_otel_attributes() to BedrockAgentCoreApp that automatically emits agentcore.invocation.user_prompt and agentcore.invocation.agent_response as OTEL span attributes on the root POST /invocations span. These attributes provide a canonical, framework-agnostic source of the user's prompt and the agent's response for AgentCore Evaluation. They enable evaluation of workflow agents that use custom state schemas (e.g. TypedDict with user_input/final_response fields) where the default MessagesState-based extraction in the evaluation mapper would fail silently with null scores. The method: - Extracts user prompt from the payload dict (tries common keys like prompt, input, query, message, falls back to full JSON) - Extracts agent response from the entrypoint return value - Skips silently for streaming responses or when OTEL is not installed - Attributes are capped at 16KB to stay within OTEL limits
Check span.attributes before setting agentcore.invocation.user_prompt and agentcore.invocation.agent_response so that user-provided values are not overwritten by auto-extraction.
1. Remove broken span.attributes guard — active Span doesn't expose .attributes (only ReadableSpan does), so the check was a no-op in prod. 2. Add prompt_key and response_key params to @app.entrypoint() so users can control which payload/result keys are used for OTEL attributes. Default (None) preserves the existing heuristic behavior. 3. Fix early return on Response objects — previously skipped user_prompt emission too. Now only skips agent_response for streaming responses.
3ce4a14 to
306f602
Compare
notgitika
approved these changes
Mar 26, 2026
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
_emit_invocation_otel_attributes()toBedrockAgentCoreAppthat automatically emitsagentcore.invocation.user_promptandagentcore.invocation.agent_responseas OTEL span attributes on the rootPOST /invocationsspanTypedDictwithuser_input/final_responsefields) where the defaultMessagesState-based extraction in the evaluation mapper fails silently with null scoresprompt_keyandresponse_keyparams to@app.entrypoint()so users can control which payload/result keys are used for OTEL attributesTest plan
TestEmitInvocationOtelAttributes)