Skip to main content

Overview

This example pairs two ways of turning the same Polyglot streaming events into metrics, run against one shared EventDispatcher:
  • a hand-rolled StreamMetricsCollector (Cognesy\Metrics\Collectors\MetricsCollector) that listens for streaming-specific events and builds derived metrics no runtime package knows about: time to first chunk, chunk count, tokens/second.
  • the canonical Telemetry path — a Cognesy\Telemetry\Application\Telemetry hub wired to Cognesy\Polyglot\Telemetry\PolyglotTelemetryProjector through RuntimeEventBridge — which turns the very same InferenceStarted / InferenceAttemptSucceeded / InferenceUsageReported / InferenceCompleted events into spans, logs, and the catalog inference.client.* metrics (token usage histograms, attempt/operation counters and timers) automatically, with zero extra collector code.
The output below is grouped so the two halves stay visibly distinct: metrics from the hand-rolled collector, and metrics + spans emitted by the Telemetry projector for free from the same run.

Example