Skip to content

improve generator span treatment#665

Open
skrawcz wants to merge 3 commits intomainfrom
stefan/improve-generator-spans
Open

improve generator span treatment#665
skrawcz wants to merge 3 commits intomainfrom
stefan/improve-generator-spans

Conversation

@skrawcz
Copy link
Contributor

@skrawcz skrawcz commented Mar 1, 2026

Changes

Add configurable streaming telemetry to the OpenTelemetry bridge and surface generation-vs-consumer timing in the Burr tracker and UI.

  • OpenTelemetryBridge: new streaming_telemetry parameter with StreamingTelemetryMode enum (SINGLE_SPAN, EVENT, CHUNK_SPANS, SINGLE_AND_CHUNK_SPANS) controlling span/event granularity for streaming actions
  • New lifecycle hooks: PreStreamGenerateHook/PostStreamGenerateHook (sync + async) bracket each generator yield in application.py
  • Tracker: SyncTrackingClient implements the generate hooks to accumulate timing in StreamState; EndStreamModel gains optional generation_time_ms, consumer_time_ms, first_item_time_ms fields
  • UI: renders generation/consumer split and TTFT when available, falls back to legacy throughput for old logs
  • Documentation updates across lifecycle, OTel, streaming actions, and tracking reference docs

How I tested this

  • 40 new tests: 10 application hook tests, 24 OTel mode tests, 6 tracker timing tests (unit, backwards compat, sync/async e2e)
  • Ran example with --tracker flag and verified timing data in the Burr UI
  • Full suite: 183 tests pass, TypeScript compiles clean, Sphinx builds with no new warnings

Notes

  • Default SINGLE_SPAN mode is backwards-compatible — same span structure as before, with added timing attributes
  • The four OTel modes only affect span/event output; the tracker always accumulates the same timing independently

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Add pre_stream_generate/post_stream_generate lifecycle hooks that
bracket each generator __next__/__anext__ call, enabling per-yield
instrumentation for streaming actions. Also improves attributes added
for streaming to distinguish internal computation from consumer time.

OpenTelemetryBridge accepts a new streaming_telemetry parameter
(StreamingTelemetryMode enum) controlling how streaming actions are
instrumented:
- SINGLE_SPAN (default): single action span, backwards compatible
- EVENT: action span + stream_completed summary event with
  generation/consumer timing, iteration count, and TTFT
- CHUNK_SPANS: per-yield child spans, no action span
- BOTH: action span with summary event + per-yield child spans
Surface generation-vs-consumer timing data in the Burr tracker and UI,
independent of the OpenTelemetry streaming telemetry modes.

Tracker changes:
- Extend StreamState with timing fields (generation_time_ns,
  consumer_time_ns, first_item_time_ns, etc.) accumulated via
  PreStreamGenerateHook/PostStreamGenerateHook
- Add generate hooks to SyncTrackingClient in both base.py and
  client.py with defensive getattr for subclass compatibility
- Add optional timing fields to EndStreamModel (generation_time_ms,
  consumer_time_ms, first_item_time_ms) with None defaults for
  backwards compatibility
- Update post_end_stream in both LocalTrackingClient and
  S3TrackingClient to convert and write accumulated timing

UI changes:
- Add timing fields to EndStreamModel.ts TypeScript type
- Update StepList.tsx end_stream rendering to show
  "gen: Xms · consumer: Yms · N items · TTFT: Zms" when timing
  data is available, falling back to legacy throughput display

Documentation:
- Add "Streaming Telemetry Modes" section to additional-visibility.rst
- Add StreamingTelemetryMode to opentelemetry.rst API reference
- Add 4 new generate hook classes to lifecycle.rst
- Add "Telemetry & Observability" section to streaming-actions.rst
- Add "Streaming Timing" section to tracking.rst
- Update monitoring.rst and examples/opentelemetry/README.md
- Update design doc to reflect final implementation

Example:
- Add --tracker flag to streaming_telemetry_modes.py for validating
  timing data in the Burr UI

Tests:
- 6 new tests covering StreamState defaults, timing accumulation,
  defensive noop, EndStreamModel backwards compat, and sync/async
  end-to-end with LocalTrackingClient
@skrawcz skrawcz added enhancement New feature or request ui hooks labels Mar 1, 2026
@github-actions
Copy link

github-actions bot commented Mar 1, 2026

A preview of 448b03c is uploaded and can be seen here:

https://burr.dagworks.io/pull/665

Changes may take a few minutes to propagate. Since this is a preview of production, content with draft: true will not be rendered. The source is here: https://github.com/apache/burr/tree/gh-pages/pull/665/

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

Labels

enhancement New feature or request hooks ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant