Skip to content

Commit b31a735

Browse files
authored
Merge branch 'main' into reyang/discourage-activity-events-in-loop
2 parents 31a7a86 + 21aeaa7 commit b31a735

21 files changed

+109
-66
lines changed

OpenTelemetry.sln

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dedicated-pipeline", "docs\
343343
EndProject
344344
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration", "Configuration", "{87A20A76-D524-4AAC-AF92-8725BFED0415}"
345345
ProjectSection(SolutionItems) = preProject
346+
src\Shared\Configuration\IConfigurationExtensionsLogger.cs = src\Shared\Configuration\IConfigurationExtensionsLogger.cs
346347
src\Shared\Configuration\OpenTelemetryConfigurationExtensions.cs = src\Shared\Configuration\OpenTelemetryConfigurationExtensions.cs
347348
EndProjectSection
348349
EndProject

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public ExperimentalOptions()
2424

2525
public ExperimentalOptions(IConfiguration configuration)
2626
{
27-
if (configuration.TryGetBoolValue(EmitLogEventEnvVar, out var emitLogEventAttributes))
27+
if (configuration.TryGetBoolValue(OpenTelemetryProtocolExporterEventSource.Log, EmitLogEventEnvVar, out var emitLogEventAttributes))
2828
{
2929
this.EmitLogEventAttributes = emitLogEventAttributes;
3030
}
3131

32-
if (configuration.TryGetBoolValue(EnableInMemoryRetryEnvVar, out var enableInMemoryRetry))
32+
if (configuration.TryGetBoolValue(OpenTelemetryProtocolExporterEventSource.Log, EnableInMemoryRetryEnvVar, out var enableInMemoryRetry))
3333
{
3434
this.EnableInMemoryRetry = enableInMemoryRetry;
3535
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OpenTelemetryProtocolExporterEventSource.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics.Tracing;
5+
using Microsoft.Extensions.Configuration;
56
using OpenTelemetry.Internal;
67

78
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
89

910
[EventSource(Name = "OpenTelemetry-Exporter-OpenTelemetryProtocol")]
10-
internal sealed class OpenTelemetryProtocolExporterEventSource : EventSource
11+
internal sealed class OpenTelemetryProtocolExporterEventSource : EventSource, IConfigurationExtensionsLogger
1112
{
1213
public static readonly OpenTelemetryProtocolExporterEventSource Log = new();
1314

@@ -81,8 +82,8 @@ public void UnsupportedAttributeType(string type, string key)
8182
this.WriteEvent(10, type.ToString(), key);
8283
}
8384

84-
[Event(11, Message = "{0} environment variable has an invalid value: '{1}'", Level = EventLevel.Warning)]
85-
public void InvalidEnvironmentVariable(string key, string value)
85+
[Event(11, Message = "Configuration key '{0}' has an invalid value: '{1}'", Level = EventLevel.Warning)]
86+
public void InvalidConfigurationValue(string key, string value)
8687
{
8788
this.WriteEvent(11, key, value);
8889
}
@@ -92,4 +93,9 @@ public void TrySubmitRequestException(string ex)
9293
{
9394
this.WriteEvent(12, ex);
9495
}
96+
97+
void IConfigurationExtensionsLogger.LogInvalidConfigurationValue(string key, string value)
98+
{
99+
this.InvalidConfigurationValue(key, value);
100+
}
95101
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/SdkLimitOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public int? LogRecordAttributeCountLimit
163163

164164
private static void SetIntConfigValue(IConfiguration configuration, string key, Action<int?> setter, int? defaultValue)
165165
{
166-
if (configuration.TryGetIntValue(key, out var result))
166+
if (configuration.TryGetIntValue(OpenTelemetryProtocolExporterEventSource.Log, key, out var result))
167167
{
168168
setter(result);
169169
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.DependencyInjection;
1313
using Microsoft.Extensions.Options;
14+
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
1415
using OpenTelemetry.Internal;
1516
using OpenTelemetry.Trace;
1617

@@ -179,13 +180,14 @@ internal void ApplyConfigurationUsingSpecificationEnvVars(
179180
string headersEnvVarKey,
180181
string timeoutEnvVarKey)
181182
{
182-
if (configuration.TryGetUriValue(endpointEnvVarKey, out var endpoint))
183+
if (configuration.TryGetUriValue(OpenTelemetryProtocolExporterEventSource.Log, endpointEnvVarKey, out var endpoint))
183184
{
184185
this.endpoint = endpoint;
185186
this.AppendSignalPathToEndpoint = appendSignalPathToEndpoint;
186187
}
187188

188189
if (configuration.TryGetValue<OtlpExportProtocol>(
190+
OpenTelemetryProtocolExporterEventSource.Log,
189191
protocolEnvVarKey,
190192
OtlpExportProtocolParser.TryParse,
191193
out var protocol))
@@ -198,7 +200,7 @@ internal void ApplyConfigurationUsingSpecificationEnvVars(
198200
this.Headers = headers;
199201
}
200202

201-
if (configuration.TryGetIntValue(timeoutEnvVarKey, out var timeout))
203+
if (configuration.TryGetIntValue(OpenTelemetryProtocolExporterEventSource.Log, timeoutEnvVarKey, out var timeout))
202204
{
203205
this.TimeoutMilliseconds = timeout;
204206
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#nullable enable
55

66
using System.Diagnostics;
7-
using Microsoft.Extensions.Configuration;
87
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
98
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
109
using OpenTelemetry.Logs;
@@ -36,7 +35,7 @@ public OtlpLogExporter(OtlpExporterOptions options)
3635
/// <summary>
3736
/// Initializes a new instance of the <see cref="OtlpLogExporter"/> class.
3837
/// </summary>
39-
/// <param name="exporterOptions">Configuration options for the exporter.</param>
38+
/// <param name="exporterOptions"><see cref="OtlpExporterOptions"/>.</param>
4039
/// <param name="sdkLimitOptions"><see cref="SdkLimitOptions"/>.</param>
4140
/// <param name="experimentalOptions"><see cref="ExperimentalOptions"/>.</param>
4241
/// <param name="transmissionHandler"><see cref="OtlpExporterTransmissionHandler{T}"/>.</param>
@@ -50,12 +49,6 @@ internal OtlpLogExporter(
5049
Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null");
5150
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
5251

53-
// Each of the Otlp exporters: Traces, Metrics, and Logs set the same
54-
// value for
55-
// `OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable`
56-
// so it should be fine even if these exporters are used together.
57-
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
58-
5952
this.transmissionHandler = transmissionHandler ?? exporterOptions.GetLogsExportTransmissionHandler(experimentalOptions!);
6053

6154
this.otlpLogRecordTransformer = new OtlpLogRecordTransformer(sdkLimitOptions!, experimentalOptions!);

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporter.cs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
using Microsoft.Extensions.Configuration;
4+
using System.Diagnostics;
55
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
66
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
77
using OpenTelemetry.Metrics;
@@ -32,21 +32,18 @@ public OtlpMetricExporter(OtlpExporterOptions options)
3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="OtlpMetricExporter"/> class.
3434
/// </summary>
35-
/// <param name="options">Configuration options for the export.</param>
35+
/// <param name="exporterOptions"><see cref="OtlpExporterOptions"/>.</param>
3636
/// <param name="experimentalOptions"><see cref="ExperimentalOptions"/>.</param>
3737
/// <param name="transmissionHandler"><see cref="OtlpExporterTransmissionHandler{T}"/>.</param>
3838
internal OtlpMetricExporter(
39-
OtlpExporterOptions options,
39+
OtlpExporterOptions exporterOptions,
4040
ExperimentalOptions experimentalOptions,
4141
OtlpExporterTransmissionHandler<OtlpCollector.ExportMetricsServiceRequest> transmissionHandler = null)
4242
{
43-
// Each of the Otlp exporters: Traces, Metrics, and Logs set the same
44-
// value for
45-
// `OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable`
46-
// so it should be fine even if these exporters are used together.
47-
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
43+
Debug.Assert(exporterOptions != null, "exporterOptions was null");
44+
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
4845

49-
this.transmissionHandler = transmissionHandler ?? options.GetMetricsExportTransmissionHandler(experimentalOptions);
46+
this.transmissionHandler = transmissionHandler ?? exporterOptions.GetMetricsExportTransmissionHandler(experimentalOptions);
5047
}
5148

5249
internal OtlpResource.Resource ProcessResource => this.processResource ??= this.ParentProvider.GetResource().ToOtlpResource();

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporter.cs

-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5-
using Microsoft.Extensions.Configuration;
65
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
76
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
87
using OtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1;
@@ -48,12 +47,6 @@ internal OtlpTraceExporter(
4847

4948
this.sdkLimitOptions = sdkLimitOptions;
5049

51-
// Each of the Otlp exporters: Traces, Metrics, and Logs set the same
52-
// value for
53-
// `OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable`
54-
// so it should be fine even if these exporters are used together.
55-
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = OpenTelemetryProtocolExporterEventSource.Log.InvalidEnvironmentVariable;
56-
5750
this.transmissionHandler = transmissionHandler ?? exporterOptions.GetTraceExportTransmissionHandler(experimentalOptions);
5851
}
5952

src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinExporterEventSource.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics.Tracing;
5+
using Microsoft.Extensions.Configuration;
56
using OpenTelemetry.Internal;
67

78
namespace OpenTelemetry.Exporter.Zipkin.Implementation;
@@ -10,7 +11,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Implementation;
1011
/// EventSource events emitted from the project.
1112
/// </summary>
1213
[EventSource(Name = "OpenTelemetry-Exporter-Zipkin")]
13-
internal sealed class ZipkinExporterEventSource : EventSource
14+
internal sealed class ZipkinExporterEventSource : EventSource, IConfigurationExtensionsLogger
1415
{
1516
public static ZipkinExporterEventSource Log = new();
1617

@@ -35,9 +36,14 @@ public void UnsupportedAttributeType(string type, string key)
3536
this.WriteEvent(2, type.ToString(), key);
3637
}
3738

38-
[Event(3, Message = "{0} environment variable has an invalid value: '{1}'", Level = EventLevel.Warning)]
39-
public void InvalidEnvironmentVariable(string key, string value)
39+
[Event(3, Message = "Configuration key '{0}' has an invalid value: '{1}'", Level = EventLevel.Warning)]
40+
public void InvalidConfigurationValue(string key, string value)
4041
{
4142
this.WriteEvent(3, key, value);
4243
}
44+
45+
void IConfigurationExtensionsLogger.LogInvalidConfigurationValue(string key, string value)
46+
{
47+
this.InvalidConfigurationValue(key, value);
48+
}
4349
}

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Net.Sockets;
1111
using System.Runtime.CompilerServices;
1212
using System.Text.Json;
13-
using Microsoft.Extensions.Configuration;
1413
using OpenTelemetry.Exporter.Zipkin.Implementation;
1514
using OpenTelemetry.Internal;
1615
using OpenTelemetry.Resources;
@@ -38,8 +37,6 @@ public ZipkinExporter(ZipkinExporterOptions options, HttpClient client = null)
3837
this.options = options;
3938
this.maxPayloadSizeInBytes = (!options.MaxPayloadSizeInBytes.HasValue || options.MaxPayloadSizeInBytes <= 0) ? ZipkinExporterOptions.DefaultMaxPayloadSizeInBytes : options.MaxPayloadSizeInBytes.Value;
4039
this.httpClient = client ?? options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("ZipkinExporter was missing HttpClientFactory or it returned null.");
41-
42-
OpenTelemetryConfigurationExtensions.LogInvalidEnvironmentVariable = ZipkinExporterEventSource.Log.InvalidEnvironmentVariable;
4340
}
4441

4542
internal ZipkinEndpoint LocalEndpoint { get; private set; }

src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net.Http;
77
#endif
88
using Microsoft.Extensions.Configuration;
9+
using OpenTelemetry.Exporter.Zipkin.Implementation;
910
using OpenTelemetry.Trace;
1011

1112
namespace OpenTelemetry.Exporter;
@@ -39,7 +40,7 @@ internal ZipkinExporterOptions(
3940
Debug.Assert(configuration != null, "configuration was null");
4041
Debug.Assert(defaultBatchOptions != null, "defaultBatchOptions was null");
4142

42-
if (configuration.TryGetUriValue(ZipkinEndpointEnvVar, out var endpoint))
43+
if (configuration.TryGetUriValue(ZipkinExporterEventSource.Log, ZipkinEndpointEnvVar, out var endpoint))
4344
{
4445
this.Endpoint = endpoint;
4546
}

src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreTraceInstrumentationOptions.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using Microsoft.AspNetCore.Http;
66
using Microsoft.Extensions.Configuration;
7+
using OpenTelemetry.Instrumentation.AspNetCore.Implementation;
78

89
namespace OpenTelemetry.Instrumentation.AspNetCore;
910

@@ -24,7 +25,10 @@ internal AspNetCoreTraceInstrumentationOptions(IConfiguration configuration)
2425
{
2526
Debug.Assert(configuration != null, "configuration was null");
2627

27-
if (configuration.TryGetBoolValue("OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_ENABLE_GRPC_INSTRUMENTATION", out var enableGrpcInstrumentation))
28+
if (configuration.TryGetBoolValue(
29+
AspNetCoreInstrumentationEventSource.Log,
30+
"OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_ENABLE_GRPC_INSTRUMENTATION",
31+
out var enableGrpcInstrumentation))
2832
{
2933
this.EnableGrpcAspNetCoreSupport = enableGrpcInstrumentation;
3034
}

src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.CodeAnalysis;
66
#endif
77
using System.Diagnostics.Tracing;
8+
using Microsoft.Extensions.Configuration;
89
using OpenTelemetry.Internal;
910

1011
namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation;
@@ -13,7 +14,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation;
1314
/// EventSource events emitted from the project.
1415
/// </summary>
1516
[EventSource(Name = "OpenTelemetry-Instrumentation-AspNetCore")]
16-
internal sealed class AspNetCoreInstrumentationEventSource : EventSource
17+
internal sealed class AspNetCoreInstrumentationEventSource : EventSource, IConfigurationExtensionsLogger
1718
{
1819
public static AspNetCoreInstrumentationEventSource Log = new();
1920

@@ -79,4 +80,15 @@ public void UnknownErrorProcessingEvent(string handlerName, string eventName, st
7980
{
8081
this.WriteEvent(5, handlerName, eventName, ex);
8182
}
83+
84+
[Event(6, Message = "Configuration key '{0}' has an invalid value: '{1}'", Level = EventLevel.Warning)]
85+
public void InvalidConfigurationValue(string key, string value)
86+
{
87+
this.WriteEvent(6, key, value);
88+
}
89+
90+
void IConfigurationExtensionsLogger.LogInvalidConfigurationValue(string key, string value)
91+
{
92+
this.InvalidConfigurationValue(key, value);
93+
}
8294
}

src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
using System.Diagnostics.CodeAnalysis;
77
#endif
88
using System.Diagnostics.Tracing;
9+
using Microsoft.Extensions.Configuration;
910

1011
namespace OpenTelemetry.Internal;
1112

1213
/// <summary>
1314
/// EventSource implementation for OpenTelemetry SDK implementation.
1415
/// </summary>
1516
[EventSource(Name = "OpenTelemetry-Sdk")]
16-
internal sealed class OpenTelemetrySdkEventSource : EventSource
17+
internal sealed class OpenTelemetrySdkEventSource : EventSource, IConfigurationExtensionsLogger
1718
{
1819
public static OpenTelemetrySdkEventSource Log = new();
1920
#if DEBUG
@@ -304,8 +305,8 @@ public void TracerProviderSdkEvent(string message)
304305
this.WriteEvent(46, message);
305306
}
306307

307-
[Event(47, Message = "{0} environment variable has an invalid value: '{1}'", Level = EventLevel.Warning)]
308-
public void InvalidEnvironmentVariable(string key, string? value)
308+
[Event(47, Message = "Configuration key '{0}' has an invalid value: '{1}'", Level = EventLevel.Warning)]
309+
public void InvalidConfigurationValue(string key, string? value)
309310
{
310311
this.WriteEvent(47, key, value);
311312
}
@@ -358,6 +359,11 @@ public void TracesSamplerArgConfigInvalid(string configValue)
358359
this.WriteEvent(55, configValue);
359360
}
360361

362+
void IConfigurationExtensionsLogger.LogInvalidConfigurationValue(string key, string value)
363+
{
364+
this.InvalidConfigurationValue(key, value);
365+
}
366+
361367
#if DEBUG
362368
public class OpenTelemetryEventListener : EventListener
363369
{

src/OpenTelemetry/Logs/BatchExportLogRecordProcessorOptions.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using Microsoft.Extensions.Configuration;
5+
using OpenTelemetry.Internal;
56

67
namespace OpenTelemetry.Logs;
78

@@ -31,22 +32,22 @@ public BatchExportLogRecordProcessorOptions()
3132

3233
internal BatchExportLogRecordProcessorOptions(IConfiguration configuration)
3334
{
34-
if (configuration.TryGetIntValue(ExporterTimeoutEnvVarKey, out var value))
35+
if (configuration.TryGetIntValue(OpenTelemetrySdkEventSource.Log, ExporterTimeoutEnvVarKey, out var value))
3536
{
3637
this.ExporterTimeoutMilliseconds = value;
3738
}
3839

39-
if (configuration.TryGetIntValue(MaxExportBatchSizeEnvVarKey, out value))
40+
if (configuration.TryGetIntValue(OpenTelemetrySdkEventSource.Log, MaxExportBatchSizeEnvVarKey, out value))
4041
{
4142
this.MaxExportBatchSize = value;
4243
}
4344

44-
if (configuration.TryGetIntValue(MaxQueueSizeEnvVarKey, out value))
45+
if (configuration.TryGetIntValue(OpenTelemetrySdkEventSource.Log, MaxQueueSizeEnvVarKey, out value))
4546
{
4647
this.MaxQueueSize = value;
4748
}
4849

49-
if (configuration.TryGetIntValue(ScheduledDelayEnvVarKey, out value))
50+
if (configuration.TryGetIntValue(OpenTelemetrySdkEventSource.Log, ScheduledDelayEnvVarKey, out value))
5051
{
5152
this.ScheduledDelayMilliseconds = value;
5253
}

src/OpenTelemetry/Metrics/MeterProviderSdk.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,12 @@ protected override void Dispose(bool disposing)
480480

481481
private void ApplySpecificationConfigurationKeys(IConfiguration configuration)
482482
{
483-
if (configuration.TryGetBoolValue(EmitOverFlowAttributeConfigKey, out this.EmitOverflowAttribute))
483+
if (configuration.TryGetBoolValue(OpenTelemetrySdkEventSource.Log, EmitOverFlowAttributeConfigKey, out this.EmitOverflowAttribute))
484484
{
485485
OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent("Overflow attribute feature enabled via configuration.");
486486
}
487487

488-
if (configuration.TryGetBoolValue(ReclaimUnusedMetricPointsConfigKey, out this.ReclaimUnusedMetricPoints))
488+
if (configuration.TryGetBoolValue(OpenTelemetrySdkEventSource.Log, ReclaimUnusedMetricPointsConfigKey, out this.ReclaimUnusedMetricPoints))
489489
{
490490
OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent("Reclaim unused metric point feature enabled via configuration.");
491491
}

0 commit comments

Comments
 (0)