Skip to content

Commit 400ea44

Browse files
committed
Make TracerSettings dependency explicit
1 parent 75937f5 commit 400ea44

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AdoNet/DbScopeFactory.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static bool HasDbType(Span span, string dbType)
138138
}
139139

140140
public static bool TryGetIntegrationDetails(
141+
HashSet<string> disabledAdoNetCommandTypes,
141142
string? commandTypeFullName,
142143
[NotNullWhen(true)] out IntegrationId? integrationId,
143144
[NotNullWhen(true)] out string? dbType)
@@ -172,7 +173,7 @@ public static bool TryGetIntegrationDetails(
172173
return true;
173174
default:
174175
string commandTypeName = commandTypeFullName.Substring(commandTypeFullName.LastIndexOf(".", StringComparison.Ordinal) + 1);
175-
if (IsDisabledCommandType(commandTypeName))
176+
if (IsDisabledCommandType(commandTypeName, disabledAdoNetCommandTypes))
176177
{
177178
integrationId = null;
178179
dbType = null;
@@ -200,14 +201,14 @@ _ when commandTypeName.EndsWith(commandSuffix) =>
200201
}
201202
}
202203

203-
internal static bool IsDisabledCommandType(string commandTypeName)
204+
internal static bool IsDisabledCommandType(string commandTypeName, HashSet<string> disabledAdoNetCommandTypes)
204205
{
205206
if (string.IsNullOrEmpty(commandTypeName))
206207
{
207208
return false;
208209
}
209210

210-
var disabledTypes = Tracer.Instance.Settings.DisabledAdoNetCommandTypes;
211+
var disabledTypes = disabledAdoNetCommandTypes;
211212

212213
if (disabledTypes is null || disabledTypes.Count == 0)
213214
{
@@ -245,7 +246,7 @@ static Cache()
245246
{
246247
CommandType = typeof(TCommand);
247248

248-
if (TryGetIntegrationDetails(CommandType.FullName, out var integrationId, out var dbTypeName))
249+
if (TryGetIntegrationDetails(Tracer.Instance.Settings.DisabledAdoNetCommandTypes, CommandType.FullName, out var integrationId, out var dbTypeName))
249250
{
250251
// cache values for this TCommand type
251252
DbTypeName = dbTypeName;
@@ -275,7 +276,7 @@ static Cache()
275276

276277
// if command.GetType() != typeof(TCommand), we are probably instrumenting a method
277278
// defined in a base class like DbCommand and we can't use the cached values
278-
if (TryGetIntegrationDetails(commandType.FullName, out var integrationId, out var dbTypeName))
279+
if (TryGetIntegrationDetails(tracer.Settings.DisabledAdoNetCommandTypes, commandType.FullName, out var integrationId, out var dbTypeName))
279280
{
280281
var operationName = $"{dbTypeName}.query";
281282
var tagsFromConnectionString = GetTagsFromConnectionString(command);

tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/DbScopeFactoryTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ internal void TryGetIntegrationDetails_CorrectNameGenerated(Type commandType, st
689689
var command = (IDbCommand)Activator.CreateInstance(commandType)!;
690690
command.CommandText = DbmCommandText;
691691

692-
bool result = DbScopeFactory.TryGetIntegrationDetails(command.GetType().FullName, out var actualIntegrationId, out var actualDbType);
692+
bool result = DbScopeFactory.TryGetIntegrationDetails([], command.GetType().FullName, out var actualIntegrationId, out var actualDbType);
693693
Assert.True(result);
694694
Assert.Equal(expectedIntegrationName, actualIntegrationId.ToString());
695695
Assert.Equal(expectedDbType, actualDbType);
@@ -698,12 +698,12 @@ internal void TryGetIntegrationDetails_CorrectNameGenerated(Type commandType, st
698698
[Fact]
699699
internal void TryGetIntegrationDetails_FailsForKnownCommandType()
700700
{
701-
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
701+
bool result = DbScopeFactory.TryGetIntegrationDetails([], "InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
702702
Assert.False(result);
703703
Assert.False(actualIntegrationId.HasValue);
704704
Assert.Null(actualDbType);
705705

706-
bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
706+
bool result2 = DbScopeFactory.TryGetIntegrationDetails([], "ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
707707
Assert.False(result2);
708708
Assert.False(actualIntegrationId2.HasValue);
709709
Assert.Null(actualDbType2);
@@ -712,18 +712,18 @@ internal void TryGetIntegrationDetails_FailsForKnownCommandType()
712712
[Fact]
713713
internal void TryGetIntegrationDetails_FailsForKnownCommandTypes_AndUserDefined()
714714
{
715-
Tracer.Configure(TracerSettings.Create(new Dictionary<string, object> { { ConfigurationKeys.DisabledAdoNetCommandTypes, "SomeFakeDbCommand" } }));
716-
bool result = DbScopeFactory.TryGetIntegrationDetails("InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
715+
HashSet<string> disabledCommandTypes = ["SomeFakeDbCommand"];
716+
bool result = DbScopeFactory.TryGetIntegrationDetails(disabledCommandTypes, "InterceptableDbCommand", out var actualIntegrationId, out var actualDbType);
717717
Assert.False(result);
718718
Assert.False(actualIntegrationId.HasValue);
719719
Assert.Null(actualDbType);
720720

721-
bool result2 = DbScopeFactory.TryGetIntegrationDetails("ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
721+
bool result2 = DbScopeFactory.TryGetIntegrationDetails(disabledCommandTypes, "ProfiledDbCommand", out var actualIntegrationId2, out var actualDbType2);
722722
Assert.False(result2);
723723
Assert.False(actualIntegrationId2.HasValue);
724724
Assert.Null(actualDbType2);
725725

726-
bool result3 = DbScopeFactory.TryGetIntegrationDetails("SomeFakeDbCommand", out var actualIntegrationId3, out var actualDbType3);
726+
bool result3 = DbScopeFactory.TryGetIntegrationDetails(disabledCommandTypes, "SomeFakeDbCommand", out var actualIntegrationId3, out var actualDbType3);
727727
Assert.False(result3);
728728
Assert.False(actualIntegrationId3.HasValue);
729729
Assert.Null(actualDbType3);
@@ -740,7 +740,7 @@ internal void TryGetIntegrationDetails_FailsForKnownCommandTypes_AndUserDefined(
740740
[InlineData("Custom.DB.Command", "AdoNet", "db")]
741741
internal void TryGetIntegrationDetails_CustomCommandType(string commandTypeFullName, string integrationId, string expectedDbType)
742742
{
743-
DbScopeFactory.TryGetIntegrationDetails(commandTypeFullName, out var actualIntegrationId, out var actualDbType);
743+
DbScopeFactory.TryGetIntegrationDetails([], commandTypeFullName, out var actualIntegrationId, out var actualDbType);
744744
Assert.Equal(integrationId, actualIntegrationId?.ToString());
745745
Assert.Equal(expectedDbType, actualDbType);
746746
}

0 commit comments

Comments
 (0)