Skip to content

Add streaming metrics and attribute#269

Open
lmolkova wants to merge 6 commits into
open-telemetry:mainfrom
lmolkova:streaming-metrics
Open

Add streaming metrics and attribute#269
lmolkova wants to merge 6 commits into
open-telemetry:mainfrom
lmolkova:streaming-metrics

Conversation

@lmolkova

Copy link
Copy Markdown
Member

Replace #13

  • Report time-to-first-chunk and time-between chunks in genai utils for inference
  • Onboard anthropic and openai
  • Add gen_ai.request.stream attribute

# 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: let's automate it in post-release workflow

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 15, 2026

Copy link
Copy Markdown

Pull request dashboard status

Status: Waiting on reviewers to review the latest changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 wrapt minimum to 1.14.0 to ensure async ObjectProxy support.

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.

Comment thread util/opentelemetry-util-genai/tests/test_handler_metrics.py
Comment thread util/opentelemetry-util-genai/tests/test_handler_metrics.py
Comment thread util/opentelemetry-util-genai/tests/test_handler_metrics.py Outdated
@Nik-Reddy

Nik-Reddy commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants