Skip to content

Commit

Permalink
Fix MongoDB instrumentation for 2.29.0+ (open-telemetry#3668)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Sep 27, 2024
1 parent 9c42941 commit baf1f78
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,30 @@ private static string ResolveManagedProfilerDirectory()
return null;
}

Logger.Debug("Requester [{0}] requested [{1}]", args?.RequestingAssembly?.FullName ?? "<null>", args?.Name ?? "<null>");
Logger.Debug("Requester [{0}] requested [{1}]", args.RequestingAssembly?.FullName ?? "<null>", args.Name ?? "<null>");

// All MongoDB* are signed and does not follow https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/versioning#assembly-version
// There is no possibility to automatically redirect from 2.28.0 to 2.29.0.
// Loading assembly and ignoring this version.
if (assemblyName.StartsWith("MongoDB", StringComparison.OrdinalIgnoreCase) &&
(string.Equals(assemblyName, "MongoDB.Driver.Core", StringComparison.OrdinalIgnoreCase) ||
string.Equals(assemblyName, "MongoDB.Bson", StringComparison.OrdinalIgnoreCase) ||
string.Equals(assemblyName, "MongoDB.Libmongocrypt", StringComparison.OrdinalIgnoreCase)))
{
try
{
var mongoAssembly = Assembly.Load(assemblyName);
Logger.Debug<string, bool>("Assembly.Load(\"{0}\") succeeded={1}", assemblyName, mongoAssembly != null);
return mongoAssembly;
}
catch (Exception ex)
{
Logger.Debug(ex, "Assembly.Load(\"{0}\") Exception: {1}", assemblyName, ex.Message);
}

return null;
}

var path = Path.Combine(ManagedProfilerDirectory, $"{assemblyName}.dll");
if (File.Exists(path))
{
Expand Down

0 comments on commit baf1f78

Please sign in to comment.