Skip to content

feat(streaming): add telemetry tags to stream metrics - #8631

Merged
ReubenBond merged 8 commits into
dotnet:mainfrom
oising:tagslist-for-streams-telemetry
Aug 1, 2026
Merged

ReubenBond merged 8 commits into
dotnet:mainfrom
oising:tagslist-for-streams-telemetry

Conversation

@oising

@oising oising commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor

This commit introduces telemetry features to several components of the Orleans streaming system. Specifically, a new class, StreamInstrumentsTagUtils, has been created to provide methods for initializing the relevant telemetry tags. This utility is now utilized in numerous places throughout the codebase, including the PubSubRendezvousGrain and PersistentStreamPullingAgent classes, where it facilitates the monitoring of crucial streaming activities. This aids in diagnostics and performance tracking, contributing to ongoing system improvement efforts.

Microsoft Reviewers: Open in CodeFlow

@oising
oising marked this pull request as ready for review September 13, 2023 14:58
@ReubenBond
ReubenBond force-pushed the tagslist-for-streams-telemetry branch from 08da875 to 1b162ac Compare April 1, 2026 17:56
@ReubenBond
ReubenBond force-pushed the tagslist-for-streams-telemetry branch from 1b162ac to 3596e12 Compare May 14, 2026 20:28
@oising

oising commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

It's alive! @ReubenBond

@ReubenBond
ReubenBond force-pushed the tagslist-for-streams-telemetry branch from b046194 to 5749ab7 Compare May 17, 2026 05:05
oising and others added 6 commits July 31, 2026 18:01
This commit introduces telemetry features to several components of the Orleans streaming system. Specifically, a new class, StreamInstrumentsTagUtils, has been created to provide methods for initializing the relevant telemetry tags. This utility is now utilized in numerous places throughout the codebase, including the PubSubRendezvousGrain and PersistentStreamPullingAgent classes, where it facilitates the monitoring of crucial streaming activities. This aids in diagnostics and performance tracking, contributing to ongoing system improvement efforts.
Use grain type instead of per-stream identifiers, keep consumer metrics balanced across add and remove paths, and add focused coverage in Orleans.Core.Tests.

Co-authored-by: Copilot <[email protected]>
Enable nullable annotations for the stream tag helper, align new tests with file-scoped namespace conventions, and preserve DiagnosticListener emissions while applying tagged stream metrics.

Co-authored-by: Copilot <[email protected]>
Revert formatting-only edits in PubSubRendezvousGrain while preserving the telemetry tag behavior changes.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
@ReubenBond
ReubenBond force-pushed the tagslist-for-streams-telemetry branch from a16145c to 2e03d91 Compare August 1, 2026 01:10
Copilot AI review requested due to automatic review settings August 1, 2026 01:10

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

Adds low-cardinality telemetry tags to Orleans streaming metrics to improve diagnostics and performance tracking across pub/sub and persistent streaming components.

Changes:

  • Introduces StreamInstrumentsTagUtils to centralize creation of bounded, stable tag dimensions for streaming-related metrics.
  • Updates pub/sub (PubSubRendezvousGrain) and persistent streaming (PersistentStreamPullingAgent) to emit metrics with tags only when instruments are enabled.
  • Adds unit tests validating tag stability/low cardinality and bounded dimensions.
Show a summary per file
File Description
test/Orleans.Core.Tests/OrleansRuntime/Streams/StreamInstrumentsTagUtilsTests.cs Adds coverage verifying tag stability and bounded dimensions for stream/grain and queue scenarios.
src/Orleans.Streaming/StreamInstrumentsTagUtils.cs New internal utility for generating low-cardinality TagList sets for stream/grain/queue metrics.
src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs Emits pub/sub counters with tags when enabled (added/removed/total for producers/consumers).
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs Emits persistent stream read/sent message counters with tags when enabled.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment on lines +265 to +270
if (_streamInstruments.PubSubConsumersTotal.Enabled)
{
tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamConsumer);
_streamInstruments.PubSubConsumersTotal.Add(
-(initialProducerCount - State.Producers.Count), tags.Value);
}
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
Copilot AI review requested due to automatic review settings August 1, 2026 01:17

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.

Copilot's findings

Suppressed comments (3)

src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs:828

  • _streamInstruments is nullable, but is dereferenced without a null-guard when recording PersistentStreamSentMessages. Capturing _streamInstruments into a local avoids nullable dereference warnings and keeps the null-check and usage tied together.
                        if (_streamInstruments?.PersistentStreamSentMessages.Enabled is true)
                        {
                            tags ??= StreamInstrumentsTagUtils.InitializeTags(
                                consumerData.StreamId, consumerData.StreamConsumer.GetGrainId());
                            _streamInstruments.PersistentStreamSentMessages.Add(1, tags.Value);
                        }

src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:313

  • consumerState is looked up unconditionally, even when both PubSubConsumersRemoved and PubSubConsumersTotal instruments are disabled. That adds an avoidable linear scan on every call. Consider only performing the lookup when at least one of those instruments is enabled.
            var consumerState = State.Consumers.FirstOrDefault(s => s.Equals(subscriptionId));

src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs:546

  • _streamInstruments is declared nullable, but is dereferenced without a null-guard in this block. While the ?. ... is true condition makes this safe at runtime, nullable flow analysis may still flag it and it’s easy to regress later. Capture _streamInstruments into a local and use that for the check and the Add call.

This issue also appears on line 823 of the same file.

            if (_streamInstruments?.PersistentStreamReadMessages.Enabled is true)
            {
                tags = StreamInstrumentsTagUtils.InitializeTags(myQueueId, streamProviderName);
                _streamInstruments.PersistentStreamReadMessages.Add(multiBatch.Count, tags.Value);
            }
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: cd7955ca-4f1e-42b5-ac19-5d6d2c7c3959
Copilot AI review requested due to automatic review settings August 1, 2026 04:22
@ReubenBond
ReubenBond enabled auto-merge August 1, 2026 04:24

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.

Copilot's findings

Suppressed comments (3)

src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:223

  • PubSubConsumersTotal is incremented unconditionally, even if this call is re-registering an existing subscription (ie, pubSubState was already present). Since this counter is used as a +/- delta to represent the current total, it can drift upward and become inaccurate.
                if (_streamInstruments.PubSubConsumersTotal.Enabled)
                {
                    tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamConsumer);
                    _streamInstruments.PubSubConsumersTotal.Add(1, tags.Value);
                }

src/Orleans.Streaming/StreamInstrumentsTagUtils.cs:18

  • grainId.Type.ToString() will not be null and does not map default/empty grain types to the intended low-cardinality "unknown" value. If a default GrainId is ever passed, this will emit an empty/implicit grain_type dimension instead of unknown.
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    internal static TagList InitializeTags(QualifiedStreamId streamId, GrainId grainId) =>
        CreateStreamTags(streamId, grainId.Type.ToString() ?? UnknownGrainType);

src/Orleans.Streaming/PubSub/PubSubRendezvousGrain.cs:133

  • PubSubProducersTotal is being incremented even when State.Producers.Add(...) is a no-op (eg, producer re-registers due to retries). Since this counter is used as a +/- delta to represent the current total, it can drift upward and become inaccurate.

This issue also appears on line 219 of the same file.

                if (_streamInstruments.PubSubProducersTotal.Enabled)
                {
                    tags ??= StreamInstrumentsTagUtils.InitializeTags(streamId, streamProducer);
                    _streamInstruments.PubSubProducersTotal.Add(1, tags.Value);
                }
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

@ReubenBond ReubenBond changed the title Additional telemetry tags adds for various Orleans streaming components feat(streaming): add telemetry tags to stream metrics Aug 1, 2026
@ReubenBond
ReubenBond disabled auto-merge August 1, 2026 06:04
@ReubenBond
ReubenBond merged commit 7cbd5ba into dotnet:main Aug 1, 2026
67 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants