Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/Npgsql-7.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Sep 18, 2023
2 parents 3c773a2 + 0731267 commit 19588d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
%*
Original file line number Diff line number Diff line change
Expand Up @@ -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

$@
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,17 @@ internal class RuleEngine
new MinSupportedFrameworkRule()
};

private readonly List<Rule> _otherRules = new()
{
new OpenTelemetrySdkMinimumVersionRule(),
new AssemblyFileVersionRule(),
new NativeProfilerDiagnosticsRule()
};
private readonly Lazy<List<Rule>> _optionalRules;

internal RuleEngine()
: this(new Lazy<List<Rule>>(CreateDefaultOptionalRules))
{
}

// This constructor is used for test purpose.
internal RuleEngine(List<Rule> rules)
internal RuleEngine(Lazy<List<Rule>> optionalRules)
{
_otherRules = rules;
_optionalRules = optionalRules;
}

internal bool ValidateRules()
Expand All @@ -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))
{
Expand Down Expand Up @@ -93,4 +89,14 @@ private static bool EvaluateRule(Rule rule)

return true;
}

private static List<Rule> CreateDefaultOptionalRules()
{
return new()
{
new OpenTelemetrySdkMinimumVersionRule(),
new AssemblyFileVersionRule(),
new NativeProfilerDiagnosticsRule()
};
}
}
2 changes: 1 addition & 1 deletion test/IntegrationTests/docker/mongodb.Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM mongo:5.0.20
FROM mongo:5.0.21
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void RuleEngineValidation_WhenShouldTrackIsTrue()
// Arrange
SetShouldTrackEnvironmentVariable(true);
var testRule = new TestRule();
var ruleEngine = new RuleEngine(new List<Rule> { testRule });
var ruleEngine = new RuleEngine(new Lazy<List<Rule>>(() => new() { testRule }));

// Act
var result = ruleEngine.ValidateRules();
Expand All @@ -48,7 +48,7 @@ public void RuleEngineValidation_WhenShouldTrackIsFalse()
// Arrange
SetShouldTrackEnvironmentVariable(false);
var testRule = new TestRule();
var ruleEngine = new RuleEngine(new List<Rule> { testRule });
var ruleEngine = new RuleEngine(new Lazy<List<Rule>>(() => new() { testRule }));

// Act
var result = ruleEngine.ValidateRules();
Expand All @@ -64,7 +64,7 @@ public void RuleEngineValidation_WhenShouldTrackIsNull()
// Arrange
SetShouldTrackEnvironmentVariable(null);
var testRule = new TestRule();
var ruleEngine = new RuleEngine(new List<Rule> { testRule });
var ruleEngine = new RuleEngine(new Lazy<List<Rule>>(() => new() { testRule }));

// Act
var result = ruleEngine.ValidateRules();
Expand All @@ -79,7 +79,7 @@ public void RuleEngineValidation_WhenShouldTrackIsNotSet()
{
// Arrange
var testRule = new TestRule();
var ruleEngine = new RuleEngine(new List<Rule> { testRule });
var ruleEngine = new RuleEngine(new Lazy<List<Rule>>(() => new() { testRule }));

// Act
var result = ruleEngine.ValidateRules();
Expand All @@ -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<Rule> { testRule });
var ruleEngine = new RuleEngine(new Lazy<List<Rule>>(() => new() { testRule }));

// Act
var result = ruleEngine.ValidateRules();
Expand Down

0 comments on commit 19588d6

Please sign in to comment.