Skip to content

Commit

Permalink
Small changes to improve stability (#3693)
Browse files Browse the repository at this point in the history
* Small changes to improve stability.

* Changes from Review
  • Loading branch information
tonyredondo authored Jan 23, 2023
1 parent 94ae486 commit 6daab3a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
32 changes: 23 additions & 9 deletions tracer/src/Datadog.Trace.Coverage.collector/AssemblyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,25 +694,27 @@ public CustomResolver(ICollectorLogger logger, string assemblyFilePath)
_defaultResolver = new DefaultAssemblyResolver();
}

public override AssemblyDefinition Resolve(AssemblyNameReference name)
public override AssemblyDefinition? Resolve(AssemblyNameReference name)
{
AssemblyDefinition assembly;
AssemblyDefinition? assembly = null;
try
{
assembly = _defaultResolver.Resolve(name);
}
catch (AssemblyResolutionException ex)
catch (AssemblyResolutionException arEx)
{
var tracerAssemblyName = TracerAssembly.GetName();
if (name.Name == tracerAssemblyName.Name && name.Version == tracerAssemblyName.Version)
{
if (!string.IsNullOrEmpty(_tracerAssemblyLocation))
var cAssemblyLocation = !string.IsNullOrEmpty(_tracerAssemblyLocation) ? _tracerAssemblyLocation : TracerAssembly.Location;
try
{
assembly = AssemblyDefinition.ReadAssembly(_tracerAssemblyLocation);
assembly = AssemblyDefinition.ReadAssembly(cAssemblyLocation);
}
else
catch (Exception innerAssemblyException)
{
assembly = AssemblyDefinition.ReadAssembly(TracerAssembly.Location);
_logger.Error(innerAssemblyException, $"Error reading the tracer assembly: {cAssemblyLocation}");
throw;
}
}
else
Expand All @@ -722,13 +724,25 @@ public override AssemblyDefinition Resolve(AssemblyNameReference name)
_logger.Debug($"Looking for: {pathTest}");
if (File.Exists(pathTest))
{
return AssemblyDefinition.ReadAssembly(pathTest);
try
{
return AssemblyDefinition.ReadAssembly(pathTest);
}
catch (Exception innerAssemblyException)
{
_logger.Error(innerAssemblyException, $"Error reading the assembly: {pathTest}");
throw;
}
}

_logger.Error(ex, $"Error in the Custom Resolver processing '{_assemblyFilePath}' for: {name.FullName}");
_logger.Error(arEx, $"Error in the Custom Resolver processing '{_assemblyFilePath}' for: {name.FullName}");
throw;
}
}
catch (Exception ex)
{
_logger.Error(ex, $"Error in the custom resolver when trying to resolve assembly: {name.FullName}");
}

return assembly;
}
Expand Down
15 changes: 14 additions & 1 deletion tracer/src/Datadog.Trace/Util/DbCommandCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ internal static ConcurrentDictionary<string, TagsCacheItem> Cache

public static TagsCacheItem GetTagsFromDbCommand(IDbCommand command)
{
var connectionString = command.Connection?.ConnectionString;
IDbConnection dbConnection = null;
try
{
dbConnection = command.Connection;
}
catch (NotSupportedException nsException)
{
Log.Debug(nsException, "Connection cannot be retrieved from the command.");
}
catch (Exception ex)
{
Log.Debug(ex, "Error trying to retrieve the connection from the command.");
}

var connectionString = dbConnection?.ConnectionString;
if (connectionString is null)
{
return default;
Expand Down

0 comments on commit 6daab3a

Please sign in to comment.