From b4e09b24a5b8a2d47b48b79b7e98f7dab4c4c92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 09:17:37 +0100 Subject: [PATCH 01/30] rename local variables --- .../Configurations/ConfigurationExtensions.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index 2c662f9c2d..6564a93753 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -21,52 +21,52 @@ internal static class ConfigurationExtensions public static IList ParseEnabledEnumList(this Configuration source, string enabledConfiguration, string disabledConfiguration, string error) where TEnum : struct, Enum, IConvertible { - var instrumentations = new Dictionary(); - var enabledInstrumentations = source.GetString(enabledConfiguration); - if (enabledInstrumentations != null) + var configurations = new Dictionary(); + var enabledConfigurations = source.GetString(enabledConfiguration); + if (enabledConfigurations != null) { - if (enabledInstrumentations == Constants.ConfigurationValues.None) + if (enabledConfigurations == Constants.ConfigurationValues.None) { return Array.Empty(); } - foreach (var instrumentation in enabledInstrumentations.Split(Constants.ConfigurationValues.Separator)) + foreach (var configuration in enabledConfigurations.Split(Constants.ConfigurationValues.Separator)) { - if (Enum.TryParse(instrumentation, out TEnum parsedType)) + if (Enum.TryParse(configuration, out TEnum parsedType)) { - instrumentations[instrumentation] = parsedType; + configurations[configuration] = parsedType; } else { - throw new FormatException(string.Format(error, instrumentation)); + throw new FormatException(string.Format(error, configuration)); } } } else { - instrumentations = Enum.GetValues(typeof(TEnum)) + configurations = Enum.GetValues(typeof(TEnum)) .Cast() .ToDictionary( key => Enum.GetName(typeof(TEnum), key)!, val => val); } - var disabledInstrumentations = source.GetString(disabledConfiguration); - if (disabledInstrumentations != null) + var disabledConfigurations = source.GetString(disabledConfiguration); + if (disabledConfigurations != null) { - foreach (var instrumentation in disabledInstrumentations.Split(Constants.ConfigurationValues.Separator)) + foreach (var configuration in disabledConfigurations.Split(Constants.ConfigurationValues.Separator)) { - if (Enum.TryParse(instrumentation, out TEnum _)) + if (Enum.TryParse(configuration, out TEnum _)) { - instrumentations.Remove(instrumentation); + configurations.Remove(configuration); } else { - throw new FormatException(string.Format(error, instrumentation)); + throw new FormatException(string.Format(error, configuration)); } } } - return instrumentations.Values.ToList(); + return configurations.Values.ToList(); } } From 56afa56a41de3b22de385530df1104accf605845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 10:00:20 +0100 Subject: [PATCH 02/30] remove IDE warnings in test --- .../Configurations/ConfigurationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index d1afe8fb1d..fc02586259 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -131,8 +131,8 @@ public void ParseDisabledEnumList_Invalid() public void ParseEmptyAsNull_CompositeConfigurationSource() { var mockSource = new Mock(); - mockSource.Setup(x => x.GetString(It.Is(x => x == "TEST_NULL_VALUE"))).Returns(k => null); - mockSource.Setup(x => x.GetString(It.Is(x => x == "TEST_EMPTY_VALUE"))).Returns(k => string.Empty); + mockSource.Setup(x => x.GetString(It.Is(key => key == "TEST_NULL_VALUE"))).Returns(_ => null); + mockSource.Setup(x => x.GetString(It.Is(key => key == "TEST_EMPTY_VALUE"))).Returns(_ => string.Empty); var compositeSource = new Configuration(mockSource.Object); using (new AssertionScope()) From 3d0c95771d9ae9b19fdc6d32e0d447bd7545c4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 10:00:44 +0100 Subject: [PATCH 03/30] new way to parse enabled signals --- .../Configurations/ConfigurationExtensions.cs | 20 +++++++ .../Configurations/ConfigurationTests.cs | 55 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index 6564a93753..aa7adc79f1 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -14,6 +14,8 @@ // limitations under the License. // +using System.Globalization; + namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions @@ -69,4 +71,22 @@ public static IList ParseEnabledEnumList(this Configuration source return configurations.Values.ToList(); } + + public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) + where TEnum : struct, Enum, IConvertible + { + var enabledConfigurations = new List(); + + foreach (var configuration in Enum.GetValues(typeof(TEnum)).Cast()) + { + var configurationEnable = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; + + if (configurationEnable) + { + enabledConfigurations.Add(configuration); + } + } + + return enabledConfigurations; + } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index fc02586259..4e1f13e894 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -127,6 +127,61 @@ public void ParseDisabledEnumList_Invalid() .WithMessage("Invalid enum value: invalid"); } + [Fact] + public void ParseEnabledEnumList_Default_Enabled() + { + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); + + var list = source.ParseEnabledEnumList( + enabledByDefault: true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + + list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); + } + + [Fact] + public void ParseEnabledEnumList_Default_Disabled() + { + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); + + var list = source.ParseEnabledEnumList( + enabledByDefault: false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + + list.Should().BeEmpty(); + } + + [Fact] + public void ParseEnabledEnumList_SelectivelyEnabled() + { + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection + { + { "TEST_CONFIGURATION_Test1_ENABLED", "true" }, + { "TEST_CONFIGURATION_Test3_ENABLED", "true" } + })); + + var list = source.ParseEnabledEnumList( + false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + + list.Should().Equal(TestEnum.Test1, TestEnum.Test3); + } + + [Fact] + public void ParseEnabledEnumList_SelectivelyDisabled() + { + var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection + { + { "TEST_CONFIGURATION_Test2_ENABLED", "false" }, + })); + + var list = source.ParseEnabledEnumList( + true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + + list.Should().Equal(TestEnum.Test1, TestEnum.Test3); + } + [Fact] public void ParseEmptyAsNull_CompositeConfigurationSource() { From cbcccf6de80877f978777be541a8d68104fbf974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 16:41:12 +0100 Subject: [PATCH 04/30] new way to configure traces instrumentation - managed code --- .../Configurations/ConfigurationKeys.cs | 13 +++++++---- .../Configurations/TracerSettings.cs | 9 +++++--- .../Configurations/SettingsTests.cs | 23 +++++++------------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index fb46499d6e..b3a61c3a6a 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -55,6 +55,11 @@ internal static class ConfigurationKeys /// public const string SetupSdk = "OTEL_DOTNET_AUTO_SETUP_SDK"; + /// + /// Configuration key for enabling all instrumentations. + /// + public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; + /// /// Configuration keys for traces. /// @@ -82,14 +87,14 @@ public static class Traces public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for comma separated list of enabled trace instrumentations. + /// Configuration key for enabling all trace instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS"; + public const string TracesInstrumentationEnabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled trace instrumentations. + /// Configuration key template for enabled trace instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS"; + public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the tracer at the startup. diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index e722f1135b..99b2f3ba86 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -76,10 +76,13 @@ protected override void OnLoad(Configuration configuration) TracesExporter = ParseTracesExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Traces.Instrumentations, - disabledConfiguration: ConfigurationKeys.Traces.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported trace instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Traces.AdditionalSources); if (additionalSources != null) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index d01d817317..c48deb9041 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -32,7 +32,6 @@ public SettingsTests() public static IEnumerable ExporterEnvVarAndLoadSettingsAction() { yield return new object[] { ConfigurationKeys.Traces.Exporter, new Action(() => Settings.FromDefaultSources()) }; - yield return new object[] { ConfigurationKeys.Traces.Instrumentations, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Metrics.Exporter, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Metrics.Instrumentations, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Logs.Exporter, new Action(() => Settings.FromDefaultSources()) }; @@ -199,24 +198,14 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, tracerInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedTracerInstrumentation }); } - [Fact] - internal void TracerSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, $"{nameof(TracerInstrumentation.AspNet)},{nameof(TracerInstrumentation.GraphQL)}"); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.DisabledInstrumentations, nameof(TracerInstrumentation.GraphQL)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { TracerInstrumentation.AspNet }); - } - [Fact] internal void TracerSettings_TracerSampler() { @@ -338,13 +327,17 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.DisabledInstrumentations, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSampler, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSamplerArguments, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.GraphQLSetDocument, null); Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, null); Environment.SetEnvironmentVariable(ConfigurationKeys.FlushOnUnhandledException, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Sdk.Propagators, null); + + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); + foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); + } } } From b79a3d5e0f4728501f1c7054664f1b2a9ada872c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 17:19:35 +0100 Subject: [PATCH 05/30] metrics configuration - managed code --- .../Configurations/ConfigurationKeys.cs | 8 +++---- .../Configurations/MetricSettings.cs | 9 ++++--- .../Configurations/SettingsTests.cs | 24 +++++++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index b3a61c3a6a..d315656929 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -151,14 +151,14 @@ public static class Metrics public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for comma separated list of enabled metric instrumentations. + /// Configuration key for enabling all metrics instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"; + public const string MetricsInstrumentationEnabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled metric instrumentations. + /// Configuration key template for enabled metric instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS"; + public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the meter at the startup. diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index de30770c28..64be6ace47 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -51,10 +51,13 @@ protected override void OnLoad(Configuration configuration) MetricExporter = ParseMetricExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Metrics.ConsoleExporterEnabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Metrics.Instrumentations, - disabledConfiguration: ConfigurationKeys.Metrics.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported metrics instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Metrics.AdditionalSources); if (additionalSources != null) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index c48deb9041..c2faf64374 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -33,7 +33,6 @@ public static IEnumerable ExporterEnvVarAndLoadSettingsAction() { yield return new object[] { ConfigurationKeys.Traces.Exporter, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Metrics.Exporter, new Action(() => Settings.FromDefaultSources()) }; - yield return new object[] { ConfigurationKeys.Metrics.Instrumentations, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Logs.Exporter, new Action(() => Settings.FromDefaultSources()) }; yield return new object[] { ConfigurationKeys.Sdk.Propagators, new Action(() => Settings.FromDefaultSources()) }; } @@ -229,24 +228,14 @@ internal void TracerSettings_TracerSampler() [InlineData(nameof(MetricInstrumentation.NServiceBus), MetricInstrumentation.NServiceBus)] internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, meterInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, meterInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedMetricInstrumentation }); } - [Fact] - internal void MeterSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, $"{nameof(MetricInstrumentation.NetRuntime)},{nameof(MetricInstrumentation.AspNet)}"); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, nameof(MetricInstrumentation.AspNet)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { MetricInstrumentation.NetRuntime }); - } - [Theory] [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) @@ -321,8 +310,13 @@ private static void ClearEnvVars() { Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.IncludeFormattedMessage, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.DisabledInstrumentations, null); + + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, null); + foreach (var metricInstrumentation in Enum.GetValues(typeof(MetricInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, null); From 49aca04bdea62a6cce25d3e3001569391c813792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 17:20:24 +0100 Subject: [PATCH 06/30] logs configuration - managed code --- .../Configurations/ConfigurationKeys.cs | 8 +++--- .../Configurations/LogSettings.cs | 9 ++++--- .../Configurations/SettingsTests.cs | 27 ++++++++++--------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index d315656929..4ece6b24db 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -194,14 +194,14 @@ public static class Logs public const string IncludeFormattedMessage = "OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE"; /// - /// Configuration key for comma separated list of enabled logs instrumentations. + /// Configuration key for enabling all log instrumentations. /// - public const string Instrumentations = "OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS"; + public const string LogsInstrumentationEnabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"; /// - /// Configuration key for comma separated list of disabled logs instrumentations. + /// Configuration key template for enabled log instrumentations. /// - public const string DisabledInstrumentations = "OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS"; + public const string EnabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED"; } /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index 2267277130..121cd7035e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -53,10 +53,13 @@ protected override void OnLoad(Configuration configuration) ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Logs.ConsoleExporterEnabled) ?? false; IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledConfiguration: ConfigurationKeys.Logs.Instrumentations, - disabledConfiguration: ConfigurationKeys.Logs.DisabledInstrumentations, - error: "The \"{0}\" is not recognized as supported logs instrumentation and cannot be enabled or disabled."); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate); } private static LogExporter ParseLogExporter(Configuration configuration) diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index c2faf64374..c270104875 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -240,23 +240,14 @@ internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrum [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, logInstrumentation); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), "true"); var settings = Settings.FromDefaultSources(); settings.EnabledInstrumentations.Should().BeEquivalentTo(new List { expectedLogInstrumentation }); } - [Fact] - internal void LogSettings_DisabledInstrumentations() - { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.DisabledInstrumentations, nameof(LogInstrumentation.ILogger)); - - var settings = Settings.FromDefaultSources(); - - settings.EnabledInstrumentations.Should().BeEmpty(); - } - [Theory] [InlineData("true", true)] [InlineData("false", false)] @@ -308,6 +299,12 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string private static void ClearEnvVars() { + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); + foreach (var logInstrumentation in Enum.GetValues(typeof(LogInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.IncludeFormattedMessage, null); @@ -318,8 +315,12 @@ private static void ClearEnvVars() } Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.DisabledInstrumentations, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); + foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) + { + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); + } + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSampler, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesSamplerArguments, null); From ff7dcb637dca0895f9fa611cbaca2b97c25ccf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 17:20:39 +0100 Subject: [PATCH 07/30] fix module tests --- test/IntegrationTests/ModuleTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/IntegrationTests/ModuleTests.cs b/test/IntegrationTests/ModuleTests.cs index 0437b37a83..19b1399bdc 100644 --- a/test/IntegrationTests/ModuleTests.cs +++ b/test/IntegrationTests/ModuleTests.cs @@ -73,8 +73,7 @@ public async Task DefaultNoExporters() [Fact] public async Task Minimal() { - SetEnvironmentVariable(ConfigurationKeys.Traces.Instrumentations, Constants.ConfigurationValues.None); - SetEnvironmentVariable(ConfigurationKeys.Metrics.Instrumentations, Constants.ConfigurationValues.None); + SetEnvironmentVariable(ConfigurationKeys.InstrumentationEnabled, "false"); SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, Constants.ConfigurationValues.None); From 5d0dd3f01f444ea36d17ba2f4700e134cf937d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 18:02:43 +0100 Subject: [PATCH 08/30] avoid reallocation for enabled values --- .../Configurations/ConfigurationExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index aa7adc79f1..c049266e47 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -75,9 +75,10 @@ public static IList ParseEnabledEnumList(this Configuration source public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { - var enabledConfigurations = new List(); + var allConfigurations = Enum.GetValues(typeof(TEnum)).Cast().ToArray(); + var enabledConfigurations = new List(allConfigurations.Length); - foreach (var configuration in Enum.GetValues(typeof(TEnum)).Cast()) + foreach (var configuration in allConfigurations) { var configurationEnable = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; From 7bb173405f7aa76b415ee0696c352dc9c9d7c71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 25 Jan 2023 18:03:57 +0100 Subject: [PATCH 09/30] remove unused cpde --- .../Configurations/ConfigurationExtensions.cs | 52 ---------- .../Configurations/ConfigurationTests.cs | 95 ------------------- 2 files changed, 147 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index c049266e47..f1bd85d67b 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -20,58 +20,6 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions { - public static IList ParseEnabledEnumList(this Configuration source, string enabledConfiguration, string disabledConfiguration, string error) - where TEnum : struct, Enum, IConvertible - { - var configurations = new Dictionary(); - var enabledConfigurations = source.GetString(enabledConfiguration); - if (enabledConfigurations != null) - { - if (enabledConfigurations == Constants.ConfigurationValues.None) - { - return Array.Empty(); - } - - foreach (var configuration in enabledConfigurations.Split(Constants.ConfigurationValues.Separator)) - { - if (Enum.TryParse(configuration, out TEnum parsedType)) - { - configurations[configuration] = parsedType; - } - else - { - throw new FormatException(string.Format(error, configuration)); - } - } - } - else - { - configurations = Enum.GetValues(typeof(TEnum)) - .Cast() - .ToDictionary( - key => Enum.GetName(typeof(TEnum), key)!, - val => val); - } - - var disabledConfigurations = source.GetString(disabledConfiguration); - if (disabledConfigurations != null) - { - foreach (var configuration in disabledConfigurations.Split(Constants.ConfigurationValues.Separator)) - { - if (Enum.TryParse(configuration, out TEnum _)) - { - configurations.Remove(configuration); - } - else - { - throw new FormatException(string.Format(error, configuration)); - } - } - } - - return configurations.Values.ToList(); - } - public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index 4e1f13e894..ed9e72d668 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -32,101 +32,6 @@ private enum TestEnum Test3 } - [Fact] - public void ParseEnabledEnumList_Default() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); - - var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); - } - - [Fact] - public void ParseEnabledEnumList_Enabled() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_ENABLED_VALUES", "Test1,Test3" } - })); - - var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - list.Should().Equal(TestEnum.Test1, TestEnum.Test3); - } - - [Fact] - public void ParseEnabledEnumList_Disabled() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_DISABLED_VALUES", "Test2" } - })); - - var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - list.Should().Equal(TestEnum.Test1, TestEnum.Test3); - } - - [Fact] - public void ParseEnabledEnumList_None() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_ENABLED_VALUES", "none" } - })); - - var list = source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - list.Should().BeEmpty(); - } - - [Fact] - public void ParseEnabledEnumList_Invalid() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_ENABLED_VALUES", "invalid" } - })); - - var act = () => source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - act.Should().Throw() - .WithMessage("Invalid enum value: invalid"); - } - - [Fact] - public void ParseDisabledEnumList_Invalid() - { - var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection() - { - { "TEST_DISABLED_VALUES", "invalid" } - })); - - var act = () => source.ParseEnabledEnumList( - enabledConfiguration: "TEST_ENABLED_VALUES", - disabledConfiguration: "TEST_DISABLED_VALUES", - error: "Invalid enum value: {0}"); - - act.Should().Throw() - .WithMessage("Invalid enum value: invalid"); - } - [Fact] public void ParseEnabledEnumList_Default_Enabled() { From f1bbaae976487406af6cb03e15fbde5c66eafe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 26 Jan 2023 07:55:02 +0100 Subject: [PATCH 10/30] documentation scaffolding --- CHANGELOG.md | 17 +++++++++++++++++ docs/config.md | 19 ++++++++++--------- docs/iis-instrumentation.md | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 709aa5b3bf..5b44b42330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,23 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope to `linux-musl-x64` for Linux musl and `OpenTelemetry.AutoInstrumentation.Native.dylib` to `osx-x64` for MacOS. +- Changed the way to managed enabled instrumentation. Following environmental variables + - `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`z, + - `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS`, + - `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` + + replaced by + + - `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`. ### Deprecated diff --git a/docs/config.md b/docs/config.md index 59c2988ebc..7be69b887d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -57,15 +57,16 @@ for more details. ## Instrumentations -| Environment variable | Description | Default value | -|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------| -| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS` | Comma-separated list of traces source instrumentations you want to enable. Set to `none` to disable all trace instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS` | Comma-separated list of traces source and bytecode instrumentations you want to disable. | | -| `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of metrics source instrumentations you want to disable. | | -| `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to enable. Set to `none` to disable all metric instrumentations. | all available instrumentations | -| `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` | Comma-separated list of logs source instrumentations you want to disable. | | +| Environment variable | Description | Default value | +|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | | `true` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### Traces instrumentations diff --git a/docs/iis-instrumentation.md b/docs/iis-instrumentation.md index 6689356e57..5f711eb016 100644 --- a/docs/iis-instrumentation.md +++ b/docs/iis-instrumentation.md @@ -66,4 +66,4 @@ to set it for all ASP.NET application running in Integrated Pipeline Mode: ## Enable ASP.NET instrumentation Make sure to enable the ASP.NET instrumentation by setting -`OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS=AspNet`. +`OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED=true`. From 393e425a50062c81f1bebbe91533362a912c51b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 26 Jan 2023 07:55:50 +0100 Subject: [PATCH 11/30] Update tests to use new variables --- test/IntegrationTests/AspNetTests.cs | 3 ++- test/IntegrationTests/GraphQLTests.cs | 3 ++- test/IntegrationTests/GrpcNetClientTests.cs | 3 ++- test/IntegrationTests/SmokeTests.cs | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index 7bcadde9cb..b1fcbf3d04 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -108,7 +108,8 @@ public async Task SubmitMetrics() _environmentVariables["OTEL_METRICS_EXPORTER"] = "otlp"; _environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl; _environmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = "1000"; - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"] = "AspNet"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. var webPort = TcpPortProvider.GetOpenPort(); await using var container = await StartContainerAsync(webPort); await CallTestApplicationEndpoint(webPort); diff --git a/test/IntegrationTests/GraphQLTests.cs b/test/IntegrationTests/GraphQLTests.cs index 6ac59207ac..ae726759bb 100644 --- a/test/IntegrationTests/GraphQLTests.cs +++ b/test/IntegrationTests/GraphQLTests.cs @@ -60,7 +60,8 @@ public async Task SubmitsTraces(bool setDocument) Expect(collector, spanName: "subscription NotImplementedSub", graphQLOperationType: "subscription", graphQLOperationName: "NotImplementedSub", graphQLDocument: "subscription NotImplementedSub{throwNotImplementedException{name}}", setDocument: setDocument, verifyFailure: VerifyNotImplementedException); SetEnvironmentVariable("OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT", setDocument.ToString()); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "GraphQL"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED", "true"); SetEnvironmentVariable("OTEL_TRACES_SAMPLER", "always_on"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED", "false"); diff --git a/test/IntegrationTests/GrpcNetClientTests.cs b/test/IntegrationTests/GrpcNetClientTests.cs index 4e675c9f70..64e7724115 100644 --- a/test/IntegrationTests/GrpcNetClientTests.cs +++ b/test/IntegrationTests/GrpcNetClientTests.cs @@ -37,7 +37,8 @@ public void SubmitsTraces() // Grpc.Net.Client is using various version of http communication under the hood. // Enabling only GrpcNetClient instrumentation to have consistent set of spans. - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "GrpcNetClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_ENABLED", "true"); RunTestApplication(); collector.AssertExpectations(); diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index 4782b947af..92a22cb6ca 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -35,7 +35,8 @@ public SmokeTests(ITestOutputHelper output) : base("Smoke", output) { SetEnvironmentVariable("OTEL_SERVICE_NAME", ServiceName); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "HttpClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); } [Fact] @@ -257,7 +258,8 @@ public void SubmitLogs() } [Theory] - [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS", "none")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED", "false")] [InlineData("OTEL_LOGS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -276,8 +278,8 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) #endif [Theory] - [InlineData("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS", "none")] - [InlineData("OTEL_DOTNET_AUTO_TRACES_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_TRACES_EXPORTER", "none")] [Trait("Category", "EndToEnd")] public void TracesNoneInstrumentations(string envVarName, string envVarVal) @@ -290,7 +292,8 @@ public void TracesNoneInstrumentations(string envVarName, string envVarVal) } [Theory] - [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS", "none")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED", "false")] [InlineData("OTEL_METRICS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -319,8 +322,7 @@ public void LogsDisabledInstrumentation() public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS", "HttpClient"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS", "HttpClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); EnableBytecodeInstrumentation(); RunTestApplication(); collector.AssertEmpty(); @@ -332,7 +334,8 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS", "AspNet,HttpClient"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "false"); RunTestApplication(); collector.AssertEmpty(); } From e0fbf95f9590321d27b6fa3c62b2be6ac94b42b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 26 Jan 2023 13:28:09 +0100 Subject: [PATCH 12/30] include missing file into vcxproj --- .../OpenTelemetry.AutoInstrumentation.Native.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj index 874bea799a..7e06d8204e 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj +++ b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj @@ -199,6 +199,7 @@ + From fccf337dbbb3c9fe617bc01d9dcd8ca233a5b898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 07:00:14 +0100 Subject: [PATCH 13/30] integration generator - cleanup code --- tools/IntegrationsJsonGenerator/Program.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 1d71f228e0..edd0c118c6 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -32,7 +32,7 @@ var assemblyInstrumentMethodAttributes = autoInstrumentationLib.DefinedTypes .Where(type => InheritsFrom(type, instrumentMethodAttributeName)).Select(x => x.FullName); -var integrations = new Dictionary<(string, string), Integration>(); +var integrations = new Dictionary<(string IntegrationType, string IntegrationName), Integration>(); foreach (var typeInfo in autoInstrumentationLib.GetTypes()) { foreach (var attribute in typeInfo.GetCustomAttributes() @@ -40,29 +40,29 @@ { var integration = ConvertToIntegration(typeInfo.FullName!, attribute); - if (!integrations.ContainsKey((integration.IntegartionType, integration.IntegrationName))) + if (!integrations.ContainsKey((integration.IntegrationType, integration.IntegrationName))) { integrations.Add( - (integration.IntegartionType, integration.IntegrationName), + (integration.IntegrationType, integration.IntegrationName), new Integration { Name = integration.IntegrationName, - Type = integration.IntegartionType, + Type = integration.IntegrationType, MethodReplacements = new List { integration.MethodReplacement } }); } else { - var integration2 = integrations[(integration.IntegartionType, integration.IntegrationName)]; + var integration2 = integrations[(integration.IntegrationType, integration.IntegrationName)]; integration2.MethodReplacements.Add(integration.MethodReplacement); } } } -var productionIntegrations = integrations.Where(x => x.Key.Item2 != "StrongNamedValidation").Select(x => x.Value) +var productionIntegrations = integrations.Where(x => x.Key.IntegrationName != "StrongNamedValidation").Select(x => x.Value) .OrderBy(x => x.Name).ToArray(); -var testIntegrations = integrations.Where(x => x.Key.Item2 == "StrongNamedValidation").Select(x => AppendMockIntegrations(x.Value)) +var testIntegrations = integrations.Where(x => x.Key.IntegrationName == "StrongNamedValidation").Select(x => AppendMockIntegrations(x.Value)) .OrderBy(x => x.Name).ToArray(); UpdateIntegrationFile(Path.Combine(solutionFolder, "integrations.json"), productionIntegrations); @@ -86,7 +86,7 @@ bool InheritsFrom(Type type, string baseType) } } -(string IntegartionType, string IntegrationName, MethodReplacement MethodReplacement) ConvertToIntegration(string wrapperTypeName, Attribute attribute) +(string IntegrationType, string IntegrationName, MethodReplacement MethodReplacement) ConvertToIntegration(string wrapperTypeName, Attribute attribute) { var integrationName = GetPropertyValue("IntegrationName", attribute); var integrationType = GetPropertyValue("Type", attribute).ToString()!; From 2cd6ea66cbc3051a40dcfdd7987d304f27166071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 07:01:15 +0100 Subject: [PATCH 14/30] generate available bytecode integration names --- ...lemetry.AutoInstrumentation.Native.vcxproj | 1 + .../bytecode_instrumentations.h | 10 +++++ tools/IntegrationsJsonGenerator/Program.cs | 42 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj index 7e06d8204e..a3c025d710 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj +++ b/src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.vcxproj @@ -180,6 +180,7 @@ + diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h new file mode 100644 index 0000000000..196b950784 --- /dev/null +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -0,0 +1,10 @@ +// Auto-generated file, do not change it - generated by the IntegrationsJsonGenerator + +#include "string.h" + +namespace trace +{ +inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; +} diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index edd0c118c6..8c703e7ea6 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -65,8 +65,23 @@ var testIntegrations = integrations.Where(x => x.Key.IntegrationName == "StrongNamedValidation").Select(x => AppendMockIntegrations(x.Value)) .OrderBy(x => x.Name).ToArray(); +Dictionary> byteCodeIntegrationsByType = new(); + +foreach (var (integrationType, integrationName) in integrations.Keys) +{ + if (byteCodeIntegrationsByType.TryGetValue(integrationType, out var integrationNames)) + { + integrationNames.Add(integrationName); + } + else + { + byteCodeIntegrationsByType.Add(integrationType, new List { integrationName }); + } +} + UpdateIntegrationFile(Path.Combine(solutionFolder, "integrations.json"), productionIntegrations); UpdateIntegrationFile(Path.Combine(solutionFolder, "test", "IntegrationTests", "StrongNamedTestsIntegrations.json"), testIntegrations); +UpdateNativeInstrumentationFile(Path.Combine(solutionFolder, "src", "OpenTelemetry.AutoInstrumentation.Native", "bytecode_instrumentations.h"), byteCodeIntegrationsByType); bool InheritsFrom(Type type, string baseType) { @@ -159,6 +174,33 @@ void UpdateIntegrationFile(string filePath, Integration[] productionIntegrations JsonSerializer.Serialize(fileStream, productionIntegrations1, jsonSerializerOptions); } +void UpdateNativeInstrumentationFile(string filePath, Dictionary> bytecodeIntegrations) +{ + using var fileStream = new FileStream(filePath, FileMode.Truncate); + + using var writer = new StreamWriter(fileStream); + writer.Write($"// Auto-generated file, do not change it - generated by the {nameof(IntegrationsJsonGenerator)}\n"); + writer.Write(@" +#include ""string.h"" + +namespace trace +{ +"); + // inline std::unordered_map traces({"StrongNamedValidation", "StrongNamedValidationKey"}); + foreach (var bytecodeIntegration in bytecodeIntegrations) + { + writer.Write("inline std::unordered_map "); + writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); + writer.Write("_integration_names = {"); + writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); + writer.Write(@"}; +"); + } + + writer.Write(@"} +"); +} + static string GetSourceFilePathName([CallerFilePath] string? callerFilePath = null) => callerFilePath ?? string.Empty; From 1f5d4ff3b1c798936a2b3503280efe61f2eb9423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 08:31:10 +0100 Subject: [PATCH 15/30] new way to load enabled integrations - native code --- .../cor_profiler.cpp | 12 +- .../environment_variables.h | 53 ++----- .../environment_variables_util.h | 16 +++ .../integration_loader.cpp | 23 +-- .../integration_loader.h | 13 +- .../util.cpp | 25 ++++ .../util.h | 4 + .../integration_loader_test.cpp | 136 +++--------------- 8 files changed, 85 insertions(+), 197 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp index 7e6b8b596c..58814e46c4 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp @@ -4,6 +4,7 @@ #include #include +#include "bytecode_instrumentations.h" #include "clr_helpers.h" #include "dllmain.h" #include "environment_variables.h" @@ -163,19 +164,16 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un rejit_handler = new RejitHandler(this->info_, callback); - + const bool instrumentation_enabled_by_default = AreInstrumentationsEnabledByDefault(); // load all integrations from JSON files const LoadIntegrationConfiguration configuration( AreTracesEnabled(), - GetEnvironmentValues(environment::enabled_traces_integrations), - GetEnvironmentValues(environment::disabled_traces_integrations), + GetEnabledEnvironmentValues(AreTracesInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), trace_integration_names), AreMetricsEnabled(), - GetEnvironmentValues(environment::enabled_metrics_integrations), - GetEnvironmentValues(environment::disabled_metrics_integrations), + GetEnabledEnvironmentValues(AreMetricsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), metric_integration_names), AreLogsEnabled(), - GetEnvironmentValues(environment::enabled_logs_integrations), - GetEnvironmentValues(environment::disabled_logs_integrations)); + GetEnabledEnvironmentValues(AreLogsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), log_integration_names)); LoadIntegrationsFromEnvironment(integration_methods_, configuration); Logger::Debug("Number of Integrations loaded: ", integration_methods_.size()); diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h index e2bc51ae17..b5fee2336f 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h @@ -24,60 +24,33 @@ const WSTRING profiler_home_path = WStr("OTEL_DOTNET_AUTO_HOME"); // "MyApp.exe,dotnet.exe" const WSTRING exclude_process_names = WStr("OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES"); +// Whether instrumentations are enabled. If not set (default), all instrumentations are enabled. +const WSTRING instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"); + // Whether traces are enabled or not. If not set (default), traces are enabled. const WSTRING traces_enabled = WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations are enabled. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_traces_integrations = - WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will remain -// unchanged. Calculation order: OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS -// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS is checked. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_traces_integrations = - WStr("OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS"); +// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING traces_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"); // Whether metrics are enabled or not. If not set (default), traces are enabled. const WSTRING metrics_enabled = WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations are enabled. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_metrics_integrations = - WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will remain -// unchanged. Calculation order: OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS -// then if instrumentation is not explicitly disabled OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS is checked. -// Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_metrics_integrations = - WStr("OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS"); +// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING metrics_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"); // Whether logs are enabled or not. If not set (default), logs are enabled. const WSTRING logs_enabled = WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED"); -// Sets a list of integrations to enable. If not set (default), all integrations -// are enabled. Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING enabled_logs_integrations = - WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS"); - -// Sets a list of integrations to disable. Status of other integrations will -// remain unchanged. Calculation order: -// OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS then if instrumentation is -// not explicitly disabled OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS is -// checked. Supports multiple values separated with comma, for example: -// "ElasticsearchNet,AspNetWebApi2" -const WSTRING disabled_logs_integrations = - WStr("OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS"); +// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING logs_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"); // Sets the directory for the profiler's log file. // If not set, default is diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h index 1c12ac93cc..1de9494693 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h @@ -78,6 +78,22 @@ bool IsNetFxAssemblyRedirectionEnabled() { ToBooleanWithDefault(GetEnvironmentValue(environment::netfx_assembly_redirection_enabled), true); } +bool AreInstrumentationsEnabledByDefault() { + ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), true); +} + +bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_enabled), enabled_if_not_configured); +} + +bool AreMetricsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_enabled), enabled_if_not_configured); +} + +bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_enabled), enabled_if_not_configured); +} + } // namespace trace #endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_ \ No newline at end of file diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp index 3a5c857863..a7c4a1cdf7 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.cpp @@ -119,23 +119,8 @@ namespace { bool InstrumentationEnabled( const WSTRING name, - const std::vector& enabledIntegrationNames, - const std::vector& disabledIntegrationNames) + const std::vector& enabledIntegrationNames) { - // check if the integration is disabled - for (const WSTRING& disabledName : disabledIntegrationNames) - { - if (name == disabledName) - { - return false; - } - } - - if (enabledIntegrationNames.empty()) - { - return true; - } - // check if the integration is enabled for (const WSTRING& enabledName : enabledIntegrationNames) { @@ -178,7 +163,7 @@ namespace return; } - if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames, configuration.disabledTraceIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledTraceIntegrationNames)) { return; } @@ -189,7 +174,7 @@ namespace { return; } - if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames, configuration.disabledMetricIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledMetricIntegrationNames)) { return; } @@ -200,7 +185,7 @@ namespace { return; } - if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames, configuration.disabledLogIntegrationNames)) + if (!InstrumentationEnabled(name, configuration.enabledLogIntegrationNames)) { return; } diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h index fb67736635..22f8721851 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/integration_loader.h @@ -20,33 +20,24 @@ class LoadIntegrationConfiguration { public: LoadIntegrationConfiguration(bool traces_enabled, std::vector enabled_trace_integration_names, - std::vector disabled_trace_integration_names, bool metrics_enabled, std::vector enabled_metric_integration_names, - std::vector disabled_metric_integration_names, bool logs_enabled, - std::vector enabled_log_integration_names, - std::vector disabled_log_integration_names) + std::vector enabled_log_integration_names) : traces_enabled(traces_enabled), enabledTraceIntegrationNames(std::move(enabled_trace_integration_names)), - disabledTraceIntegrationNames(std::move(disabled_trace_integration_names)), metrics_enabled(metrics_enabled), enabledMetricIntegrationNames(std::move(enabled_metric_integration_names)), - disabledMetricIntegrationNames(std::move(disabled_metric_integration_names)), logs_enabled(logs_enabled), - enabledLogIntegrationNames(std::move(enabled_log_integration_names)), - disabledLogIntegrationNames(std::move(disabled_log_integration_names)) { + enabledLogIntegrationNames(std::move(enabled_log_integration_names)) { } const bool traces_enabled; const std::vector enabledTraceIntegrationNames; - const std::vector disabledTraceIntegrationNames; const bool metrics_enabled; const std::vector enabledMetricIntegrationNames; - const std::vector disabledMetricIntegrationNames; const bool logs_enabled; const std::vector enabledLogIntegrationNames; - const std::vector disabledLogIntegrationNames; }; // LoadIntegrationsFromEnvironment loads integrations from any files specified diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp index cde66bb293..ad6b0f3018 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,30 @@ std::vector GetEnvironmentValues(const WSTRING& name) return GetEnvironmentValues(name, L','); } +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map values_map) +{ + std::vector values; + + for (auto value : values_map) + { + bool enabled = enabled_by_default; + const auto env_value = GetEnvironmentValue(value.second); + if (env_value == WStr("true")) + { + enabled = true; + } + else if (env_value == WStr("false")) + { + enabled = false; + } + if (enabled) + { + values.push_back(value.first); + } + } + + return values; +} std::vector GetEnvironmentVariables(const std::vector &prefixes) { diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.h b/src/OpenTelemetry.AutoInstrumentation.Native/util.h index 193702ac5e..696825306f 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "string.h" @@ -35,6 +36,9 @@ std::vector GetEnvironmentValues(const WSTRING& name); // GetEnvironmentVariables returns list of all environment variable std::vector GetEnvironmentVariables(const std::vector &prefixes); +// GetEnabledEnvironmentValues returns collection of enabled elements from values_map +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map values_map); + // Convert Hex to string WSTRING HexStr(const void* data, int len); diff --git a/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp b/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp index 28ceaacf47..b7d2e70a8b 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp +++ b/test/OpenTelemetry.AutoInstrumentation.Native.Tests/integration_loader_test.cpp @@ -16,7 +16,7 @@ using namespace trace; TEST(IntegrationLoaderTest, HandlesMissingFile) { std::vector integrations; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromFile(L"missing-file", integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -25,7 +25,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNoName) { std::vector integrations; std::stringstream str("[{}]"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); // 0 because name is required EXPECT_EQ(0, integrations.size()); @@ -35,7 +35,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationBadJson) { std::vector integrations; std::stringstream str("["); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -44,7 +44,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNotAnObject) { std::vector integrations; std::stringstream str("[1,2,3]"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -55,7 +55,7 @@ TEST(IntegrationLoaderTest, HandlesInvalidIntegrationNotAnArray) std::stringstream str(R"TEXT( {"name": "test-integration"} )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(0, integrations.size()); } @@ -75,7 +75,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithMethodReplacements) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -96,7 +96,7 @@ TEST(IntegrationLoaderTest, DoesNotCrashWithOutOfRangeVersion) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -128,7 +128,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithMissingCaller) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -167,7 +167,7 @@ TEST(IntegrationLoaderTest, HandlesSingleIntegrationWithInvalidTarget) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(1, integrations.size()); EXPECT_STREQ(L"test-integration", integrations[0].integration_name.c_str()); @@ -201,7 +201,7 @@ TEST(IntegrationLoaderTest, LoadsFromEnvironment) const std::vector expected_names = {L"test-integration-1", L"test-integration-2"}; std::vector actual_names; std::vector integrations; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration-1", L"test-integration-2"}, true, {}, true, {}); LoadIntegrationsFromEnvironment(integrations, configuration); for (auto& integration : integrations) { @@ -228,7 +228,7 @@ TEST(IntegrationLoaderTest, DeserializesSignatureTypeArray) }] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); const auto target = integrations[0].replacement.target_method; EXPECT_STREQ(L"System.Void", target.signature_types[0].c_str()); @@ -247,7 +247,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledTraceIntegrations) { const std::vector expected_names = {L"test-trace-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {L"test-trace-integration-2"}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-trace-integration-2"}, true, {}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -268,8 +268,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledMetricIntegrations) { const std::vector expected_names = { L"test-metric-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, {}, {}, true, {L"test-metric-integration-2"}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {L"test-metric-integration-2"}, true, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { actual_names.push_back(integration.integration_name); @@ -289,7 +288,7 @@ TEST(IntegrationLoaderTest, SupportsEnabledLogIntegrations) const std::vector expected_names = {L"test-log-integration-2"}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {L"test-log-integration-2"}, {}); + const LoadIntegrationConfiguration configuration(true, {}, true, {}, true, {L"test-log-integration-2"}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -298,109 +297,6 @@ TEST(IntegrationLoaderTest, SupportsEnabledLogIntegrations) EXPECT_EQ(expected_names, actual_names); } -TEST(IntegrationLoaderTest, SupportsDisabledTraceIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-trace-integration-1", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-2", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-trace-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, {}, {L"test-trace-integration-2"}, true, {}, {}, true, {}, {}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsDisabledMetricIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-metric-integration-1", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-2", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-metric-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {L"test-metric-integration-2"}, true, {}, {}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsDisabledLogIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-log-integration-1", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-2", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-log-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {L"test-log-integration-2"}); - LoadIntegrationsFromStream(str, integrations, configuration); - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - -TEST(IntegrationLoaderTest, SupportsEnabledAndDisabledIntegrations) -{ - std::vector integrations; - std::stringstream str(R"TEXT( - [ - { "name": "test-trace-integration-1", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-2", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-trace-integration-3", "type": "Trace", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-1", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-2", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-metric-integration-3", "type": "Metric", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-1", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-2", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] }, - { "name": "test-log-integration-3", "type": "Log", "method_replacements": [{ "caller": {}, "target": {}, "wrapper": {} }] } - ] - )TEXT"); - - const std::vector expected_names = {L"test-trace-integration-1", L"test-log-integration-1", L"test-metric-integration-1"}; - std::vector actual_names; - const LoadIntegrationConfiguration configuration( - true, - {L"test-trace-integration-1", L"test-trace-integration-2"}, - {L"test-trace-integration-2", L"test-trace-integration-3"}, - true, - {L"test-metric-integration-1", L"test-metric-integration-2"}, - {L"test-metric-integration-2", L"test-metric-integration-3"}, - true, - {L"test-log-integration-1", L"test-log-integration-2"}, - {L"test-log-integration-2", L"test-log-integration-3"}); - - LoadIntegrationsFromStream(str, integrations, configuration); - - for (auto& integration : integrations) - { - actual_names.push_back(integration.integration_name); - } - EXPECT_EQ(expected_names, actual_names); -} - TEST(IntegrationLoaderTest, SupportsDisableAllIntegrations) { std::vector integrations; std::stringstream str(R"TEXT( @@ -413,7 +309,7 @@ TEST(IntegrationLoaderTest, SupportsDisableAllIntegrations) { const std::vector expected_names = {}; std::vector actual_names; - const LoadIntegrationConfiguration configuration(false, {}, {}, false, {}, {}, false, {}, {}); + const LoadIntegrationConfiguration configuration(false, {}, false, {}, false, {}); LoadIntegrationsFromStream(str, integrations, configuration); for (auto& integration : integrations) { @@ -435,7 +331,7 @@ TEST(IntegrationLoaderTest, DuplicatedIntegrations) { ] )TEXT"); - const LoadIntegrationConfiguration configuration(true, {}, {}, true, {}, {}, true, {}, {}); + const LoadIntegrationConfiguration configuration(true, {L"test-integration-1"}, true, {L"test-integration-1"}, true, {L"test-integration-1"}); LoadIntegrationsFromStream(str, integrations, configuration); EXPECT_EQ(4, integrations.size()); From edde1526217481f85cfb2c2a053f11e28fb49b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 09:42:49 +0100 Subject: [PATCH 16/30] fix smoke test --- test/IntegrationTests/SmokeTests.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index 92a22cb6ca..ee5898a710 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -35,8 +35,6 @@ public SmokeTests(ITestOutputHelper output) : base("Smoke", output) { SetEnvironmentVariable("OTEL_SERVICE_NAME", ServiceName); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); } [Fact] @@ -54,7 +52,7 @@ public void WhenStartupHookIsNotEnabled() #if NETFRAMEWORK VerifyTestApplicationInstrumented(); #else - // on .NET Core it is required to set DOTNET_STARTUP_HOOKS + // on .NET it is required to set DOTNET_STARTUP_HOOKS VerifyTestApplicationNotInstrumented(); #endif } @@ -120,6 +118,7 @@ public void TracesResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -138,6 +137,7 @@ public void MetricsResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -157,6 +157,7 @@ public void LogsResource() collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version); collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -172,6 +173,7 @@ public void OtlpTracesExporter() SetExporter(collector); collector.Expect("MyCompany.MyProduct.MyLibrary", span => span.Name == "SayHello"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -185,6 +187,7 @@ public void ZipkinExporter() using var collector = new MockZipkinCollector(Output); collector.Expect(span => span.Name == "SayHello" && span.Tags?.GetValueOrDefault("otel.library.name") == "MyCompany.MyProduct.MyLibrary"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_TRACES_EXPORTER", "zipkin"); SetEnvironmentVariable("OTEL_EXPORTER_ZIPKIN_ENDPOINT", $"http://localhost:{collector.Port}/api/v2/spans"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); @@ -198,6 +201,7 @@ public void ZipkinExporter() [Trait("Category", "EndToEnd")] public void PrometheusExporter() { + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("LONG_RUNNING", "true"); SetEnvironmentVariable("OTEL_METRICS_EXPORTER", "prometheus"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); @@ -250,6 +254,7 @@ public void SubmitLogs() SetExporter(collector); collector.Expect(logRecord => Convert.ToString(logRecord.Body) == "{ \"stringValue\": \"Example log message\" }"); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE", "true"); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -268,6 +273,7 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) using var collector = new MockLogsCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable(envVarName, envVarVal); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -301,6 +307,7 @@ public void MetricsNoneInstrumentations(string envVarName, string envVarVal) { using var collector = new MockMetricsCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable(envVarName, envVarVal); RunTestApplication(); collector.AssertEmpty(); @@ -312,6 +319,7 @@ public void LogsDisabledInstrumentation() { using var collector = new MockLogsCollector(Output); SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS", "ILogger"); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); collector.AssertEmpty(); @@ -323,6 +331,7 @@ public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); + EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); collector.AssertEmpty(); @@ -353,6 +362,7 @@ private void VerifyTestApplicationInstrumented() collector.Expect("OpenTelemetry.Instrumentation.Http.HttpClient"); #endif + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); @@ -364,9 +374,16 @@ private void VerifyTestApplicationNotInstrumented() using var collector = new MockSpansCollector(Output); SetExporter(collector); + EnableOnlyHttpClientTraceInstrumentation(); SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary"); RunTestApplication(); collector.AssertEmpty(); } + + private void EnableOnlyHttpClientTraceInstrumentation() + { + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); + } } From 860e833b206a2e23730a6fb20566a4c51295f1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 09:43:35 +0100 Subject: [PATCH 17/30] update documentation --- docs/config.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/config.md b/docs/config.md index 7be69b887d..320c0e3fdf 100644 --- a/docs/config.md +++ b/docs/config.md @@ -60,13 +60,13 @@ for more details. | Environment variable | Description | Default value | |--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------| | `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | | `true` | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Enables all metric instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Enables all log instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### Traces instrumentations From d8f28afd5f51f1987cdab27781031df03535ec97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 09:52:32 +0100 Subject: [PATCH 18/30] typo fix --- docs/config.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/config.md b/docs/config.md index 320c0e3fdf..cc778d7f7b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -61,12 +61,12 @@ for more details. |--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------| | `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | | `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Enables all metric instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Enables all log instrumentations. Overriddes `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overriddes `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Enables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Enables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### Traces instrumentations From 228d52f2178081f4082f7c3c7ac81cfacc68c6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 09:58:07 +0100 Subject: [PATCH 19/30] remove temp code --- tools/IntegrationsJsonGenerator/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 8c703e7ea6..ab4737858a 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -186,7 +186,6 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary traces({"StrongNamedValidation", "StrongNamedValidationKey"}); foreach (var bytecodeIntegration in bytecodeIntegrations) { writer.Write("inline std::unordered_map "); From e081254ad2a0404d0e4ce488f702a3c1e2134af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 10:51:27 +0100 Subject: [PATCH 20/30] fix line ending + guard in header --- .../bytecode_instrumentations.h | 2 ++ tools/IntegrationsJsonGenerator/Program.cs | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h index 196b950784..e9a3466b3a 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -1,4 +1,6 @@ // Auto-generated file, do not change it - generated by the IntegrationsJsonGenerator +#ifndef BYTECODE_INSTRUMENTATIONS_H +#define BYTECODE_INSTRUMENTATIONS_H #include "string.h" diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index ab4737858a..647a8bb478 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -179,25 +179,20 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary "); writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); writer.Write("_integration_names = {"); writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); - writer.Write(@"}; -"); + writer.Write("};\r\n"); } - writer.Write(@"} -"); + writer.Write("}\r\n"); } static string GetSourceFilePathName([CallerFilePath] string? callerFilePath = null) From 2300c6ade31d27ec24e2c853a00a37fb5f9951a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 10:52:15 +0100 Subject: [PATCH 21/30] update changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b44b42330..cfaca00e46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope to `linux-musl-x64` for Linux musl and `OpenTelemetry.AutoInstrumentation.Native.dylib` to `osx-x64` for MacOS. -- Changed the way to managed enabled instrumentation. Following environmental variables +- Change the way to manage enabled instrumentations. The following environmental variables: - `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`z, - `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`, @@ -37,7 +37,7 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope - `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_LOGS_DISABLED_INSTRUMENTATIONS` - replaced by + are replaced by: - `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`, - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`, From 767f0166437f102b9f1b6aaec7b904b8a150f0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 10:55:10 +0100 Subject: [PATCH 22/30] md lint --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfaca00e46..1eda4c3950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,8 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope to `linux-musl-x64` for Linux musl and `OpenTelemetry.AutoInstrumentation.Native.dylib` to `osx-x64` for MacOS. -- Change the way to manage enabled instrumentations. The following environmental variables: +- Change the way to manage enabled instrumentations. The following environmental + variables: - `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`z, - `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`, From df37e2869302233ba3a4358c032fdf73df94e941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 11:38:37 +0100 Subject: [PATCH 23/30] add missing endif --- .../bytecode_instrumentations.h | 1 + tools/IntegrationsJsonGenerator/Program.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h index e9a3466b3a..ff5763d167 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -10,3 +10,4 @@ inline std::unordered_map trace_integration_names = {{WStr("St inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; } +#endif diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 647a8bb478..16d3896b9c 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -193,6 +193,7 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary Date: Fri, 27 Jan 2023 12:28:29 +0100 Subject: [PATCH 24/30] ENABLED -> DISABLED --- CHANGELOG.md | 14 ++++----- docs/config.md | 20 ++++++------- .../bytecode_instrumentations.h | 6 ++-- .../cor_profiler.cpp | 8 ++--- .../environment_variables.h | 24 +++++++-------- .../environment_variables_util.h | 16 +++++----- .../util.cpp | 12 ++++---- .../util.h | 2 +- .../Configurations/ConfigurationExtensions.cs | 6 ++-- .../Configurations/ConfigurationKeys.cs | 20 ++++++------- .../Configurations/LogSettings.cs | 8 ++--- .../Configurations/MetricSettings.cs | 10 +++---- .../Configurations/TracerSettings.cs | 10 +++---- test/IntegrationTests/AspNetTests.cs | 4 +-- test/IntegrationTests/GraphQLTests.cs | 4 +-- test/IntegrationTests/GrpcNetClientTests.cs | 4 +-- test/IntegrationTests/ModuleTests.cs | 6 +--- test/IntegrationTests/SmokeTests.cs | 22 +++++++------- .../Configurations/ConfigurationTests.cs | 26 ++++++++-------- .../Configurations/SettingsTests.cs | 30 ++++++++----------- tools/IntegrationsJsonGenerator/Program.cs | 2 +- 21 files changed, 122 insertions(+), 132 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eda4c3950..13dcf36178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,13 +40,13 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope are replaced by: - - `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`, - - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`. + - `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`, + - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED`. ### Deprecated diff --git a/docs/config.md b/docs/config.md index e55f5f3b7e..d7b444939f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -63,16 +63,16 @@ for more details. ## Instrumentations -| Environment variable | Description | Default value | -|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------| -| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Enables all instrumentations. | `true` | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Enables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Enables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Enables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | +| Environment variable | Description | Default value | +|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | Disables all instrumentations. | `false` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | ### Traces instrumentations diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h index ff5763d167..123847d016 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -6,8 +6,8 @@ namespace trace { -inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}}; -inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; -inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_DISABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_DISABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_DISABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_DISABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_DISABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_DISABLED")}}; +inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_DISABLED")}}; +inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_DISABLED")}}; } #endif diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp index 58814e46c4..6f256ef0e8 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp @@ -164,16 +164,16 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un rejit_handler = new RejitHandler(this->info_, callback); - const bool instrumentation_enabled_by_default = AreInstrumentationsEnabledByDefault(); + const bool instrumentation_disabled_by_default = AreInstrumentationsDisabledByDefault(); // load all integrations from JSON files const LoadIntegrationConfiguration configuration( AreTracesEnabled(), - GetEnabledEnvironmentValues(AreTracesInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), trace_integration_names), + GetEnabledEnvironmentValues(AreTracesInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), trace_integration_names), AreMetricsEnabled(), - GetEnabledEnvironmentValues(AreMetricsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), metric_integration_names), + GetEnabledEnvironmentValues(AreMetricsInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), metric_integration_names), AreLogsEnabled(), - GetEnabledEnvironmentValues(AreLogsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), log_integration_names)); + GetEnabledEnvironmentValues(AreLogsInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), log_integration_names)); LoadIntegrationsFromEnvironment(integration_methods_, configuration); Logger::Debug("Number of Integrations loaded: ", integration_methods_.size()); diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h index b5fee2336f..e5b36f0698 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h @@ -24,33 +24,33 @@ const WSTRING profiler_home_path = WStr("OTEL_DOTNET_AUTO_HOME"); // "MyApp.exe,dotnet.exe" const WSTRING exclude_process_names = WStr("OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES"); -// Whether instrumentations are enabled. If not set (default), all instrumentations are enabled. -const WSTRING instrumentation_enabled = - WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"); +// Whether instrumentations are disabled. If not set (default), all instrumentations are enabled. +const WSTRING instrumentation_disabled = + WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED"); // Whether traces are enabled or not. If not set (default), traces are enabled. const WSTRING traces_enabled = WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED"); -// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. -const WSTRING traces_instrumentation_enabled = - WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"); +// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. +const WSTRING traces_instrumentation_disabled = + WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED"); // Whether metrics are enabled or not. If not set (default), traces are enabled. const WSTRING metrics_enabled = WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED"); -// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. -const WSTRING metrics_instrumentation_enabled = - WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"); +// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. +const WSTRING metrics_instrumentation_disabled = + WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"); // Whether logs are enabled or not. If not set (default), logs are enabled. const WSTRING logs_enabled = WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED"); -// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. -const WSTRING logs_instrumentation_enabled = - WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"); +// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. +const WSTRING logs_instrumentation_disabled = + WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED"); // Sets the directory for the profiler's log file. // If not set, default is diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h index 1de9494693..e850af94cc 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h @@ -78,20 +78,20 @@ bool IsNetFxAssemblyRedirectionEnabled() { ToBooleanWithDefault(GetEnvironmentValue(environment::netfx_assembly_redirection_enabled), true); } -bool AreInstrumentationsEnabledByDefault() { - ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), true); +bool AreInstrumentationsDisabledByDefault() { + ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_disabled), false); } -bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_enabled), enabled_if_not_configured); +bool AreTracesInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_disabled), disabled_if_not_configured); } -bool AreMetricsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_enabled), enabled_if_not_configured); +bool AreMetricsInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_disabled), disabled_if_not_configured); } -bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_enabled), enabled_if_not_configured); +bool AreLogsInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_disabled), disabled_if_not_configured); } } // namespace trace diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp index ad6b0f3018..365732def7 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp @@ -103,23 +103,23 @@ std::vector GetEnvironmentValues(const WSTRING& name) return GetEnvironmentValues(name, L','); } -std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map values_map) +std::vector GetEnabledEnvironmentValues(const bool disabled_by_default, const std::unordered_map& values_map) { std::vector values; - for (auto value : values_map) + for (const auto& value : values_map) { - bool enabled = enabled_by_default; + bool disabled = disabled_by_default; const auto env_value = GetEnvironmentValue(value.second); if (env_value == WStr("true")) { - enabled = true; + disabled = true; } else if (env_value == WStr("false")) { - enabled = false; + disabled = false; } - if (enabled) + if (!disabled) { values.push_back(value.first); } diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.h b/src/OpenTelemetry.AutoInstrumentation.Native/util.h index 696825306f..2dbca03e9c 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.h @@ -37,7 +37,7 @@ std::vector GetEnvironmentValues(const WSTRING& name); std::vector GetEnvironmentVariables(const std::vector &prefixes); // GetEnabledEnvironmentValues returns collection of enabled elements from values_map -std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map values_map); +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map &values_map); // Convert Hex to string WSTRING HexStr(const void* data, int len); diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index f1bd85d67b..ba0cb70d87 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -20,7 +20,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions { - public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) + public static IList ParseEnabledEnumList(this Configuration source, bool disabledByDefault, string disabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { var allConfigurations = Enum.GetValues(typeof(TEnum)).Cast().ToArray(); @@ -28,9 +28,9 @@ public static IList ParseEnabledEnumList(this Configuration source foreach (var configuration in allConfigurations) { - var configurationEnable = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; + var configurationDisabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, disabledConfigurationTemplate, configuration)) ?? disabledByDefault; - if (configurationEnable) + if (!configurationDisabled) { enabledConfigurations.Add(configuration); } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index 4ece6b24db..fdfd379c69 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -58,7 +58,7 @@ internal static class ConfigurationKeys /// /// Configuration key for enabling all instrumentations. /// - public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; + public const string InstrumentationDisabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED"; /// /// Configuration keys for traces. @@ -87,14 +87,14 @@ public static class Traces public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_TRACES_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for enabling all trace instrumentations. + /// Configuration key for disabling all trace instrumentations. /// - public const string TracesInstrumentationEnabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"; + public const string TracesInstrumentationDisabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED"; /// - /// Configuration key template for enabled trace instrumentations. + /// Configuration key template for disabled trace instrumentations. /// - public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED"; + public const string DisabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED"; /// /// Configuration key for additional names to be added to the tracer at the startup. @@ -151,14 +151,14 @@ public static class Metrics public const string ConsoleExporterEnabled = "OTEL_DOTNET_AUTO_METRICS_CONSOLE_EXPORTER_ENABLED"; /// - /// Configuration key for enabling all metrics instrumentations. + /// Configuration key for disabling all metrics instrumentations. /// - public const string MetricsInstrumentationEnabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"; + public const string MetricsInstrumentationDisabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"; /// /// Configuration key template for enabled metric instrumentations. /// - public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED"; + public const string DisabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED"; /// /// Configuration key for additional names to be added to the meter at the startup. @@ -196,12 +196,12 @@ public static class Logs /// /// Configuration key for enabling all log instrumentations. /// - public const string LogsInstrumentationEnabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"; + public const string LogsInstrumentationDisabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED"; /// /// Configuration key template for enabled log instrumentations. /// - public const string EnabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED"; + public const string DisabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED"; } /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index 121cd7035e..c1286b5575 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -54,12 +54,12 @@ protected override void OnLoad(Configuration configuration) IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false; var instrumentationEnabledByDefault = - configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationEnabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationDisabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledByDefault: instrumentationEnabledByDefault, - enabledConfigurationTemplate: ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate); + disabledByDefault: instrumentationEnabledByDefault, + disabledConfigurationTemplate: ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate); } private static LogExporter ParseLogExporter(Configuration configuration) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index 64be6ace47..9ce61a3ad0 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -51,13 +51,13 @@ protected override void OnLoad(Configuration configuration) MetricExporter = ParseMetricExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Metrics.ConsoleExporterEnabled) ?? false; - var instrumentationEnabledByDefault = - configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + var instrumentationDisabledByDefault = + configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledByDefault: instrumentationEnabledByDefault, - enabledConfigurationTemplate: ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate); + disabledByDefault: instrumentationDisabledByDefault, + disabledConfigurationTemplate: ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Metrics.AdditionalSources); if (additionalSources != null) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index 99b2f3ba86..282289ea56 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -76,13 +76,13 @@ protected override void OnLoad(Configuration configuration) TracesExporter = ParseTracesExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false; - var instrumentationEnabledByDefault = - configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; + var instrumentationDisabledByDefault = + configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationDisabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; EnabledInstrumentations = configuration.ParseEnabledEnumList( - enabledByDefault: instrumentationEnabledByDefault, - enabledConfigurationTemplate: ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate); + disabledByDefault: instrumentationDisabledByDefault, + disabledConfigurationTemplate: ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Traces.AdditionalSources); if (additionalSources != null) diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index b1fcbf3d04..1c0e8c7d9c 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -108,8 +108,8 @@ public async Task SubmitMetrics() _environmentVariables["OTEL_METRICS_EXPORTER"] = "otlp"; _environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl; _environmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = "1000"; - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_DISABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. var webPort = TcpPortProvider.GetOpenPort(); await using var container = await StartContainerAsync(webPort); await CallTestApplicationEndpoint(webPort); diff --git a/test/IntegrationTests/GraphQLTests.cs b/test/IntegrationTests/GraphQLTests.cs index ae726759bb..dd8f487a2d 100644 --- a/test/IntegrationTests/GraphQLTests.cs +++ b/test/IntegrationTests/GraphQLTests.cs @@ -60,8 +60,8 @@ public async Task SubmitsTraces(bool setDocument) Expect(collector, spanName: "subscription NotImplementedSub", graphQLOperationType: "subscription", graphQLOperationName: "NotImplementedSub", graphQLDocument: "subscription NotImplementedSub{throwNotImplementedException{name}}", setDocument: setDocument, verifyFailure: VerifyNotImplementedException); SetEnvironmentVariable("OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT", setDocument.ToString()); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_DISABLED", "false"); SetEnvironmentVariable("OTEL_TRACES_SAMPLER", "always_on"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED", "false"); diff --git a/test/IntegrationTests/GrpcNetClientTests.cs b/test/IntegrationTests/GrpcNetClientTests.cs index 64e7724115..a95dad3bfd 100644 --- a/test/IntegrationTests/GrpcNetClientTests.cs +++ b/test/IntegrationTests/GrpcNetClientTests.cs @@ -37,8 +37,8 @@ public void SubmitsTraces() // Grpc.Net.Client is using various version of http communication under the hood. // Enabling only GrpcNetClient instrumentation to have consistent set of spans. - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_DISABLED", "false"); RunTestApplication(); collector.AssertExpectations(); diff --git a/test/IntegrationTests/ModuleTests.cs b/test/IntegrationTests/ModuleTests.cs index 19b1399bdc..567c7ac7bf 100644 --- a/test/IntegrationTests/ModuleTests.cs +++ b/test/IntegrationTests/ModuleTests.cs @@ -14,14 +14,10 @@ // limitations under the License. // -using System.IO; -using System.Threading.Tasks; using IntegrationTests.Helpers; using Newtonsoft.Json; using OpenTelemetry.AutoInstrumentation; using OpenTelemetry.AutoInstrumentation.Configurations; -using VerifyXunit; -using Xunit; using Xunit.Abstractions; namespace IntegrationTests; @@ -73,7 +69,7 @@ public async Task DefaultNoExporters() [Fact] public async Task Minimal() { - SetEnvironmentVariable(ConfigurationKeys.InstrumentationEnabled, "false"); + SetEnvironmentVariable(ConfigurationKeys.InstrumentationDisabled, "true"); SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, Constants.ConfigurationValues.None); diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index ee5898a710..eef58e4df7 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -263,8 +263,8 @@ public void SubmitLogs() } [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] - [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED", "true")] [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED", "false")] [InlineData("OTEL_LOGS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -284,8 +284,8 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) #endif [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] - [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true")] [InlineData("OTEL_TRACES_EXPORTER", "none")] [Trait("Category", "EndToEnd")] public void TracesNoneInstrumentations(string envVarName, string envVarVal) @@ -298,8 +298,8 @@ public void TracesNoneInstrumentations(string envVarName, string envVarVal) } [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] - [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED", "true")] [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED", "false")] [InlineData("OTEL_METRICS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -330,7 +330,7 @@ public void LogsDisabledInstrumentation() public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_DISABLED", "true"); EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -343,8 +343,8 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_DISABLED", "true"); RunTestApplication(); collector.AssertEmpty(); } @@ -383,7 +383,7 @@ private void VerifyTestApplicationNotInstrumented() private void EnableOnlyHttpClientTraceInstrumentation() { - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_DISABLED", "false"); } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index ed9e72d668..625bf10694 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -38,10 +38,10 @@ public void ParseEnabledEnumList_Default_Enabled() var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - enabledByDefault: true, - enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + disabledByDefault: true, + disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); - list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); + list.Should().BeEmpty(); } [Fact] @@ -50,10 +50,10 @@ public void ParseEnabledEnumList_Default_Disabled() var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - enabledByDefault: false, - enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + disabledByDefault: false, + disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); - list.Should().BeEmpty(); + list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); } [Fact] @@ -61,13 +61,13 @@ public void ParseEnabledEnumList_SelectivelyEnabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test1_ENABLED", "true" }, - { "TEST_CONFIGURATION_Test3_ENABLED", "true" } + { "TEST_CONFIGURATION_Test1_DISABLED", "false" }, + { "TEST_CONFIGURATION_Test3_DISABLED", "false" } })); var list = source.ParseEnabledEnumList( - false, - enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + true, + disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } @@ -77,12 +77,12 @@ public void ParseEnabledEnumList_SelectivelyDisabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test2_ENABLED", "false" }, + { "TEST_CONFIGURATION_Test2_DISABLED", "true" }, })); var list = source.ParseEnabledEnumList( - true, - enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); + disabledByDefault: false, + disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index c270104875..cd7fea2e09 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -197,8 +197,8 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), "true"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationDisabled, "true"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate, tracerInstrumentation), "false"); var settings = Settings.FromDefaultSources(); @@ -228,8 +228,8 @@ internal void TracerSettings_TracerSampler() [InlineData(nameof(MetricInstrumentation.NServiceBus), MetricInstrumentation.NServiceBus)] internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, meterInstrumentation), "true"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled, "true"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate, meterInstrumentation), "false"); var settings = Settings.FromDefaultSources(); @@ -240,8 +240,8 @@ internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrum [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, "false"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), "true"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationDisabled, "true"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate, logInstrumentation), "false"); var settings = Settings.FromDefaultSources(); @@ -299,26 +299,26 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string private static void ClearEnvVars() { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationDisabled, null); foreach (var logInstrumentation in Enum.GetValues(typeof(LogInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate, logInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.IncludeFormattedMessage, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled, null); foreach (var metricInstrumentation in Enum.GetValues(typeof(MetricInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate, metricInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationDisabled, null); foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate, tracerInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); @@ -328,11 +328,5 @@ private static void ClearEnvVars() Environment.SetEnvironmentVariable(ConfigurationKeys.ExporterOtlpProtocol, null); Environment.SetEnvironmentVariable(ConfigurationKeys.FlushOnUnhandledException, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Sdk.Propagators, null); - - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); - foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) - { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); - } } } diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 16d3896b9c..3b4edfdae0 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -188,7 +188,7 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary "); writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); writer.Write("_integration_names = {"); - writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); + writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_DISABLED\")}}"))); writer.Write("};\r\n"); } From 9c54b1e98450efe677a5640db18cf5f1fb1e7a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 13:00:43 +0100 Subject: [PATCH 25/30] typo fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f5331b26a..dad5c48d33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope - Change the way to manage enabled instrumentations. The following environmental variables: - `OTEL_DOTNET_AUTO_TRACES_ENABLED_INSTRUMENTATIONS`, - - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`z, + - `OTEL_DOTNET_AUTO_TRACES_DISABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_METRICS_ENABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_METRICS_DISABLED_INSTRUMENTATIONS`, - `OTEL_DOTNET_AUTO_LOGS_ENABLED_INSTRUMENTATIONS`, From 301092ef7c54ffccbc2a7d7b2b1a180347b20009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 13:04:41 +0100 Subject: [PATCH 26/30] generator generates lineending specific for system --- tools/IntegrationsJsonGenerator/Program.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index 3b4edfdae0..fd1df36475 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -179,21 +179,25 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary "); writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); writer.Write("_integration_names = {"); writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_DISABLED\")}}"))); - writer.Write("};\r\n"); + writer.WriteLine("};"); } - writer.Write("}\r\n"); - writer.Write("#endif\r\n"); + writer.WriteLine("}"); + writer.WriteLine("#endif"); } static string GetSourceFilePathName([CallerFilePath] string? callerFilePath = null) From d4398104102607006798baa30f67b8d22d612dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Jan 2023 14:19:10 +0100 Subject: [PATCH 27/30] Adjust documentation Co-authored-by: Fabrizio Ferri-Benedetti --- docs/config.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/config.md b/docs/config.md index 642d618e3c..29787d3025 100644 --- a/docs/config.md +++ b/docs/config.md @@ -62,16 +62,29 @@ for more details. ## Instrumentations -| Environment variable | Description | Default value | -|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------| -| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | Disables all instrumentations. | `false` | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`. | Same as `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | +All instrumentations are enabled by default for all signal types +(traces, metrics, and logs). + +You can disable all instrumentations for a specific signal type by setting +the `OTEL_DOTNET_AUTO_{SIGNAL}_INSTRUMENTATION_DISABLED` +environment variable to `false`. + +For a more granular approach, you can disable specific instrumentations +for a given signal type by setting +the `OTEL_DOTNET_AUTO_{SIGNAL}_{0}_INSTRUMENTATION_DISABLED` +environment variable to `false`, where `{SIGNAL}` is the type of signal, +for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentation. + +| Environment variable | Description | Default value | +|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | Disables all instrumentations. | `false` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | ### Traces instrumentations From 0dc6986dd3c8eb5a80f0472ca40db3ae1008f11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 1 Feb 2023 18:55:02 +0100 Subject: [PATCH 28/30] ENABLED -> DISABLED --- CHANGELOG.md | 14 +++++----- docs/config.md | 24 ++++++++--------- .../bytecode_instrumentations.h | 6 ++--- .../cor_profiler.cpp | 8 +++--- .../environment_variables.h | 24 ++++++++--------- .../environment_variables_util.h | 16 ++++++------ .../util.cpp | 10 +++---- .../Configurations/ConfigurationExtensions.cs | 6 ++--- .../Configurations/ConfigurationKeys.cs | 14 +++++----- .../Configurations/LogSettings.cs | 8 +++--- .../Configurations/MetricSettings.cs | 10 +++---- .../Configurations/TracerSettings.cs | 10 +++---- test/IntegrationTests/AspNetTests.cs | 4 +-- test/IntegrationTests/GraphQLTests.cs | 4 +-- test/IntegrationTests/GrpcNetClientTests.cs | 4 +-- test/IntegrationTests/ModuleTests.cs | 2 +- test/IntegrationTests/SmokeTests.cs | 22 ++++++++-------- .../Configurations/ConfigurationTests.cs | 26 +++++++++---------- .../Configurations/SettingsTests.cs | 24 ++++++++--------- tools/IntegrationsJsonGenerator/Program.cs | 2 +- 20 files changed, 119 insertions(+), 119 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3391bea97e..ad069eb046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,13 +41,13 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope are replaced by: - - `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`, - - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED`. + - `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`, + - `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`. ### Deprecated diff --git a/docs/config.md b/docs/config.md index 29787d3025..2a10c151f5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -66,25 +66,25 @@ All instrumentations are enabled by default for all signal types (traces, metrics, and logs). You can disable all instrumentations for a specific signal type by setting -the `OTEL_DOTNET_AUTO_{SIGNAL}_INSTRUMENTATION_DISABLED` +the `OTEL_DOTNET_AUTO_{SIGNAL}_INSTRUMENTATION_ENABLED` environment variable to `false`. For a more granular approach, you can disable specific instrumentations for a given signal type by setting -the `OTEL_DOTNET_AUTO_{SIGNAL}_{0}_INSTRUMENTATION_DISABLED` +the `OTEL_DOTNET_AUTO_{SIGNAL}_{0}_INSTRUMENTATION_ENABLED` environment variable to `false`, where `{SIGNAL}` is the type of signal, for example `TRACES`, and `{0}` is the case-sensitive name of the instrumentation. -| Environment variable | Description | Default value | -|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------| -| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | -| `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | Disables all instrumentations. | `false` | -| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED` | -| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED` | +| Environment variable | Description | Default value | +|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------| +| `OTEL_DOTNET_AUTO_INTEGRATIONS_FILE` | List of bytecode instrumentations JSON configuration filepaths, delimited by the platform-specific path separator (`;` on Windows, `:` on Linux and macOS). For example: `%ProfilerDirectory%/integrations.json`. It is required for bytecode instrumentations. | | +| `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | Disables all instrumentations. | `true` | +| `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | Disables all trace instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific trace instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | Disables all metric instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific metric instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | Disables all log instrumentations. Overrides `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED` | +| `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED` | Configuration pattern for enabling or disabling a specific log instrumentation, where `{0}` is the case-sensitive name of the instrumentation you want to enable. Overrides `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`. | Inherited from the current value of `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED` | ### Traces instrumentations diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h index 123847d016..ff5763d167 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/bytecode_instrumentations.h @@ -6,8 +6,8 @@ namespace trace { -inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_DISABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_DISABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_DISABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_DISABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_DISABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_DISABLED")}}; -inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_DISABLED")}}; -inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_DISABLED")}}; +inline std::unordered_map trace_integration_names = {{WStr("StrongNamedValidation"), WStr("OTEL_DOTNET_AUTO_TRACES_StrongNamedValidation_INSTRUMENTATION_ENABLED")}, {WStr("StackExchangeRedis"), WStr("OTEL_DOTNET_AUTO_TRACES_StackExchangeRedis_INSTRUMENTATION_ENABLED")}, {WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_TRACES_NServiceBus_INSTRUMENTATION_ENABLED")}, {WStr("MySqlData"), WStr("OTEL_DOTNET_AUTO_TRACES_MySqlData_INSTRUMENTATION_ENABLED")}, {WStr("MongoDB"), WStr("OTEL_DOTNET_AUTO_TRACES_MongoDB_INSTRUMENTATION_ENABLED")}, {WStr("GraphQL"), WStr("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map metric_integration_names = {{WStr("NServiceBus"), WStr("OTEL_DOTNET_AUTO_METRICS_NServiceBus_INSTRUMENTATION_ENABLED")}}; +inline std::unordered_map log_integration_names = {{WStr("ILogger"), WStr("OTEL_DOTNET_AUTO_LOGS_ILogger_INSTRUMENTATION_ENABLED")}}; } #endif diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp index 6f256ef0e8..58814e46c4 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp @@ -164,16 +164,16 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un rejit_handler = new RejitHandler(this->info_, callback); - const bool instrumentation_disabled_by_default = AreInstrumentationsDisabledByDefault(); + const bool instrumentation_enabled_by_default = AreInstrumentationsEnabledByDefault(); // load all integrations from JSON files const LoadIntegrationConfiguration configuration( AreTracesEnabled(), - GetEnabledEnvironmentValues(AreTracesInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), trace_integration_names), + GetEnabledEnvironmentValues(AreTracesInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), trace_integration_names), AreMetricsEnabled(), - GetEnabledEnvironmentValues(AreMetricsInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), metric_integration_names), + GetEnabledEnvironmentValues(AreMetricsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), metric_integration_names), AreLogsEnabled(), - GetEnabledEnvironmentValues(AreLogsInstrumentationsDisabledByDefault(instrumentation_disabled_by_default), log_integration_names)); + GetEnabledEnvironmentValues(AreLogsInstrumentationsEnabledByDefault(instrumentation_enabled_by_default), log_integration_names)); LoadIntegrationsFromEnvironment(integration_methods_, configuration); Logger::Debug("Number of Integrations loaded: ", integration_methods_.size()); diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h index e5b36f0698..b5fee2336f 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables.h @@ -24,33 +24,33 @@ const WSTRING profiler_home_path = WStr("OTEL_DOTNET_AUTO_HOME"); // "MyApp.exe,dotnet.exe" const WSTRING exclude_process_names = WStr("OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES"); -// Whether instrumentations are disabled. If not set (default), all instrumentations are enabled. -const WSTRING instrumentation_disabled = - WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED"); +// Whether instrumentations are enabled. If not set (default), all instrumentations are enabled. +const WSTRING instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"); // Whether traces are enabled or not. If not set (default), traces are enabled. const WSTRING traces_enabled = WStr("OTEL_DOTNET_AUTO_TRACES_ENABLED"); -// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. -const WSTRING traces_instrumentation_disabled = - WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED"); +// Whether traces instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING traces_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"); // Whether metrics are enabled or not. If not set (default), traces are enabled. const WSTRING metrics_enabled = WStr("OTEL_DOTNET_AUTO_METRICS_ENABLED"); -// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. -const WSTRING metrics_instrumentation_disabled = - WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"); +// Whether metrics instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING metrics_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"); // Whether logs are enabled or not. If not set (default), logs are enabled. const WSTRING logs_enabled = WStr("OTEL_DOTNET_AUTO_LOGS_ENABLED"); -// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED is used. -const WSTRING logs_instrumentation_disabled = - WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED"); +// Whether logs instrumentations are enabled. If not set (default), value from OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED is used. +const WSTRING logs_instrumentation_enabled = + WStr("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"); // Sets the directory for the profiler's log file. // If not set, default is diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h index e850af94cc..2208e28c53 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h @@ -78,20 +78,20 @@ bool IsNetFxAssemblyRedirectionEnabled() { ToBooleanWithDefault(GetEnvironmentValue(environment::netfx_assembly_redirection_enabled), true); } -bool AreInstrumentationsDisabledByDefault() { - ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_disabled), false); +bool AreInstrumentationsEnabledByDefault() { + ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), false); } -bool AreTracesInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_disabled), disabled_if_not_configured); +bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::traces_instrumentation_enabled), enabled_if_not_configured); } -bool AreMetricsInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_disabled), disabled_if_not_configured); +bool AreMetricsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::metrics_instrumentation_enabled), enabled_if_not_configured); } -bool AreLogsInstrumentationsDisabledByDefault(const bool disabled_if_not_configured) { - ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_disabled), disabled_if_not_configured); +bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { + ToBooleanWithDefault(GetEnvironmentValue(environment::logs_instrumentation_enabled), enabled_if_not_configured); } } // namespace trace diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp index 365732def7..4c6d164b48 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/util.cpp @@ -103,23 +103,23 @@ std::vector GetEnvironmentValues(const WSTRING& name) return GetEnvironmentValues(name, L','); } -std::vector GetEnabledEnvironmentValues(const bool disabled_by_default, const std::unordered_map& values_map) +std::vector GetEnabledEnvironmentValues(const bool enabled_by_default, const std::unordered_map& values_map) { std::vector values; for (const auto& value : values_map) { - bool disabled = disabled_by_default; + bool enabled = enabled_by_default; const auto env_value = GetEnvironmentValue(value.second); if (env_value == WStr("true")) { - disabled = true; + enabled = true; } else if (env_value == WStr("false")) { - disabled = false; + enabled = false; } - if (!disabled) + if (enabled) { values.push_back(value.first); } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs index ba0cb70d87..8fd68e70b7 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationExtensions.cs @@ -20,7 +20,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations; internal static class ConfigurationExtensions { - public static IList ParseEnabledEnumList(this Configuration source, bool disabledByDefault, string disabledConfigurationTemplate) + public static IList ParseEnabledEnumList(this Configuration source, bool enabledByDefault, string enabledConfigurationTemplate) where TEnum : struct, Enum, IConvertible { var allConfigurations = Enum.GetValues(typeof(TEnum)).Cast().ToArray(); @@ -28,9 +28,9 @@ public static IList ParseEnabledEnumList(this Configuration source foreach (var configuration in allConfigurations) { - var configurationDisabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, disabledConfigurationTemplate, configuration)) ?? disabledByDefault; + var configurationEnabled = source.GetBool(string.Format(CultureInfo.InvariantCulture, enabledConfigurationTemplate, configuration)) ?? enabledByDefault; - if (!configurationDisabled) + if (configurationEnabled) { enabledConfigurations.Add(configuration); } diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index 833a1db33a..ac6380ca29 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -58,7 +58,7 @@ internal static class ConfigurationKeys /// /// Configuration key for enabling all instrumentations. /// - public const string InstrumentationDisabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED"; + public const string InstrumentationEnabled = "OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED"; /// /// Configuration keys for traces. @@ -89,12 +89,12 @@ public static class Traces /// /// Configuration key for disabling all trace instrumentations. /// - public const string TracesInstrumentationDisabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED"; + public const string TracesInstrumentationEnabled = "OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED"; /// /// Configuration key template for disabled trace instrumentations. /// - public const string DisabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_DISABLED"; + public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the tracer at the startup. @@ -153,12 +153,12 @@ public static class Metrics /// /// Configuration key for disabling all metrics instrumentations. /// - public const string MetricsInstrumentationDisabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"; + public const string MetricsInstrumentationEnabled = "OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"; /// /// Configuration key template for enabled metric instrumentations. /// - public const string DisabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_DISABLED"; + public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED"; /// /// Configuration key for additional names to be added to the meter at the startup. @@ -196,12 +196,12 @@ public static class Logs /// /// Configuration key for enabling all log instrumentations. /// - public const string LogsInstrumentationDisabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED"; + public const string LogsInstrumentationEnabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"; /// /// Configuration key template for enabled log instrumentations. /// - public const string DisabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_DISABLED"; + public const string EnabledLogsInstrumentationTemplate = "OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED"; } /// diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs index c1286b5575..121cd7035e 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/LogSettings.cs @@ -54,12 +54,12 @@ protected override void OnLoad(Configuration configuration) IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false; var instrumentationEnabledByDefault = - configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationDisabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; + configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; EnabledInstrumentations = configuration.ParseEnabledEnumList( - disabledByDefault: instrumentationEnabledByDefault, - disabledConfigurationTemplate: ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate); } private static LogExporter ParseLogExporter(Configuration configuration) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs index 9ce61a3ad0..64be6ace47 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/MetricSettings.cs @@ -51,13 +51,13 @@ protected override void OnLoad(Configuration configuration) MetricExporter = ParseMetricExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Metrics.ConsoleExporterEnabled) ?? false; - var instrumentationDisabledByDefault = - configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; EnabledInstrumentations = configuration.ParseEnabledEnumList( - disabledByDefault: instrumentationDisabledByDefault, - disabledConfigurationTemplate: ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Metrics.AdditionalSources); if (additionalSources != null) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs index 282289ea56..99b2f3ba86 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/TracerSettings.cs @@ -76,13 +76,13 @@ protected override void OnLoad(Configuration configuration) TracesExporter = ParseTracesExporter(configuration); ConsoleExporterEnabled = configuration.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false; - var instrumentationDisabledByDefault = - configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationDisabled) ?? - configuration.GetBool(ConfigurationKeys.InstrumentationDisabled) ?? false; + var instrumentationEnabledByDefault = + configuration.GetBool(ConfigurationKeys.Traces.TracesInstrumentationEnabled) ?? + configuration.GetBool(ConfigurationKeys.InstrumentationEnabled) ?? true; EnabledInstrumentations = configuration.ParseEnabledEnumList( - disabledByDefault: instrumentationDisabledByDefault, - disabledConfigurationTemplate: ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate); + enabledByDefault: instrumentationEnabledByDefault, + enabledConfigurationTemplate: ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate); var additionalSources = configuration.GetString(ConfigurationKeys.Traces.AdditionalSources); if (additionalSources != null) diff --git a/test/IntegrationTests/AspNetTests.cs b/test/IntegrationTests/AspNetTests.cs index 1c0e8c7d9c..b1fcbf3d04 100644 --- a/test/IntegrationTests/AspNetTests.cs +++ b/test/IntegrationTests/AspNetTests.cs @@ -108,8 +108,8 @@ public async Task SubmitMetrics() _environmentVariables["OTEL_METRICS_EXPORTER"] = "otlp"; _environmentVariables["OTEL_EXPORTER_OTLP_ENDPOINT"] = collectorUrl; _environmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = "1000"; - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. - _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_DISABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED"] = "false"; // Helps to reduce noise by enabling only AspNet metrics. + _environmentVariables["OTEL_DOTNET_AUTO_METRICS_AspNet_INSTRUMENTATION_ENABLED"] = "true"; // Helps to reduce noise by enabling only AspNet metrics. var webPort = TcpPortProvider.GetOpenPort(); await using var container = await StartContainerAsync(webPort); await CallTestApplicationEndpoint(webPort); diff --git a/test/IntegrationTests/GraphQLTests.cs b/test/IntegrationTests/GraphQLTests.cs index dd8f487a2d..ae726759bb 100644 --- a/test/IntegrationTests/GraphQLTests.cs +++ b/test/IntegrationTests/GraphQLTests.cs @@ -60,8 +60,8 @@ public async Task SubmitsTraces(bool setDocument) Expect(collector, spanName: "subscription NotImplementedSub", graphQLOperationType: "subscription", graphQLOperationName: "NotImplementedSub", graphQLDocument: "subscription NotImplementedSub{throwNotImplementedException{name}}", setDocument: setDocument, verifyFailure: VerifyNotImplementedException); SetEnvironmentVariable("OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT", setDocument.ToString()); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_DISABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GraphQL_INSTRUMENTATION_ENABLED", "true"); SetEnvironmentVariable("OTEL_TRACES_SAMPLER", "always_on"); SetEnvironmentVariable("OTEL_DOTNET_AUTO_NETFX_REDIRECT_ENABLED", "false"); diff --git a/test/IntegrationTests/GrpcNetClientTests.cs b/test/IntegrationTests/GrpcNetClientTests.cs index a95dad3bfd..64e7724115 100644 --- a/test/IntegrationTests/GrpcNetClientTests.cs +++ b/test/IntegrationTests/GrpcNetClientTests.cs @@ -37,8 +37,8 @@ public void SubmitsTraces() // Grpc.Net.Client is using various version of http communication under the hood. // Enabling only GrpcNetClient instrumentation to have consistent set of spans. - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_DISABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_GrpcNetClient_INSTRUMENTATION_ENABLED", "true"); RunTestApplication(); collector.AssertExpectations(); diff --git a/test/IntegrationTests/ModuleTests.cs b/test/IntegrationTests/ModuleTests.cs index 567c7ac7bf..2341a4b23b 100644 --- a/test/IntegrationTests/ModuleTests.cs +++ b/test/IntegrationTests/ModuleTests.cs @@ -69,7 +69,7 @@ public async Task DefaultNoExporters() [Fact] public async Task Minimal() { - SetEnvironmentVariable(ConfigurationKeys.InstrumentationDisabled, "true"); + SetEnvironmentVariable(ConfigurationKeys.InstrumentationEnabled, "false"); SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, Constants.ConfigurationValues.None); SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, Constants.ConfigurationValues.None); diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs index eef58e4df7..ee5898a710 100644 --- a/test/IntegrationTests/SmokeTests.cs +++ b/test/IntegrationTests/SmokeTests.cs @@ -263,8 +263,8 @@ public void SubmitLogs() } [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] - [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_LOGS_ENABLED", "false")] [InlineData("OTEL_LOGS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -284,8 +284,8 @@ public void LogsNoneInstrumentations(string envVarName, string envVarVal) #endif [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] - [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_TRACES_EXPORTER", "none")] [Trait("Category", "EndToEnd")] public void TracesNoneInstrumentations(string envVarName, string envVarVal) @@ -298,8 +298,8 @@ public void TracesNoneInstrumentations(string envVarName, string envVarVal) } [Theory] - [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_DISABLED", "true")] - [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_DISABLED", "true")] + [InlineData("OTEL_DOTNET_AUTO_INSTRUMENTATION_ENABLED", "false")] + [InlineData("OTEL_DOTNET_AUTO_METRICS_INSTRUMENTATION_ENABLED", "false")] [InlineData("OTEL_DOTNET_AUTO_METRICS_ENABLED", "false")] [InlineData("OTEL_METRICS_EXPORTER", "none")] [Trait("Category", "EndToEnd")] @@ -330,7 +330,7 @@ public void LogsDisabledInstrumentation() public void MetricsDisabledInstrumentation() { using var collector = new MockMetricsCollector(Output); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_HttpClient_INSTRUMENTATION_ENABLED", "false"); EnableOnlyHttpClientTraceInstrumentation(); EnableBytecodeInstrumentation(); RunTestApplication(); @@ -343,8 +343,8 @@ public void TracesDisabledInstrumentation() { using var collector = new MockSpansCollector(Output); SetExporter(collector); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_DISABLED", "true"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_DISABLED", "true"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_AspNet_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "false"); RunTestApplication(); collector.AssertEmpty(); } @@ -383,7 +383,7 @@ private void VerifyTestApplicationNotInstrumented() private void EnableOnlyHttpClientTraceInstrumentation() { - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_DISABLED", "true"); - SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_DISABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_INSTRUMENTATION_ENABLED", "false"); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_HttpClient_INSTRUMENTATION_ENABLED", "true"); } } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs index 625bf10694..6a1a5f722c 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/ConfigurationTests.cs @@ -38,10 +38,10 @@ public void ParseEnabledEnumList_Default_Enabled() var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - disabledByDefault: true, - disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); + enabledByDefault: true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); - list.Should().BeEmpty(); + list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); } [Fact] @@ -50,10 +50,10 @@ public void ParseEnabledEnumList_Default_Disabled() var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection())); var list = source.ParseEnabledEnumList( - disabledByDefault: false, - disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); + enabledByDefault: false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); - list.Should().Equal(TestEnum.Test1, TestEnum.Test2, TestEnum.Test3); + list.Should().BeEmpty(); } [Fact] @@ -61,13 +61,13 @@ public void ParseEnabledEnumList_SelectivelyEnabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test1_DISABLED", "false" }, - { "TEST_CONFIGURATION_Test3_DISABLED", "false" } + { "TEST_CONFIGURATION_Test1_ENABLED", "true" }, + { "TEST_CONFIGURATION_Test3_ENABLED", "true" } })); var list = source.ParseEnabledEnumList( - true, - disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); + enabledByDefault: false, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } @@ -77,12 +77,12 @@ public void ParseEnabledEnumList_SelectivelyDisabled() { var source = new Configuration(new NameValueConfigurationSource(new NameValueCollection { - { "TEST_CONFIGURATION_Test2_DISABLED", "true" }, + { "TEST_CONFIGURATION_Test2_ENABLED", "false" }, })); var list = source.ParseEnabledEnumList( - disabledByDefault: false, - disabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_DISABLED"); + enabledByDefault: true, + enabledConfigurationTemplate: "TEST_CONFIGURATION_{0}_ENABLED"); list.Should().Equal(TestEnum.Test1, TestEnum.Test3); } diff --git a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs index cd7fea2e09..aaec6e88a3 100644 --- a/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/SettingsTests.cs @@ -197,8 +197,8 @@ internal void Propagators_SupportedValues(string propagators, Propagator[] expec #endif internal void TracerSettings_Instrumentations_SupportedValues(string tracerInstrumentation, TracerInstrumentation expectedTracerInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationDisabled, "true"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate, tracerInstrumentation), "false"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), "true"); var settings = Settings.FromDefaultSources(); @@ -228,8 +228,8 @@ internal void TracerSettings_TracerSampler() [InlineData(nameof(MetricInstrumentation.NServiceBus), MetricInstrumentation.NServiceBus)] internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled, "true"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate, meterInstrumentation), "false"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, meterInstrumentation), "true"); var settings = Settings.FromDefaultSources(); @@ -240,8 +240,8 @@ internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrum [InlineData(nameof(LogInstrumentation.ILogger), LogInstrumentation.ILogger)] internal void LogSettings_Instrumentations_SupportedValues(string logInstrumentation, LogInstrumentation expectedLogInstrumentation) { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationDisabled, "true"); - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate, logInstrumentation), "false"); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, "false"); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), "true"); var settings = Settings.FromDefaultSources(); @@ -299,26 +299,26 @@ internal void FlushOnUnhandledException_DependsOnCorrespondingEnvVariable(string private static void ClearEnvVars() { - Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationDisabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.LogsInstrumentationEnabled, null); foreach (var logInstrumentation in Enum.GetValues(typeof(LogInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.DisabledLogsInstrumentationTemplate, logInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Logs.EnabledLogsInstrumentationTemplate, logInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.Exporter, null); Environment.SetEnvironmentVariable(ConfigurationKeys.Logs.IncludeFormattedMessage, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationDisabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.MetricsInstrumentationEnabled, null); foreach (var metricInstrumentation in Enum.GetValues(typeof(MetricInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.DisabledMetricsInstrumentationTemplate, metricInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Metrics.EnabledMetricsInstrumentationTemplate, metricInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Metrics.Exporter, null); - Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationDisabled, null); + Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.TracesInstrumentationEnabled, null); foreach (var tracerInstrumentation in Enum.GetValues(typeof(TracerInstrumentation)).Cast()) { - Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.DisabledTracesInstrumentationTemplate, tracerInstrumentation), null); + Environment.SetEnvironmentVariable(string.Format(ConfigurationKeys.Traces.EnabledTracesInstrumentationTemplate, tracerInstrumentation), null); } Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.Exporter, null); diff --git a/tools/IntegrationsJsonGenerator/Program.cs b/tools/IntegrationsJsonGenerator/Program.cs index fd1df36475..631cbcf230 100644 --- a/tools/IntegrationsJsonGenerator/Program.cs +++ b/tools/IntegrationsJsonGenerator/Program.cs @@ -192,7 +192,7 @@ void UpdateNativeInstrumentationFile(string filePath, Dictionary "); writer.Write(bytecodeIntegration.Key.ToLowerInvariant()); writer.Write("_integration_names = {"); - writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_DISABLED\")}}"))); + writer.Write(string.Join(", ", bytecodeIntegration.Value.Select(name => $"{{WStr(\"{name}\"), WStr(\"OTEL_DOTNET_AUTO_{bytecodeIntegration.Key.ToUpperInvariant()}S_{name}_INSTRUMENTATION_ENABLED\")}}"))); writer.WriteLine("};"); } From aea539c6d22f5eec8be2d3e7b92b332828f4d128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 1 Feb 2023 19:12:07 +0100 Subject: [PATCH 29/30] PR feedback- make comment consistent --- .../Configurations/ConfigurationKeys.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs index ac6380ca29..f42066e470 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs @@ -194,7 +194,7 @@ public static class Logs public const string IncludeFormattedMessage = "OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE"; /// - /// Configuration key for enabling all log instrumentations. + /// Configuration key for disabling all log instrumentations. /// public const string LogsInstrumentationEnabled = "OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED"; From f3e12be38248f4c8be11aa5a734fdbd35796fc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 1 Feb 2023 20:07:09 +0100 Subject: [PATCH 30/30] fix default value --- .../environment_variables_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h index 2208e28c53..5549b036cc 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/environment_variables_util.h @@ -79,7 +79,7 @@ bool IsNetFxAssemblyRedirectionEnabled() { } bool AreInstrumentationsEnabledByDefault() { - ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), false); + ToBooleanWithDefault(GetEnvironmentValue(environment::instrumentation_enabled), true); } bool AreTracesInstrumentationsEnabledByDefault(const bool enabled_if_not_configured) { @@ -96,4 +96,4 @@ bool AreLogsInstrumentationsEnabledByDefault(const bool enabled_if_not_configure } // namespace trace -#endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_ \ No newline at end of file +#endif // OTEL_CLR_PROFILER_ENVIRONMENT_VARIABLES_UTIL_H_