forked from open-telemetry/opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperimentalOptions.cs
More file actions
79 lines (66 loc) · 2.88 KB
/
ExperimentalOptions.cs
File metadata and controls
79 lines (66 loc) · 2.88 KB
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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using Microsoft.Extensions.Configuration;
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
internal sealed class ExperimentalOptions
{
public const string LogRecordEventIdAttribute = "logrecord.event.id";
public const string EmitLogEventEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES";
public const string OtlpRetryEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY";
public const string OtlpDiskRetryDirectoryPathEnvVar = "OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH";
public ExperimentalOptions()
: this(new ConfigurationBuilder().AddEnvironmentVariables().Build())
{
}
public ExperimentalOptions(IConfiguration configuration)
{
if (configuration.TryGetBoolValue(OpenTelemetryProtocolExporterEventSource.Log, EmitLogEventEnvVar, out var emitLogEventAttributes))
{
this.EmitLogEventAttributes = emitLogEventAttributes;
}
if (configuration.TryGetStringValue(OtlpRetryEnvVar, out var retryPolicy))
{
if (retryPolicy.Equals("in_memory", StringComparison.OrdinalIgnoreCase))
{
this.EnableInMemoryRetry = true;
}
else if (retryPolicy.Equals("disk", StringComparison.OrdinalIgnoreCase))
{
this.EnableDiskRetry = true;
if (configuration.TryGetStringValue(OtlpDiskRetryDirectoryPathEnvVar, out var path))
{
this.DiskRetryDirectoryPath = path;
}
else
{
throw new NotSupportedException(
$"Retry Policy '{retryPolicy}' requires '{OtlpDiskRetryDirectoryPathEnvVar}' to be configured.");
}
}
else
{
throw new NotSupportedException($"Retry Policy '{retryPolicy}' is not supported.");
}
}
}
/// <summary>
/// Gets a value indicating whether log event attributes should be exported.
/// </summary>
public bool EmitLogEventAttributes { get; }
/// <summary>
/// Gets a value indicating whether or not in-memory retry should be enabled for transient errors.
/// </summary>
/// <remarks>
/// Specification: <see
/// href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#retry"/>.
/// </remarks>
public bool EnableInMemoryRetry { get; }
/// <summary>
/// Gets a value indicating whether or not retry via disk should be enabled for transient errors.
/// </summary>
public bool EnableDiskRetry { get; }
/// <summary>
/// Gets the path on disk where the telemetry will be stored for retries at a later point.
/// </summary>
public string? DiskRetryDirectoryPath { get; }
}