Add streaming metrics and attribute#269
Conversation
eb74d0f to
cb3b195
Compare
| # There is currently nothing to pin: anthropic has no test-only dependency that isn't already | ||
| # provided by a declared bound or by the shared test fixtures. | ||
| # Drop this once opentelemetry-util-genai 1.1b0 is published. | ||
| -e util/opentelemetry-util-genai |
There was a problem hiding this comment.
todo: let's automate it in post-release workflow
Pull request dashboard statusStatus: Waiting on reviewers to review the latest changes. |
There was a problem hiding this comment.
Pull request overview
This PR extends the shared opentelemetry-util-genai streaming wrappers and invocation lifecycle to emit streaming timing telemetry (TTFC and per-chunk timing) and a gen_ai.request.stream span attribute, then wires those capabilities into the OpenAI and Anthropic instrumentations with added unit/integration/conformance coverage.
Changes:
- Add streaming timing capture plumbing in
opentelemetry-util-genai(stream wrappers → invocation → metrics + span attributes). - Wire
invocation=...into OpenAI/Anthropic stream wrappers and add regression tests + conformance scenarios to ensure metrics/attributes are emitted. - Bump
wraptminimum to 1.14.0 to ensure asyncObjectProxysupport.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Updates resolved wrapt minimum constraint. |
| tox.ini | Installs util package editable in typecheck env. |
| util/opentelemetry-util-genai/tests/test_stream.py | Adds seam tests for wrapper → invocation timing callbacks. |
| util/opentelemetry-util-genai/tests/test_handler_metrics.py | Adds tests for TTFC/per-chunk metrics + new span attributes. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/stream.py | Adds optional invocation to stream wrappers and reports per-chunk timing. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/metrics.py | Adds histograms + recorder APIs for streaming timing metrics. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/instruments.py | Defines streaming timing histograms. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_invocation.py | Adds streaming state + _on_stream_chunk() timing aggregation/recording. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py | Adds gen_ai.request.stream + gen_ai.response.time_to_first_chunk; caches metric attrs for streaming. |
| util/opentelemetry-util-genai/README.rst | Documents new streaming timing histograms. |
| util/opentelemetry-util-genai/pyproject.toml | Raises wrapt minimum to 1.14.0. |
| util/opentelemetry-util-genai/.changelog/267.fixed | Towncrier fragment for wrapt minimum bump. |
| util/opentelemetry-util-genai/.changelog/267.added | Towncrier fragment for new streaming metrics/attributes. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py | Adds assertions/tests for streaming timing metrics via Responses API. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_response_wrappers.py | Updates wrapper tests to include _on_stream_chunk seam. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_conformance.py | Registers new streaming conformance scenarios. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_chat_metrics.py | Adds streaming timing metrics tests for chat completions (sync/async). |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py | Adds async Responses streaming timing metrics test. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/requirements.oldest.txt | Ensures local util is installed for oldest factor until util is released. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/conformance/responses_streaming.py | Adds Responses streaming conformance scenario. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/conformance/inference_streaming.py | Adds chat streaming conformance scenario. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/response_wrappers.py | Passes invocation into util stream wrappers. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/chat_wrappers.py | Passes invocation into util stream wrappers and sets response model eagerly. |
| instrumentation/opentelemetry-instrumentation-genai-openai/README.rst | Documents new streaming timing metrics behavior. |
| instrumentation/opentelemetry-instrumentation-genai-openai/pyproject.toml | Bumps util dependency to >=1.1b0.dev. |
| instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/267.added | Towncrier fragment for OpenAI streaming timing metrics. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_metrics.py | Adds Anthropic streaming timing metrics tests. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_conformance.py | Registers new streaming conformance scenario. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_async_wrappers.py | Updates wrapper tests to include _on_stream_chunk seam. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/requirements.oldest.txt | Ensures local util is installed for oldest factor until util is released. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/conformance/inference_streaming.py | Adds Anthropic streaming conformance scenario. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/wrappers.py | Passes invocation into util stream wrappers. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/pyproject.toml | Bumps util dependency to >=1.1b0.dev. |
| instrumentation/opentelemetry-instrumentation-genai-anthropic/.changelog/267.added | Towncrier fragment for Anthropic streaming timing metrics. |
|
Thanks for picking this up @lmolkova! I'm glad to see the streaming timing work from my original PR #13 moving forward. Happy to review this since I worked on the initial implementation. Also happy to co-author this if it helps, since a lot of the design decisions here came out of the iteration on #13. Let me know! |
Replace #13