-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
InstrumentRule.cs
58 lines (52 loc) · 3.21 KB
/
InstrumentRule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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>
/// Contains a set of parameters used to determine which instruments are enabled for which listeners. Unspecified
/// parameters match anything.
/// </summary>
/// <remarks>
/// <para>The most specific rule that matches a given instrument will be used. The priority of parameters is as follows:</para>
/// <para>- MeterName, either an exact match, or the longest prefix match. See <see cref="Meter.Name">Meter.Name</see>.</para>
/// <para>- InstrumentName, an exact match. <see cref="Instrument.Name">Instrument.Name</see>.</para>
/// <para>- ListenerName, an exact match. <see cref="IMetricsListener.Name">IMetricsListener.Name</see>.</para>
/// <para>- Scopes</para>
/// </remarks>
/// <param name="meterName">The <see cref="Meter.Name">Meter.Name</see> or prefix.</param>
/// <param name="instrumentName">The <see cref="Instrument.Name">Instrument.Name</see>.</param>
/// <param name="listenerName">The <see cref="IMetricsListener.Name">IMetricsListener.Name</see>.</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>
/// Gets the <see cref="Meter.Name">Meter.Name</see>, either an exact match or the longest prefix match. Only full segment matches are considered.
/// All meters are matched if this is <see langword="null" />.
/// </summary>
public string? MeterName { get; } = meterName;
/// <summary>
/// Gets the <see cref="Instrument.Name">Instrument.Name</see>, an exact match.
/// All instruments for the given meter are matched if this is <see langword="null" />.
/// </summary>
public string? InstrumentName { get; } = instrumentName;
/// <summary>
/// Gets the <see cref="IMetricsListener.Name">IMetricsListener.Name</see>, an exact match.
/// All listeners are matched if this is <see langword="null" />.
/// </summary>
public string? ListenerName { get; } = listenerName;
/// <summary>
/// Gets 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>
/// Gets a value that indicates whether the instrument should be enabled for the listener.
/// </summary>
public bool Enable { get; } = enable;
}
}