Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
919033d
Packaging
Tratcher Jul 17, 2023
775c9dd
Bulk add types
Tratcher Jul 17, 2023
a537d9e
Configuration packaging, API ref
Tratcher Jul 18, 2023
7453b2a
Hosting API dump, dependencies
Tratcher Jul 18, 2023
784becb
AddConsole
Tratcher Jul 19, 2023
6103d82
Hosting wireup
Tratcher Jul 19, 2023
f599cb9
Rules
Tratcher Jul 19, 2023
97aee1f
Wire up the factory
Tratcher Jul 24, 2023
646fe7c
Revert non-CLS Compliance
Tratcher Jul 25, 2023
7b90ec2
Feedback, scopes
Tratcher Jul 25, 2023
80dfa86
Split DefaultMeterFactory
Tratcher Jul 26, 2023
4d789be
Remove hosting CLS compliance
Tratcher Jul 26, 2023
3bf5e56
Split out listener subscriptions.
Tratcher Jul 26, 2023
74da7e1
Remove filter, add enable, replace TListener with string, internal Co…
Tratcher Jul 26, 2023
0c11591
IMetric_s_SubscriptionManager
Tratcher Jul 26, 2023
2109487
Better matching
Tratcher Jul 26, 2023
a7e1884
sealed
Tratcher Jul 27, 2023
f0f578b
Rule heirarchy, tests
Tratcher Jul 27, 2023
74bc673
Test cases
Tratcher Jul 27, 2023
743d27f
Listener name constant
Tratcher Jul 27, 2023
c2a249d
Add/ClearListener
Tratcher Jul 27, 2023
8275820
More console output
Tratcher Jul 27, 2023
3747367
Revert DefaultMeterFactory changes
Tratcher Jul 27, 2023
84eebd6
Cleanup
Tratcher Jul 27, 2023
5205861
Notes
Tratcher Jul 27, 2023
dd8c364
Console updates, SetSoruce
Tratcher Jul 28, 2023
fc3553e
Update InstrumentPublished
Tratcher Jul 31, 2023
5e042a7
Move MetricsBuilderEnableExtensions back
Tratcher Jul 31, 2023
2852d14
API refactor
Tratcher Aug 1, 2023
98f3eff
GetMeasurementHandlers();
Tratcher Aug 1, 2023
5d4335c
Intellisense and defaults
Tratcher Aug 1, 2023
a7f1b43
Less default
Tratcher Aug 1, 2023
0a0596b
Less default refs
Tratcher Aug 7, 2023
ccac470
Docs, cleaup
Tratcher Aug 8, 2023
1d01973
More scopes
Tratcher Aug 8, 2023
6ccde38
Renames
Tratcher Aug 8, 2023
224c834
Merge Configuration assembly
Tratcher Aug 8, 2023
5748df4
Tests, cleanup
Tratcher Aug 8, 2023
b9263f4
Scope validation
Tratcher Aug 8, 2023
482888f
Split tests, fix naming
Tratcher Aug 8, 2023
2c7a7e9
Cleanup
Tratcher Aug 8, 2023
a461a6b
Implement configuration reading
Tratcher Aug 9, 2023
898ec8f
Add new Abstractions to transport package
Tratcher Aug 9, 2023
8d3dc1d
Remove IVT, cleanup
Tratcher Aug 10, 2023
e045058
Only track active instruments
Tratcher Aug 10, 2023
cc52509
Check that the instrument matches the current scope
Tratcher Aug 10, 2023
e07073c
Priorities, cleanup
Tratcher Aug 10, 2023
9f32fa0
Review feedback
Tratcher Aug 10, 2023
5b15523
Compiler issues
Tratcher Aug 10, 2023
c9d6b37
Foo*
Tratcher Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
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!;
}
}
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>
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; }
}
}
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();
}
}
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();
}
}
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scopes;

should we validate this if someone added more unsupported values? or we don't care?

Copy link
Member Author

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 😁.

Copy link
Member

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.


/// <summary>
/// Indicates if the instrument should be enabled for the listener.
/// </summary>
public bool Enable { get; } = enable;
}
}
Loading