Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S.D.DS version rule on .NET 7.0 #2960

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

### Fixed

- Fixed Rule checking System.Diagnostics.DiagnosticSource version for net7.0
failing on correct configuration [#2950](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/2950).

### Security

## [1.0.0](https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/tag/v1.0.0)
Expand Down
13 changes: 8 additions & 5 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,18 +558,17 @@ DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>
.Executes(() =>
{
var netPath = TracerHomeDirectory / "net";
var ruleEngineJsonFilePath = netPath / "ruleEngine.json";
var ruleEngineJsonNugetFilePath = RootDirectory / "nuget" / "OpenTelemetry.AutoInstrumentation" / "contentFiles" / "any" / "any" / "RuleEngine.json";
var fileInfoList = new List<object>();
var files = Directory.GetFiles(netPath);
var fileInfoList = new List<object>(files.Length);

foreach (string file in files)
{
var fileName = Path.GetFileNameWithoutExtension(file);
var fileVersion = FileVersionInfo.GetVersionInfo(file).FileVersion;

if (fileName.StartsWith("OpenTelemetry.") && !fileName.StartsWith("OpenTelemetry.Api") && !fileName.StartsWith("OpenTelemetry.AutoInstrumentation"))
if (fileName == "System.Diagnostics.DiagnosticSource" ||
(fileName.StartsWith("OpenTelemetry.") && !fileName.StartsWith("OpenTelemetry.Api") && !fileName.StartsWith("OpenTelemetry.AutoInstrumentation")))
{
var fileVersion = FileVersionInfo.GetVersionInfo(file).FileVersion;
fileInfoList.Add(new
{
FileName = fileName,
Expand All @@ -580,7 +579,11 @@ DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>

JsonSerializerOptions options = new JsonSerializerOptions { WriteIndented = true };
string jsonContent = JsonSerializer.Serialize(fileInfoList, options);

var ruleEngineJsonFilePath = netPath / "ruleEngine.json";
File.WriteAllText(ruleEngineJsonFilePath, jsonContent);

var ruleEngineJsonNugetFilePath = RootDirectory / "nuget" / "OpenTelemetry.AutoInstrumentation" / "contentFiles" / "any" / "any" / "RuleEngine.json";
File.Delete(ruleEngineJsonNugetFilePath);
File.Copy(ruleEngineJsonFilePath, ruleEngineJsonNugetFilePath);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="InstrumentationAssemblyRule.cs" company="OpenTelemetry Authors">
// <copyright file="AssemblyFileVersionRule.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,14 +21,14 @@

namespace OpenTelemetry.AutoInstrumentation.RulesEngine;

internal class InstrumentationAssemblyRule : Rule
internal class AssemblyFileVersionRule : Rule
{
private static readonly IOtelLogger Logger = OtelLogging.GetLogger("StartupHook");

public InstrumentationAssemblyRule()
public AssemblyFileVersionRule()
{
Name = "Instrumentation Assembly Validator";
Description = "Ensure that the version of the OpenTelemetry Instrumentation libraries is not older than the version used by Automatic Instrumentation.";
Name = "Assembly File Version Validator";
Description = "Ensure that the version of key assemblies is not older than the version used by Automatic Instrumentation.";
}

internal override bool Evaluate()
Expand Down Expand Up @@ -63,19 +63,19 @@ internal override bool Evaluate()
if (appInstrumentationFileVersion < autoInstrumentationFileVersion)
{
result = false;
Logger.Error($"Rule Engine: Application has direct or indirect reference to older version of Instrumentation library {ruleFileInfo.FileName} - {ruleFileInfo.FileVersion}.");
Logger.Error($"Rule Engine: Application has direct or indirect reference to older version of assembly {ruleFileInfo.FileName} - {ruleFileInfo.FileVersion}.");
}
else
{
Logger.Information($"Rule Engine: Application has reference to Instrumentation library {ruleFileInfo.FileName} and loaded successfully.");
Logger.Information($"Rule Engine: Application has reference to assembly {ruleFileInfo.FileName} and loaded successfully.");
}
}
}
}
catch (Exception ex)
{
// Exception in rule evaluation should not impact the result of the rule.
Logger.Warning($"Rule Engine:Couldn't evaluate OpenTelemetry Instrumentation Evaluation. Exception: {ex}");
Logger.Warning($"Rule Engine: Couldn't evaluate assembly reference file version. Exception: {ex}");
}

return result;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal class RuleEngine
private readonly List<Rule> _otherRules = new()
{
new OpenTelemetrySdkMinimumVersionRule(),
new DiagnosticSourceRule(),
new InstrumentationAssemblyRule(),
new AssemblyFileVersionRule(),
new NativeProfilerDiagnosticsRule()
};

Expand Down

This file was deleted.

Loading