diff --git a/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.cmd b/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.cmd index 75e86d323a..9cf290bae2 100644 --- a/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.cmd +++ b/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.cmd @@ -25,6 +25,7 @@ set DOTNET_STARTUP_HOOKS=%BASE_PATH%OpenTelemetry.AutoInstrumentation.StartupHoo :: Settings for OpenTelemetry set OTEL_DOTNET_AUTO_HOME=%BASE_PATH% +set OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED=false @echo on %* diff --git a/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.sh b/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.sh index 132f1d009d..0d766c904d 100755 --- a/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.sh +++ b/nuget/OpenTelemetry.AutoInstrumentation/contentFiles/any/any/instrument.sh @@ -11,5 +11,6 @@ export DOTNET_STARTUP_HOOKS=${BASE_PATH}/OpenTelemetry.AutoInstrumentation.Start # Settings for OpenTelemetry export OTEL_DOTNET_AUTO_HOME=${BASE_PATH} +export OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED=false $@ diff --git a/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs b/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs index b4da092982..91da865c5c 100644 --- a/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs +++ b/src/OpenTelemetry.AutoInstrumentation.StartupHook/RulesEngine/RuleEngine.cs @@ -28,21 +28,17 @@ internal class RuleEngine new MinSupportedFrameworkRule() }; - private readonly List _otherRules = new() - { - new OpenTelemetrySdkMinimumVersionRule(), - new AssemblyFileVersionRule(), - new NativeProfilerDiagnosticsRule() - }; + private readonly Lazy> _optionalRules; internal RuleEngine() + : this(new Lazy>(CreateDefaultOptionalRules)) { } // This constructor is used for test purpose. - internal RuleEngine(List rules) + internal RuleEngine(Lazy> optionalRules) { - _otherRules = rules; + _optionalRules = optionalRules; } internal bool ValidateRules() @@ -65,7 +61,7 @@ internal bool ValidateRules() } // All the rules are validated here. - foreach (var rule in _otherRules) + foreach (var rule in _optionalRules.Value) { if (!EvaluateRule(rule)) { @@ -93,4 +89,14 @@ private static bool EvaluateRule(Rule rule) return true; } + + private static List CreateDefaultOptionalRules() + { + return new() + { + new OpenTelemetrySdkMinimumVersionRule(), + new AssemblyFileVersionRule(), + new NativeProfilerDiagnosticsRule() + }; + } } diff --git a/test/IntegrationTests/docker/mongodb.Dockerfile b/test/IntegrationTests/docker/mongodb.Dockerfile index 8b122196aa..0ba61916a1 100644 --- a/test/IntegrationTests/docker/mongodb.Dockerfile +++ b/test/IntegrationTests/docker/mongodb.Dockerfile @@ -1 +1 @@ -FROM mongo:5.0.20 \ No newline at end of file +FROM mongo:5.0.21 \ No newline at end of file diff --git a/test/OpenTelemetry.AutoInstrumentation.StartupHook.Tests/RuleEngineTests.cs b/test/OpenTelemetry.AutoInstrumentation.StartupHook.Tests/RuleEngineTests.cs index 5e5acf8abd..ab206f223f 100644 --- a/test/OpenTelemetry.AutoInstrumentation.StartupHook.Tests/RuleEngineTests.cs +++ b/test/OpenTelemetry.AutoInstrumentation.StartupHook.Tests/RuleEngineTests.cs @@ -32,7 +32,7 @@ public void RuleEngineValidation_WhenShouldTrackIsTrue() // Arrange SetShouldTrackEnvironmentVariable(true); var testRule = new TestRule(); - var ruleEngine = new RuleEngine(new List { testRule }); + var ruleEngine = new RuleEngine(new Lazy>(() => new() { testRule })); // Act var result = ruleEngine.ValidateRules(); @@ -48,7 +48,7 @@ public void RuleEngineValidation_WhenShouldTrackIsFalse() // Arrange SetShouldTrackEnvironmentVariable(false); var testRule = new TestRule(); - var ruleEngine = new RuleEngine(new List { testRule }); + var ruleEngine = new RuleEngine(new Lazy>(() => new() { testRule })); // Act var result = ruleEngine.ValidateRules(); @@ -64,7 +64,7 @@ public void RuleEngineValidation_WhenShouldTrackIsNull() // Arrange SetShouldTrackEnvironmentVariable(null); var testRule = new TestRule(); - var ruleEngine = new RuleEngine(new List { testRule }); + var ruleEngine = new RuleEngine(new Lazy>(() => new() { testRule })); // Act var result = ruleEngine.ValidateRules(); @@ -79,7 +79,7 @@ public void RuleEngineValidation_WhenShouldTrackIsNotSet() { // Arrange var testRule = new TestRule(); - var ruleEngine = new RuleEngine(new List { testRule }); + var ruleEngine = new RuleEngine(new Lazy>(() => new() { testRule })); // Act var result = ruleEngine.ValidateRules(); @@ -95,7 +95,7 @@ public void RuleEngineValidation_WhenShouldTrackHasInvalidValue() // Arrange Environment.SetEnvironmentVariable("OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED", "Invalid"); var testRule = new TestRule(); - var ruleEngine = new RuleEngine(new List { testRule }); + var ruleEngine = new RuleEngine(new Lazy>(() => new() { testRule })); // Act var result = ruleEngine.ValidateRules();