-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add metrics configuration APIs #90201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
919033d
Packaging
Tratcher 775c9dd
Bulk add types
Tratcher a537d9e
Configuration packaging, API ref
Tratcher 7453b2a
Hosting API dump, dependencies
Tratcher 784becb
AddConsole
Tratcher 6103d82
Hosting wireup
Tratcher f599cb9
Rules
Tratcher 97aee1f
Wire up the factory
Tratcher 646fe7c
Revert non-CLS Compliance
Tratcher 7b90ec2
Feedback, scopes
Tratcher 80dfa86
Split DefaultMeterFactory
Tratcher 4d789be
Remove hosting CLS compliance
Tratcher 3bf5e56
Split out listener subscriptions.
Tratcher 74da7e1
Remove filter, add enable, replace TListener with string, internal Co…
Tratcher 0c11591
IMetric_s_SubscriptionManager
Tratcher 2109487
Better matching
Tratcher a7e1884
sealed
Tratcher f0f578b
Rule heirarchy, tests
Tratcher 74bc673
Test cases
Tratcher 743d27f
Listener name constant
Tratcher c2a249d
Add/ClearListener
Tratcher 8275820
More console output
Tratcher 3747367
Revert DefaultMeterFactory changes
Tratcher 84eebd6
Cleanup
Tratcher 5205861
Notes
Tratcher dd8c364
Console updates, SetSoruce
Tratcher fc3553e
Update InstrumentPublished
Tratcher 5e042a7
Move MetricsBuilderEnableExtensions back
Tratcher 2852d14
API refactor
Tratcher 98f3eff
GetMeasurementHandlers();
Tratcher 5d4335c
Intellisense and defaults
Tratcher a7f1b43
Less default
Tratcher 0a0596b
Less default refs
Tratcher ccac470
Docs, cleaup
Tratcher 1d01973
More scopes
Tratcher 6ccde38
Renames
Tratcher 224c834
Merge Configuration assembly
Tratcher 5748df4
Tests, cleanup
Tratcher b9263f4
Scope validation
Tratcher 482888f
Split tests, fix naming
Tratcher 2c7a7e9
Cleanup
Tratcher a461a6b
Implement configuration reading
Tratcher 898ec8f
Add new Abstractions to transport package
Tratcher 8d3dc1d
Remove IVT, cleanup
Tratcher e045058
Only track active instruments
Tratcher cc52509
Check that the instrument matches the current scope
Tratcher e07073c
Priorities, cleanup
Tratcher 9f32fa0
Review feedback
Tratcher 5b15523
Compiler issues
Tratcher c9d6b37
Foo*
Tratcher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...oft.Extensions.Diagnostics.Abstractions/Microsoft.Extensions.Diagnostics.Abstractions.sln
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.7.33711.374 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{79CE8C7E-A4AF-413C-A54D-86F17073559C}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bcl.AsyncInterfaces", "..\Microsoft.Bcl.AsyncInterfaces\ref\Microsoft.Bcl.AsyncInterfaces.csproj", "{9052AC86-4B89-4311-BEF2-7C49FB72DC0F}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bcl.AsyncInterfaces", "..\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj", "{FA353FC1-2D03-426A-8973-0CDA8DF5E5DD}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DependencyInjection.Abstractions", "..\Microsoft.Extensions.DependencyInjection.Abstractions\ref\Microsoft.Extensions.DependencyInjection.Abstractions.csproj", "{D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DependencyInjection.Abstractions", "..\Microsoft.Extensions.DependencyInjection.Abstractions\src\Microsoft.Extensions.DependencyInjection.Abstractions.csproj", "{527CCF66-AC37-487C-871E-A4F6B94E1731}" | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4DE63935-DCA9-4D63-9C1F-AAE79C89CA8B}" | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{7631380A-FB73-4241-9987-0891A21E9769}" | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{548DF5F7-790C-4A1C-89EB-BD904CA1BA86}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Diagnostics.Abstractions", "src\Microsoft.Extensions.Diagnostics.Abstractions.csproj", "{0588387D-FB65-4BA9-A8B2-DA6790027CC2}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Diagnostics.Abstractions", "ref\Microsoft.Extensions.Diagnostics.Abstractions.csproj", "{EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Diagnostics.Abstractions.Tests", "tests\Microsoft.Extensions.Diagnostics.Abstractions.Tests.csproj", "{CB373FE5-F976-4CB2-A04E-6188D67A5816}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {79CE8C7E-A4AF-413C-A54D-86F17073559C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {79CE8C7E-A4AF-413C-A54D-86F17073559C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {79CE8C7E-A4AF-413C-A54D-86F17073559C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {79CE8C7E-A4AF-413C-A54D-86F17073559C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {9052AC86-4B89-4311-BEF2-7C49FB72DC0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {9052AC86-4B89-4311-BEF2-7C49FB72DC0F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {9052AC86-4B89-4311-BEF2-7C49FB72DC0F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {9052AC86-4B89-4311-BEF2-7C49FB72DC0F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {FA353FC1-2D03-426A-8973-0CDA8DF5E5DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {FA353FC1-2D03-426A-8973-0CDA8DF5E5DD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {FA353FC1-2D03-426A-8973-0CDA8DF5E5DD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {FA353FC1-2D03-426A-8973-0CDA8DF5E5DD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {527CCF66-AC37-487C-871E-A4F6B94E1731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {527CCF66-AC37-487C-871E-A4F6B94E1731}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {527CCF66-AC37-487C-871E-A4F6B94E1731}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {527CCF66-AC37-487C-871E-A4F6B94E1731}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {0588387D-FB65-4BA9-A8B2-DA6790027CC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {0588387D-FB65-4BA9-A8B2-DA6790027CC2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {0588387D-FB65-4BA9-A8B2-DA6790027CC2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {0588387D-FB65-4BA9-A8B2-DA6790027CC2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {CB373FE5-F976-4CB2-A04E-6188D67A5816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {CB373FE5-F976-4CB2-A04E-6188D67A5816}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {CB373FE5-F976-4CB2-A04E-6188D67A5816}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {CB373FE5-F976-4CB2-A04E-6188D67A5816}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(NestedProjects) = preSolution | ||
| {79CE8C7E-A4AF-413C-A54D-86F17073559C} = {4DE63935-DCA9-4D63-9C1F-AAE79C89CA8B} | ||
| {9052AC86-4B89-4311-BEF2-7C49FB72DC0F} = {7631380A-FB73-4241-9987-0891A21E9769} | ||
| {FA353FC1-2D03-426A-8973-0CDA8DF5E5DD} = {548DF5F7-790C-4A1C-89EB-BD904CA1BA86} | ||
| {D6778DF4-DA03-43E7-BD9D-2E2C35DCCE7F} = {7631380A-FB73-4241-9987-0891A21E9769} | ||
| {527CCF66-AC37-487C-871E-A4F6B94E1731} = {548DF5F7-790C-4A1C-89EB-BD904CA1BA86} | ||
| {0588387D-FB65-4BA9-A8B2-DA6790027CC2} = {548DF5F7-790C-4A1C-89EB-BD904CA1BA86} | ||
| {EF2C8F2A-6088-4A89-9AE2-9C2FDFB0241C} = {7631380A-FB73-4241-9987-0891A21E9769} | ||
| {CB373FE5-F976-4CB2-A04E-6188D67A5816} = {4DE63935-DCA9-4D63-9C1F-AAE79C89CA8B} | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {450DA749-CBDC-4BDC-950F-8A491CF59D49} | ||
| EndGlobalSection | ||
| EndGlobal |
21 changes: 21 additions & 0 deletions
21
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Microsoft.Extensions.Diagnostics.Abstractions | ||
|
|
||
| `Microsoft.Extensions.Diagnostics.Abstractions` provides abstractions of diagnostics. Interfaces defined in this package are implemented by classes in [Microsoft.Extensions.Diagnostics](https://www.nuget.org/packages/Microsoft.Extensions.Diagnostics/) and other diagnostics packages. | ||
|
|
||
| Commonly Used Types: | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.IMetricsBuilder` | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.IMetricsListener` | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.InstrumentRule` | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.MeterScope` | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.MetricsBuilderExtensions` | ||
| - `Microsoft.Extensions.Diagnostics.Metrics.MetricsOptions` | ||
|
|
||
| Documentation can be found at https://learn.microsoft.com/en-us/dotnet/core/extensions/diagnostics. | ||
|
|
||
| ## Contribution Bar | ||
| - [x] [We consider new features, new APIs, bug fixes, and performance changes](../../libraries/README.md#primary-bar) | ||
|
|
||
| The APIs and functionality are new in .NET 8 and will continue to be developed. | ||
|
|
||
| ## Deployment | ||
| [Microsoft.Extensions.Diagnostics.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Diagnostics.Abstractions) is included in the ASP.NET Core shared framework. The package is deployed as out-of-band (OOB) too and can be referenced into projects directly. |
75 changes: 75 additions & 0 deletions
75
....Extensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // ------------------------------------------------------------------------------ | ||
| // Changes to this file must follow the https://aka.ms/api-review process. | ||
| // ------------------------------------------------------------------------------ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Extensions.Diagnostics.Metrics | ||
| { | ||
| public interface IMetricsBuilder | ||
| { | ||
| Microsoft.Extensions.DependencyInjection.IServiceCollection Services { get; } | ||
| } | ||
| public interface IMetricsListener | ||
| { | ||
| public string Name { get; } | ||
| public void Initialize(IObservableInstrumentsSource source); | ||
| public bool InstrumentPublished(System.Diagnostics.Metrics.Instrument instrument, out object? userState); | ||
| public void MeasurementsCompleted(System.Diagnostics.Metrics.Instrument instrument, object? userState); | ||
| public MeasurementHandlers GetMeasurementHandlers(); | ||
| } | ||
| public class MeasurementHandlers | ||
| { | ||
| public System.Diagnostics.Metrics.MeasurementCallback<byte>? ByteHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<short>? ShortHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<int>? IntHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<long>? LongHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<float>? FloatHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<double>? DoubleHandler { get; set; } | ||
| public System.Diagnostics.Metrics.MeasurementCallback<decimal>? DecimalHandler { get; set; } | ||
| } | ||
| public interface IObservableInstrumentsSource | ||
| { | ||
| public void RecordObservableInstruments(); | ||
| } | ||
| public class InstrumentRule | ||
| { | ||
| public InstrumentRule(string? meterName, string? instrumentName, string? listenerName, MeterScope scopes, bool enable) { } | ||
| public string? MeterName { get; } | ||
| public string? InstrumentName { get; } | ||
| public string? ListenerName { get; } | ||
| public MeterScope Scopes { get; } | ||
| public bool Enable { get; } | ||
| } | ||
| [Flags] | ||
| public enum MeterScope | ||
| { | ||
| None = 0, | ||
| Global, | ||
| Local | ||
| } | ||
| public static class MetricsBuilderExtensions | ||
| { | ||
| public static IMetricsBuilder AddListener<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] T> | ||
| (this IMetricsBuilder builder) where T : class, IMetricsListener { throw null!; } | ||
| public static IMetricsBuilder AddListener(this IMetricsBuilder builder, IMetricsListener listener) { throw null!; } | ||
| public static IMetricsBuilder ClearListeners(this IMetricsBuilder builder) { throw null!; } | ||
|
|
||
| public static IMetricsBuilder EnableMetrics(this IMetricsBuilder builder, string? meterName) => throw null!; | ||
| public static IMetricsBuilder EnableMetrics(this IMetricsBuilder builder, string? meterName, string? instrumentName = null, string? listenerName = null, MeterScope scopes = MeterScope.Global | MeterScope.Local) => throw null!; | ||
| public static MetricsOptions EnableMetrics(this MetricsOptions options, string? meterName) => throw null!; | ||
| public static MetricsOptions EnableMetrics(this MetricsOptions options, string? meterName, string? instrumentName = null, string? listenerName = null, MeterScope scopes = MeterScope.Global | MeterScope.Local) => throw null!; | ||
|
|
||
| public static IMetricsBuilder DisableMetrics(this IMetricsBuilder builder, string? meterName) => throw null!; | ||
| public static IMetricsBuilder DisableMetrics(this IMetricsBuilder builder, string? meterName, string? instrumentName = null, string? listenerName = null, MeterScope scopes = MeterScope.Global | MeterScope.Local) => throw null!; | ||
| public static MetricsOptions DisableMetrics(this MetricsOptions options, string? meterName) => throw null!; | ||
| public static MetricsOptions DisableMetrics(this MetricsOptions options, string? meterName, string? instrumentName = null, string? listenerName = null, MeterScope scopes = MeterScope.Global | MeterScope.Local) => throw null!; | ||
| } | ||
| public class MetricsOptions | ||
| { | ||
| public IList<InstrumentRule> Rules { get; } = null!; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...ensions.Diagnostics.Abstractions/ref/Microsoft.Extensions.Diagnostics.Abstractions.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Microsoft.Extensions.Diagnostics.Abstractions.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"> | ||
| <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" /> | ||
| <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(LibrariesProjectRoot)System.Diagnostics.DiagnosticSource\ref\System.Diagnostics.DiagnosticSource.csproj" /> | ||
| <ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.DependencyInjection.Abstractions\ref\Microsoft.Extensions.DependencyInjection.Abstractions.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
19 changes: 19 additions & 0 deletions
19
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Metrics/IMetricsBuilder.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Microsoft.Extensions.Diagnostics.Metrics | ||
| { | ||
| /// <summary> | ||
| /// Represents a type used to configure the metrics system by registering IMetricsListeners and using rules | ||
| /// to determine which metrics are enabled. | ||
| /// </summary> | ||
| public interface IMetricsBuilder | ||
| { | ||
| /// <summary> | ||
| /// The application <see cref="IServiceCollection"/>. This is used by extension methods to register services. | ||
| /// </summary> | ||
| IServiceCollection Services { get; } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Metrics/IMetricsListener.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.Metrics; | ||
|
|
||
| namespace Microsoft.Extensions.Diagnostics.Metrics | ||
| { | ||
| /// <summary> | ||
| /// Represents a type used to listen to metrics emitted from the system. | ||
| /// </summary> | ||
| public interface IMetricsListener | ||
| { | ||
| /// <summary> | ||
| /// The name of the listener. This is used to identify the listener in the rules configuration. | ||
| /// </summary> | ||
| public string Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// Called once by the runtime to provide a <see cref="IObservableInstrumentsSource"/> used to pull for fresh metrics data. | ||
| /// </summary> | ||
| /// <param name="source">A <see cref="IObservableInstrumentsSource"/> that can be called to request current metrics.</param> | ||
| public void Initialize(IObservableInstrumentsSource source); | ||
|
|
||
| /// <summary> | ||
| /// Called when a new instrument is created and enabled by a matching rule. | ||
| /// </summary> | ||
| /// <param name="instrument">The new <see cref="Instrument"/>.</param> | ||
| /// <param name="userState">Listener state associated with this instrument. This will be returned to <see cref="MeasurementCallback{T}"/> | ||
| /// and <see cref="MeasurementsCompleted(Instrument, object?)"/>.</param> | ||
| /// <returns>Returns true if the listener wants to subscribe to this instrument, otherwise false.</returns> | ||
| public bool InstrumentPublished(Instrument instrument, out object? userState); | ||
|
|
||
| /// <summary> | ||
| /// Called when a instrument is disabled by the producer or a rules change. | ||
| /// </summary> | ||
| /// <param name="instrument">The <see cref="Instrument"/> being disabled.</param> | ||
| /// <param name="userState">The original listener state returned by <see cref="InstrumentPublished(Instrument, out object?)"/>.</param> | ||
| public void MeasurementsCompleted(Instrument instrument, object? userState); | ||
|
|
||
| /// <summary> | ||
| /// Called once to get the <see cref="MeasurementHandlers"/> that will be used to process measurements. | ||
| /// </summary> | ||
| /// <returns>The <see cref="MeasurementHandlers"/>.</returns> | ||
| public MeasurementHandlers GetMeasurementHandlers(); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...Microsoft.Extensions.Diagnostics.Abstractions/src/Metrics/IObservableInstrumentsSource.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.Metrics; | ||
|
|
||
| namespace Microsoft.Extensions.Diagnostics.Metrics | ||
| { | ||
| /// <summary> | ||
| /// An interface registered with each IMetricsListener using <see cref="IMetricsListener.Initialize(IObservableInstrumentsSource)"/>. The listener | ||
| /// can call <see cref="RecordObservableInstruments"/> to receive the current set of measurements for enabled observable instruments. | ||
| /// </summary> | ||
| public interface IObservableInstrumentsSource | ||
| { | ||
| /// <summary> | ||
| /// Requests that the current set of metrics for enabled instruments be sent to the listener's <see cref="MeasurementCallback{T}"/>'s. | ||
| /// </summary> | ||
| public void RecordObservableInstruments(); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/libraries/Microsoft.Extensions.Diagnostics.Abstractions/src/Metrics/InstrumentRule.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Diagnostics.Metrics; | ||
|
|
||
| namespace Microsoft.Extensions.Diagnostics.Metrics | ||
| { | ||
| /// <summary> | ||
| /// A set of parameters used to determine which instruments are enabled for which listeners. Unspecified | ||
| /// parameters match anything. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The most specific rule that matches a given instrument will be used. The priority of parameters is as follows: | ||
| /// - MeterName, either an exact match, or the longest prefix match. See <see cref="Meter.Name"/>. | ||
| /// - InstrumentName, an exact match. <see cref="Instrument.Name"/>. | ||
| /// - ListenerName, an exact match. <see cref="IMetricsListener.Name"/>. | ||
| /// - Scopes | ||
| /// </remarks> | ||
| /// <param name="meterName">The <see cref="Meter.Name"/> or prefix.</param> | ||
| /// <param name="instrumentName">The <see cref="Instrument.Name"/>.</param> | ||
| /// <param name="listenerName">The <see cref="IMetricsListener.Name"/>.</param> | ||
| /// <param name="scopes">The <see cref="MeterScope"/>'s to consider.</param> | ||
| /// <param name="enable">Enables or disabled the matched instrument for this listener.</param> | ||
| public class InstrumentRule(string? meterName, string? instrumentName, string? listenerName, MeterScope scopes, bool enable) | ||
| { | ||
| /// <summary> | ||
| /// The <see cref="Meter.Name"/>, either an exact match or the longest prefix match. Only full segment matches are considered. | ||
| /// All meters are matched if this is null. | ||
| /// </summary> | ||
| public string? MeterName { get; } = meterName; | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="Instrument.Name"/>, an exact match. | ||
| /// All instruments for the given meter are matched if this is null. | ||
| /// </summary> | ||
| public string? InstrumentName { get; } = instrumentName; | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="IMetricsListener.Name"/>, an exact match. | ||
| /// All listeners are matched if this is null. | ||
| /// </summary> | ||
| public string? ListenerName { get; } = listenerName; | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="MeterScope"/>. This is used to distinguish between meters created via <see cref="Meter"/> constructors (<see cref="MeterScope.Global"/>) | ||
| /// and those created via Dependency Injection with <see cref="IMeterFactory.Create(MeterOptions)"/> (<see cref="MeterScope.Local"/>)."/>. | ||
| /// </summary> | ||
| public MeterScope Scopes { get; } = scopes == MeterScope.None | ||
| ? throw new ArgumentOutOfRangeException(nameof(scopes), scopes, "The MeterScope must be Global, Local, or both.") | ||
| : scopes; | ||
|
|
||
| /// <summary> | ||
| /// Indicates if the instrument should be enabled for the listener. | ||
| /// </summary> | ||
| public bool Enable { get; } = enable; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate this if someone added more unsupported values? or we don't care?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mostly worried about the common case where someone passes in None by mistake. If they want to deliberately pass in other values I'm not going to question them too closely 😁.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion here but would prefer to communicate the failure sooner instead of having the user see unexpected behavior later and it will be hard to investigate.