Skip to content

Commit

Permalink
Revert "Don't use the static Tracer.Instance"
Browse files Browse the repository at this point in the history
This reverts commit d34f2d0.
  • Loading branch information
bouwkast committed Sep 18, 2024
1 parent d34f2d0 commit 846624f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ static bool HasDbType(Span span, string dbType)

public static bool TryGetIntegrationDetails(
string? commandTypeFullName,
Tracer? tracer,
[NotNullWhen(true)] out IntegrationId? integrationId,
[NotNullWhen(true)] out string? dbType)
{
Expand Down Expand Up @@ -171,7 +170,7 @@ public static bool TryGetIntegrationDetails(
return true;
default:
string commandTypeName = commandTypeFullName.Substring(commandTypeFullName.LastIndexOf(".", StringComparison.Ordinal) + 1);
if (IsDisabledCommandType(commandTypeName, tracer))
if (IsDisabledCommandType(commandTypeName))
{
integrationId = null;
dbType = null;
Expand Down Expand Up @@ -199,19 +198,14 @@ _ when commandTypeName.EndsWith(commandSuffix) =>
}
}

internal static bool IsDisabledCommandType(string commandTypeName, Tracer? tracer)
internal static bool IsDisabledCommandType(string commandTypeName)
{
if (tracer is null)
{
return false;
}

if (string.IsNullOrEmpty(commandTypeName))
{
return false;
}

var disabledTypes = tracer.Settings.DisabledAdoNetCommandTypes;
var disabledTypes = Tracer.Instance.Settings.DisabledAdoNetCommandTypes;

if (disabledTypes is null || disabledTypes.Count == 0)
{
Expand Down Expand Up @@ -249,7 +243,7 @@ static Cache()
{
CommandType = typeof(TCommand);

if (TryGetIntegrationDetails(CommandType.FullName, tracer: Tracer.Instance, out var integrationId, out var dbTypeName))
if (TryGetIntegrationDetails(CommandType.FullName, out var integrationId, out var dbTypeName))
{
// cache values for this TCommand type
DbTypeName = dbTypeName;
Expand Down Expand Up @@ -279,7 +273,7 @@ static Cache()

// if command.GetType() != typeof(TCommand), we are probably instrumenting a method
// defined in a base class like DbCommand and we can't use the cached values
if (TryGetIntegrationDetails(commandType.FullName, tracer, out var integrationId, out var dbTypeName))
if (TryGetIntegrationDetails(commandType.FullName, out var integrationId, out var dbTypeName))
{
var operationName = $"{dbTypeName}.query";
var tagsFromConnectionString = GetTagsFromConnectionString(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal void TryGetIntegrationDetails_CorrectNameGenerated(Type commandType, st
var command = (IDbCommand)Activator.CreateInstance(commandType)!;
command.CommandText = DbmCommandText;

bool result = DbScopeFactory.TryGetIntegrationDetails(command.GetType().FullName, tracer: Tracer.Instance, out var actualIntegrationId, out var actualDbType);
bool result = DbScopeFactory.TryGetIntegrationDetails(command.GetType().FullName, out var actualIntegrationId, out var actualDbType);
Assert.True(result);
Assert.Equal(expectedIntegrationName, actualIntegrationId.ToString());
Assert.Equal(expectedDbType, actualDbType);
Expand All @@ -262,12 +262,12 @@ internal void TryGetIntegrationDetails_CorrectNameGenerated(Type commandType, st
[Fact]
internal void TryGetIntegrationDetails_FailsForKnownCommandType()
{
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", tracer: Tracer.Instance, out var actualIntegrationId, out var actualDbType);
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
Assert.False(result);
Assert.False(actualIntegrationId.HasValue);
Assert.Null(actualDbType);

bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", tracer: Tracer.Instance, out var actualIntegrationId2, out var actualDbType2);
bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
Assert.False(result2);
Assert.False(actualIntegrationId2.HasValue);
Assert.Null(actualDbType2);
Expand All @@ -277,17 +277,17 @@ internal void TryGetIntegrationDetails_FailsForKnownCommandType()
internal void TryGetIntegrationDetails_FailsForKnownCommandTypes_AndUserDefined()
{
Tracer.Configure(TracerSettings.Create(new Dictionary<string, object> { { ConfigurationKeys.DisabledAdoNetCommandTypes, "SomeFakeDbCommand" } }));
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", tracer: Tracer.Instance, out var actualIntegrationId, out var actualDbType);
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
Assert.False(result);
Assert.False(actualIntegrationId.HasValue);
Assert.Null(actualDbType);

bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", tracer: Tracer.Instance, out var actualIntegrationId2, out var actualDbType2);
bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
Assert.False(result2);
Assert.False(actualIntegrationId2.HasValue);
Assert.Null(actualDbType2);

bool result3 = DbScopeFactory.TryGetIntegrationDetails("SomeFakeDbCommand", tracer: Tracer.Instance, out var actualIntegrationId3, out var actualDbType3);
bool result3 = DbScopeFactory.TryGetIntegrationDetails("SomeFakeDbCommand", out var actualIntegrationId3, out var actualDbType3);
Assert.False(result3);
Assert.False(actualIntegrationId3.HasValue);
Assert.Null(actualDbType3);
Expand All @@ -304,7 +304,7 @@ internal void TryGetIntegrationDetails_FailsForKnownCommandTypes_AndUserDefined(
[InlineData("Custom.DB.Command", "AdoNet", "db")]
internal void TryGetIntegrationDetails_CustomCommandType(string commandTypeFullName, string integrationId, string expectedDbType)
{
DbScopeFactory.TryGetIntegrationDetails(commandTypeFullName, tracer: Tracer.Instance, out var actualIntegrationId, out var actualDbType);
DbScopeFactory.TryGetIntegrationDetails(commandTypeFullName, out var actualIntegrationId, out var actualDbType);
Assert.Equal(integrationId, actualIntegrationId?.ToString());
Assert.Equal(expectedDbType, actualDbType);
}
Expand Down

0 comments on commit 846624f

Please sign in to comment.