diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs index f07aec4341c..49431a3b1a4 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs @@ -169,8 +169,8 @@ private static OtlpExporterOptions GetOtlpExporterOptions(IServiceProvider sp, s { // Note: If OtlpExporter has been registered for tracing and/or metrics // then IOptionsFactory will be set by a call to - // OtlpExporterOptions.RegisterOtlpExporterOptionsFactory. However if we - // are only using logging we don't have an opportunity to do that + // OtlpExporterOptions.RegisterOtlpExporterOptionsFactory. However, if we + // are only using logging, we don't have an opportunity to do that // registration so we manually create a factory. var optionsFactory = sp.GetRequiredService>(); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs index 2ddbc6e0b6e..711a8571c2e 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpLogExporterTests.cs @@ -1289,8 +1289,12 @@ public void ValidateInstrumentationScope() Assert.Empty(OtlpLogRecordTransformer.LogListPool); } - [Fact] - public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggerFactoryCreate() + [Theory] + [InlineData("logging", true)] + [InlineData("logging", false)] + [InlineData("tracing", true)] + [InlineData("tracing", false)] + public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggerFactoryCreate(string name, bool optionalNameMatch) { var values = new Dictionary() { @@ -1307,20 +1311,31 @@ public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggerFact { logging.Services.AddSingleton(configuration); - logging.Services.Configure(o => + logging.Services.Configure(name, o => { configureDelegateCalled = true; Assert.Equal(new Uri("http://test:8888"), o.Endpoint); }); - logging.AddOpenTelemetry(o => o.AddOtlpExporter()); + logging.AddOpenTelemetry(o => o.AddOtlpExporter(optionalNameMatch ? name : "otherSignalName", configure: null)); }); - Assert.True(configureDelegateCalled); + if (optionalNameMatch) + { + Assert.True(configureDelegateCalled); + } + else + { + Assert.False(configureDelegateCalled); + } } - [Fact] - public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggingBuilder() + [Theory] + [InlineData("logging", true)] + [InlineData("logging", false)] + [InlineData("tracing", true)] + [InlineData("tracing", false)] + public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggingBuilder(string name, bool optionalNameMatch) { var values = new Dictionary() { @@ -1337,14 +1352,15 @@ public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggingBui services.AddSingleton(configuration); - services.Configure(o => + services.Configure(name, o => { configureDelegateCalled = true; Assert.Equal(new Uri("http://test:8888"), o.Endpoint); }); services.AddLogging( - logging => logging.AddOpenTelemetry(o => o.AddOtlpExporter())); + logging => logging.AddOpenTelemetry(o => + o.AddOtlpExporter(optionalNameMatch ? name : "otherSignalName", configure: null))); using var sp = services.BuildServiceProvider(); @@ -1352,7 +1368,14 @@ public void VerifyEnvironmentVariablesTakenFromIConfigurationWhenUsingLoggingBui Assert.NotNull(factory); - Assert.True(configureDelegateCalled); + if (optionalNameMatch) + { + Assert.True(configureDelegateCalled); + } + else + { + Assert.False(configureDelegateCalled); + } } private static OtlpCommon.KeyValue TryGetAttribute(OtlpLogs.LogRecord record, string key)