Commit 8bae410
feat: Emit OTEL attributes for AgentCore Evaluation support (#368)
* feat: Emit OTEL attributes for AgentCore Evaluation support
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
* Do not override user_prompt/agent_response if already set on span
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.
* Address PR feedback: prompt_key/response_key, Response early-return fix
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.
---------
Co-authored-by: Lior Shoval <lshoval@amazon.com>1 parent 2c4911d commit 8bae410
2 files changed
Lines changed: 386 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
147 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
151 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
155 | 173 | | |
156 | | - | |
157 | | - | |
158 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
159 | 187 | | |
160 | 188 | | |
161 | 189 | | |
| |||
384 | 412 | | |
385 | 413 | | |
386 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
387 | 487 | | |
388 | 488 | | |
389 | 489 | | |
| |||
411 | 511 | | |
412 | 512 | | |
413 | 513 | | |
| 514 | + | |
| 515 | + | |
414 | 516 | | |
415 | 517 | | |
416 | 518 | | |
| |||
0 commit comments