Skip to content

feat(openai): emit streaming latency span attrs - #34

Merged
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
feat/openai-streaming-latency-span-attrs
Jun 18, 2026
Merged

feat(openai): emit streaming latency span attrs#34
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
feat/openai-streaming-latency-span-attrs

Conversation

@sayonfortify

Copy link
Copy Markdown

Adds FortifyRoot span attributes for OpenAI streaming latency so TTFT/STTG can be extracted into RDS while leaving existing Mimir histograms unchanged.

Attributes:

  • fortifyroot.llm.streaming.time_to_first_token_ms
  • fortifyroot.llm.streaming.time_to_generate_ms

Implementation:

  • Sets TTFT/STTG as integer milliseconds in ChatStream, _build_from_streaming_response, and _abuild_from_streaming_response.
  • First-token detection is independent of histogram availability, so tracing/RDS span attrs still work when metrics histograms are disabled.
  • Empty streams set neither attr, preserving nullable RDS semantics.
  • Existing histogram names, units, and .record() calls are preserved.

Tests:

  • New deterministic unit test drives the v0 streaming generator with fake chunks/stub histograms.
  • Covers: streaming sets attrs + histograms still fire; metrics-disabled path still sets attrs; empty stream sets no attrs.

Validation run locally:

  • python3 -m py_compile packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/chat_wrappers.py packages/opentelemetry-instrumentation-openai/tests/test_streaming_latency_span_attrs.py
  • PYTHONPATH=packages/opentelemetry-instrumentation-openai:packages/opentelemetry-semantic-conventions-ai:packages/opentelemetry-instrumentation-fortifyroot /Users/sayondutta/opt/anaconda3/envs/py3.12/bin/python -m pytest packages/opentelemetry-instrumentation-openai/tests/test_streaming_latency_span_attrs.py -q → 3 passed.

No tag/PyPI release in this PR.

@sayonfortify
sayonfortify merged commit 8193cdb into fr-v0.52.6.x Jun 18, 2026
10 checks passed
@sayonfortify
sayonfortify deleted the feat/openai-streaming-latency-span-attrs branch June 18, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant