Skip to content

chore: Using IMeterFactory for metrics - ApplicationRequestInstruments#9656

Merged
ReubenBond merged 6 commits into
dotnet:mainfrom
Meir017:chore/metrics-di-application-request-timeouts
Feb 15, 2026
Merged

chore: Using IMeterFactory for metrics - ApplicationRequestInstruments#9656
ReubenBond merged 6 commits into
dotnet:mainfrom
Meir017:chore/metrics-di-application-request-timeouts

Conversation

@Meir017

@Meir017 Meir017 commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

related to #9608

Converts static ApplicationRequestInstruments to instance-based implementation that receives OrleansInstruments through constructor injection.

Introduces OrleansInstruments as a new service that wraps meter creation functionality and registers it in both client and silo service containers.

Updates CallbackData constructors to accept ApplicationRequestInstruments parameter, enabling proper dependency injection throughout the request lifecycle.

Improves testability and follows dependency injection patterns consistently across the Orleans runtime.

Microsoft Reviewers: Open in CodeFlow

@Meir017 Meir017 mentioned this pull request Aug 25, 2025
24 tasks
@ReubenBond ReubenBond force-pushed the chore/metrics-di-application-request-timeouts branch from 4b1d753 to 72ae37a Compare February 15, 2026 17:01
Copilot AI review requested due to automatic review settings February 15, 2026 17:01

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 refactors the ApplicationRequestInstruments class from a static implementation to an instance-based approach using dependency injection, as part of the broader effort tracked in issue #9608 to migrate Orleans metrics to use IMeterFactory.

Changes:

  • Introduced OrleansInstruments service to wrap IMeterFactory and provide a shared Meter instance
  • Converted ApplicationRequestInstruments from static to instance-based with constructor injection
  • Updated CallbackData, InsideRuntimeClient, and OutsideRuntimeClient to accept and use ApplicationRequestInstruments instances

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Orleans.Core/Diagnostics/Metrics/OrleansInstruments.cs New public service that wraps IMeterFactory to create the Orleans Meter
src/Orleans.Core/Diagnostics/Metrics/ApplicationRequestInstruments.cs Converted from static class to instance-based with dependency injection
src/Orleans.Runtime/Hosting/DefaultSiloServices.cs Registers OrleansInstruments singleton in silo service container
src/Orleans.Core/Core/DefaultClientServices.cs Registers OrleansInstruments singleton in client service container
src/Orleans.Runtime/Core/InsideRuntimeClient.cs Updated to inject OrleansInstruments and create ApplicationRequestInstruments instance
src/Orleans.Core/Runtime/OutsideRuntimeClient.cs Updated to inject OrleansInstruments and create ApplicationRequestInstruments instance
src/Orleans.Core/Runtime/CallbackData.cs Updated to accept and use ApplicationRequestInstruments instance for metrics

Comment thread src/Orleans.Core/Core/DefaultClientServices.cs Outdated
Comment thread src/Orleans.Core/Diagnostics/Metrics/OrleansInstruments.cs Outdated
Comment thread src/Orleans.Core/Diagnostics/Metrics/OrleansInstruments.cs
Comment thread src/Orleans.Core/Diagnostics/Metrics/OrleansInstruments.cs Outdated
Comment thread src/Orleans.Core/Diagnostics/Metrics/ApplicationRequestInstruments.cs Outdated
Comment thread src/Orleans.Runtime/Hosting/DefaultSiloServices.cs Outdated
Meir017 and others added 3 commits February 15, 2026 13:54
…- ApplicationRequestInstruments

Converts static ApplicationRequestInstruments to instance-based implementation that receives OrleansInstruments through constructor injection.

Introduces OrleansInstruments as a new service that wraps meter creation functionality and registers it in both client and silo service containers.

Updates CallbackData constructors to accept ApplicationRequestInstruments parameter, enabling proper dependency injection throughout the request lifecycle.

Improves testability and follows dependency injection patterns consistently across the Orleans runtime.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use the existing static meter when IMeterFactory is not registered so OrleansInstruments can still be activated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ReubenBond ReubenBond force-pushed the chore/metrics-di-application-request-timeouts branch from ad1388a to 94551e8 Compare February 15, 2026 21:54
ReubenBond and others added 3 commits February 15, 2026 14:03
Use AddMetrics in default client/silo service registration so OrleansInstruments can depend on IMeterFactory without fallback behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove duplicate histogram aggregator initialization\n- Add XML docs/null-guard for public OrleansInstruments\n- Add OrleansInstruments to Orleans.Core API baseline\n- Use TryAddSingleton for OrleansInstruments in silo services

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Revert the Orleans.Core.cs baseline entry for OrleansInstruments since API baseline automation applies that change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ReubenBond ReubenBond added this pull request to the merge queue Feb 15, 2026
Merged via the queue into dotnet:main with commit 7ecb7e9 Feb 15, 2026
59 checks passed
@Meir017 Meir017 deleted the chore/metrics-di-application-request-timeouts branch February 16, 2026 08:53
rkargMsft pushed a commit to rkargMsft/orleans that referenced this pull request Feb 27, 2026
dotnet#9656)

* chore: Refactors metrics instrumentation to use dependency injection - ApplicationRequestInstruments

Converts static ApplicationRequestInstruments to instance-based implementation that receives OrleansInstruments through constructor injection.

Introduces OrleansInstruments as a new service that wraps meter creation functionality and registers it in both client and silo service containers.

Updates CallbackData constructors to accept ApplicationRequestInstruments parameter, enabling proper dependency injection throughout the request lifecycle.

Improves testability and follows dependency injection patterns consistently across the Orleans runtime.

* Update src/Orleans.Core/Core/DefaultClientServices.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix OrleansInstruments DI fallback

Use the existing static meter when IMeterFactory is not registered so OrleansInstruments can still be activated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Register IMeterFactory via AddMetrics

Use AddMetrics in default client/silo service registration so OrleansInstruments can depend on IMeterFactory without fallback behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address PR feedback on metrics DI

- Remove duplicate histogram aggregator initialization\n- Add XML docs/null-guard for public OrleansInstruments\n- Add OrleansInstruments to Orleans.Core API baseline\n- Use TryAddSingleton for OrleansInstruments in silo services

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove manual Orleans.Core API edit

Revert the Orleans.Core.cs baseline entry for OrleansInstruments since API baseline automation applies that change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Reuben Bond <reuben.bond@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 18, 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