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

Bump MongoDB.Driver.Core.Extensions.DiagnosticSources from 1.1.0 to 1.2.0 in /src/OpenTelemetry.AutoInstrumentation.AdditionalDeps #1320

Merged
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Replaced `OTEL_DOTNET_AUTO_TRACES_PLUGINS` and `OTEL_DOTNET_AUTO_METRICS_PLUGINS`
with new environment variable `OTEL_DOTNET_AUTO_PLUGINS`.
- Adjusted tags for MongoDB integration. See [pull request](https://github.com/jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources/pull/18)
for more details.

### Removed

- Removed support for MongoDB integration for [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core)
older than 2.13.3.
Kielek marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
136 changes: 103 additions & 33 deletions build/nuke/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using Extensions;
using Nuke.Common;
Expand Down Expand Up @@ -350,40 +351,109 @@ partial class Build
}
});

Target CopyAdditionalDeps => _ => _
.Unlisted()
.Description("Creates AutoInstrumentation.AdditionalDeps and shared store in tracer-home")
.After(CompileManagedSrc)
.Executes(() =>
{
AdditionalDepsDirectory.GlobFiles("**/*deps.json").ForEach(DeleteFile);
Target CopyAdditionalDeps => _ =>
{
return _
.Unlisted()
.Description("Creates AutoInstrumentation.AdditionalDeps and shared store in tracer-home")
.After(CompileManagedSrc)
.Executes(() =>
{
AdditionalDepsDirectory.GlobFiles("**/*deps.json").ForEach(DeleteFile);

DotNetPublish(s => s
.SetProject(Solution.GetProject(Projects.AutoInstrumentationAdditionalDeps))
.SetConfiguration(BuildConfiguration)
.SetTargetPlatformAnyCPU()
.SetProperty("TracerHomePath", TracerHomeDirectory)
.EnableNoBuild()
.EnableNoRestore()
.CombineWith(TestFrameworks.ExceptNetFramework(), (p, framework) => p
.SetFramework(framework)
// Additional-deps probes the directory using SemVer format.
// Example: For netcoreapp3.1 framework, additional-deps uses 3.1.0 or 3.1.1 and so on.
// Major and Minor version are extracted from framework and default value of 0 is appended for patch.
.SetOutput(AdditionalDepsDirectory / "shared" / "Microsoft.NETCore.App" / framework.ToString().Substring(framework.ToString().Length - 3) + ".0")));

AdditionalDepsDirectory.GlobFiles("**/*.dll", "**/*.pdb", "**/*.xml").ForEach(DeleteFile);
AdditionalDepsDirectory.GlobFiles("**/*deps.json")
.ForEach(file =>
{
string depsJsonContent = File.ReadAllText(file);
// Remove OpenTelemetry.Instrumentation.AutoInstrumentationAdditionalDeps entry from target section.
depsJsonContent = Regex.Replace(depsJsonContent, "\"OpenTelemetry(.+)AutoInstrumentation.AdditionalDeps.dll(.+?)}," + Environment.NewLine + "(.+?)\"", "\"", RegexOptions.IgnoreCase | RegexOptions.Singleline);
// Remove OpenTelemetry.Instrumentation.AutoInstrumentationAdditionalDeps entry from library section and write to file.
depsJsonContent = Regex.Replace(depsJsonContent, "\"OpenTelemetry(.+?)}," + Environment.NewLine + "(.+?)\"", "\"", RegexOptions.IgnoreCase | RegexOptions.Singleline);
File.WriteAllText(file, depsJsonContent);
});
});
DotNetPublish(s => s
.SetProject(Solution.GetProject(Projects.AutoInstrumentationAdditionalDeps))
.SetConfiguration(BuildConfiguration)
.SetTargetPlatformAnyCPU()
.SetProperty("TracerHomePath", TracerHomeDirectory)
.EnableNoBuild()
.EnableNoRestore()
.CombineWith(TestFrameworks.ExceptNetFramework(), (p, framework) => p
.SetFramework(framework)
// Additional-deps probes the directory using SemVer format.
// Example: For netcoreapp3.1 framework, additional-deps uses 3.1.0 or 3.1.1 and so on.
// Major and Minor version are extracted from framework and default value of 0 is appended for patch.
.SetOutput(AdditionalDepsDirectory / "shared" / "Microsoft.NETCore.App" / framework.ToString().Substring(framework.ToString().Length - 3) + ".0")));


AdditionalDepsDirectory.GlobFiles("**/*deps.json")
.ForEach(file =>
{
var depsJsonContent = File.ReadAllText(file);
CopyNativeDependenciesToStore(file, depsJsonContent);

RemoveOpenTelemetryAutoInstrumentationAdditionalDepsFromDepsFile(depsJsonContent, file);
});
RemoveFilesFromAdditionalDepsDirectory();

void CopyNativeDependenciesToStore(AbsolutePath file, string depsJsonContent)
{
var depsDirectory = file.Parent;
var targetDirectory = Path.Combine(depsDirectory.Parent.Parent.Parent.Parent, "store");
using var jsonDocument = JsonDocument.Parse(depsJsonContent);

var runtimeName = jsonDocument.RootElement.GetProperty("runtimeTarget").GetProperty("name").GetString();
var folderRuntimeName = runtimeName switch
{
".NETCoreApp,Version=v3.1" => "netcoreapp3.1",
".NETCoreApp,Version=v6.0" => "net6.0",
_ => throw new ArgumentOutOfRangeException(nameof(runtimeName), runtimeName,
"This value is not supported. You have probably introduced new .NET version to AutoInstrumentation")
};

foreach (var targetProperty in jsonDocument.RootElement.GetProperty("targets").EnumerateObject())
{
var target = targetProperty.Value;

foreach (var packages in target.EnumerateObject())
{
if (!packages.Value.TryGetProperty("runtimeTargets", out var runtimeTargets))
{
continue;
}

foreach (var runtimeDependency in runtimeTargets.EnumerateObject())
{
var sourceFileName = Path.Combine(depsDirectory, runtimeDependency.Name);


Kielek marked this conversation as resolved.
Show resolved Hide resolved
var targetFileNameX64 = Path.Combine(targetDirectory, "x64", folderRuntimeName,
packages.Name.ToLowerInvariant(), runtimeDependency.Name);
var targetFileNameX86 = Path.Combine(targetDirectory, "x86", folderRuntimeName,
packages.Name.ToLowerInvariant(), runtimeDependency.Name);

var targetDirectoryX64 = Path.GetDirectoryName(targetFileNameX64);
var targetDirectoryX86 = Path.GetDirectoryName(targetFileNameX86);

Directory.CreateDirectory(targetDirectoryX64);
Directory.CreateDirectory(targetDirectoryX86);

File.Copy(sourceFileName, targetFileNameX64);
File.Copy(sourceFileName, targetFileNameX86);
}
}
}
}

void RemoveOpenTelemetryAutoInstrumentationAdditionalDepsFromDepsFile(string depsJsonContent, AbsolutePath file)
{
// Remove OpenTelemetry.Instrumentation.AutoInstrumentationAdditionalDeps entry from target section.
depsJsonContent = Regex.Replace(depsJsonContent,
"\"OpenTelemetry(.+)AutoInstrumentation.AdditionalDeps.dll(.+?)}," + Environment.NewLine + "(.+?)\"", "\"",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
// Remove OpenTelemetry.Instrumentation.AutoInstrumentationAdditionalDeps entry from library section and write to file.
depsJsonContent = Regex.Replace(depsJsonContent, "\"OpenTelemetry(.+?)}," + Environment.NewLine + "(.+?)\"", "\"",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
File.WriteAllText(file, depsJsonContent);
}

void RemoveFilesFromAdditionalDepsDirectory()
{
AdditionalDepsDirectory.GlobFiles("**/*.dll", "**/*.pdb", "**/*.xml", "**/*.dylib", "**/*.so").ForEach(DeleteFile);
AdditionalDepsDirectory.GlobDirectories("**/runtimes").ForEach(DeleteDirectory);
}
});
};

Target InstallDocumentationTools => _ => _
.Description("Installs markdownlint-cli and cspell locally. npm is required")
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for more details.
| `GraphQL` | [GraphQL](https://www.nuget.org/packages/GraphQL/) | ≥2.3.0 & < 3.0.0 | bytecode |
| `GrpcNetClient` | [Grpc.Net.Client](https://www.nuget.org/packages/Grpc.Net.Client) | ≥2.43.0 & < 3.0.0 | source |
| `HttpClient` | [System.Net.Http.HttpClient](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) and [System.Net.HttpWebRequest](https://docs.microsoft.com/dotnet/api/system.net.httpwebrequest) | * | source |
| `MongoDB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.3.0 & < 3.0.0 | source & bytecode |
| `MongoDB` | [MongoDB.Driver.Core](https://www.nuget.org/packages/MongoDB.Driver.Core) **Not supported on .NET Framework** | ≥2.13.3 & < 3.0.0 | source & bytecode |
| `MySqlData` | [MySql.Data](https://www.nuget.org/packages/MySql.Data) **Not supported on .NET Framework** | ≥6.10.7 | source |
| `Npgsql` | [Npgsql](https://www.nuget.org/packages/Npgsql) | ≥6.0.0 | source |
| `SqlClient` | [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) and [System.Data.SqlClient](https://www.nuget.org/packages/System.Data.SqlClient) | * | source |
Expand Down
4 changes: 2 additions & 2 deletions integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"MongoDB.Driver.MongoClientSettings"
],
"minimum_major": 2,
"minimum_minor": 3,
"minimum_patch": 0,
"minimum_minor": 13,
"minimum_patch": 3,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.1.0" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.2.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB;
MethodName = ".ctor",
ReturnTypeName = ClrNames.Void,
ParameterTypeNames = new[] { "MongoDB.Driver.MongoClientSettings" },
MinimumVersion = "2.3.0",
MinimumVersion = "2.13.3",
MaximumVersion = "2.65535.65535",
IntegrationName = "MongoDB")]
public class MongoClientIntegration
Expand Down
Loading