Python: record gen_ai.client.operation.duration for failed chat and embedding calls - #8347
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Streaming finalizer and result-hook failures still omit the operation-duration metric.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds failed-operation duration metrics for Python chat and embedding telemetry.
Changes:
- Centralizes GenAI metric attribute filtering.
- Records duration and
error.typefor chat and embedding failures. - Adds failure-path unit tests.
File summaries
| File | Description |
|---|---|
python/packages/core/agent_framework/observability.py |
Adds error-duration metric capture. |
python/packages/core/tests/core/test_observability.py |
Tests filtering and failure paths. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
…ze_stream Narrow error handling to get_final_response and re-raise exceptions while independently guarding telemetry capture, ensuring caller outcomes and duration error metrics remain aligned.
|
Thanks for the update. Before this is ready, could you please:
Once those are addressed, please re-request review. Thanks! |
|
Eduard van Valkenburg (@eavanvalkenburg) Resolved the review discussion thread and addressed the feedback in commit 465198a (re-raising exceptions on |
|
Please fix the failing CI/CD checks. |
|
The failing Hyperlight cleanup test was racing background directory removal. I merged upstream Preflight CI on this exact commit passed all 10 Linux/Windows unit-test jobs across Python 3.10–3.14. The Ubuntu/Python 3.11 coverage check also passed: 91.1% overall, with every enforced package meeting the 85% threshold. The new upstream workflows are awaiting approval, so their results are still pending. Could a maintainer approve those runs? |
Motivation & Context
OpenTelemetry Semantic Conventions for Generative AI operations define
gen_ai.client.operation.durationfor failed operations as well as successful ones, witherror.typeset to the class of the error. Recording only successes leaves error latency out of the metric and prevents calculating error rates from operation duration histograms.This resolves #7818, incorporating previous feedback from Eduard van Valkenburg (@eavanvalkenburg) by centralizing GenAI metric attribute filtering and adding tests for synchronous chat, streaming setup/iteration, and embedding failure paths.
Description & Review Guide
_filter_metric_attributesto projectGEN_AI_METRIC_ATTRIBUTESin a single place._capture_operation_errorto recordoperation_duration_histogramon failures witherror.type.ChatTelemetryLayer(non-streaming, streaming setup, and streaming iteration) to record operation duration on error before closing/raising.EmbeddingTelemetryLayerto record operation duration on error.ChatTelemetryLayerandEmbeddingTelemetryLayer.Related Issue
Fixes #7818
Contribution Checklist