-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
AzureMonitorOptions.cs
86 lines (76 loc) · 3.83 KB
/
AzureMonitorOptions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable disable
using Azure.Core;
using Azure.Monitor.OpenTelemetry.Exporter;
namespace Azure.Monitor.OpenTelemetry.AspNetCore
{
/// <summary>
/// Options that allow users to configure the Azure Monitor.
/// </summary>
public class AzureMonitorOptions : ClientOptions
{
/// <summary>
/// The Connection String provides users with a single configuration setting to identify the Azure Monitor resource and endpoint.
/// </summary>
/// <remarks>
/// <see href="https://docs.microsoft.com/azure/azure-monitor/app/sdk-connection-string"/>.
/// </remarks>
public string ConnectionString { get; set; }
/// <summary>
/// Get or sets the value of <see cref="TokenCredential" />.
/// If <see cref="TokenCredential" /> is not set, AAD authentication is disabled
/// and Instrumentation Key from the Connection String will be used.
/// </summary>
/// <remarks>
/// <see href="https://learn.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string?tabs=net#is-the-connection-string-a-secret"/>.
/// </remarks>
public TokenCredential Credential { get; set; }
/// <summary>
/// Disable offline storage.
/// </summary>
public bool DisableOfflineStorage { get; set; }
/// <summary>
/// Enables or disables the Live Metrics feature. This property is enabled by default.
/// Note: Enabling Live Metrics incurs no additional billing or costs. However, it does introduce
/// a performance overhead due to extra data collection, processing, and networking calls. This overhead
/// is only significant when the LiveMetrics portal is actively used in the UI. Once the portal is closed,
/// LiveMetrics reverts to a 'silent' mode with minimal to no overhead.
/// <see href="https://learn.microsoft.com/azure/azure-monitor/app/live-stream?tabs=dotnet6"/>.
/// </summary>
public bool EnableLiveMetrics { get; set; } = true;
/// <summary>
/// Gets or sets the ratio of telemetry items to be sampled. The value must be between 0.0F and 1.0F, inclusive.
/// For example, specifying 0.4 means that 40% of traces are sampled and 60% are dropped.
/// The default value is 1.0F, indicating that all telemetry items are sampled.
/// </summary>
public float SamplingRatio { get; set; } = 1.0F;
/// <summary>
/// Override the default directory for offline storage.
/// </summary>
public string StorageDirectory { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="AzureMonitorOptions"/>.
/// </summary>
public AzureMonitorOptions()
{
// users can explicitly change it, but by default we don't want internal logs to be reported to Azure Monitor.
this.Diagnostics.IsDistributedTracingEnabled = false;
this.Diagnostics.IsLoggingEnabled = false;
}
internal void SetValueToExporterOptions(AzureMonitorExporterOptions exporterOptions)
{
exporterOptions.ConnectionString = ConnectionString;
exporterOptions.Credential = Credential;
exporterOptions.DisableOfflineStorage = DisableOfflineStorage;
exporterOptions.SamplingRatio = SamplingRatio;
exporterOptions.StorageDirectory = StorageDirectory;
if (Transport != null)
{
exporterOptions.Transport = Transport;
}
exporterOptions.Diagnostics.IsDistributedTracingEnabled = Diagnostics.IsDistributedTracingEnabled;
exporterOptions.Diagnostics.IsLoggingEnabled = Diagnostics.IsLoggingEnabled;
}
}
}