chore: Using IMeterFactory for metrics - ApplicationRequestInstruments#9656
Merged
ReubenBond merged 6 commits intoFeb 15, 2026
Merged
Conversation
24 tasks
4b1d753 to
72ae37a
Compare
Contributor
There was a problem hiding this comment.
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
OrleansInstrumentsservice to wrapIMeterFactoryand provide a sharedMeterinstance - Converted
ApplicationRequestInstrumentsfrom static to instance-based with constructor injection - Updated
CallbackData,InsideRuntimeClient, andOutsideRuntimeClientto accept and useApplicationRequestInstrumentsinstances
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 |
…- 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>
ad1388a to
94551e8
Compare
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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