Skip to content

Commit 2e9e4cf

Browse files
committed
Simplify ShouldIGnoreBeOperationName because it's ~15 times faster
| Method | Mean | Error | StdDev | Allocated | |----------------- |----------:|----------:|----------:|----------:| | ArrayBasedUpdate | 30.029 us | 0.1795 us | 0.1402 us | - | | PairBasedUpdate | 2.815 us | 0.0232 us | 0.0206 us | - |
1 parent 434e9f4 commit 2e9e4cf

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

tracer/src/Datadog.Trace/Activity/Handlers/ActivityHandlerCommon.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
157157
}
158158

159159
// We check if we have to ignore the activity by the operation name value
160-
if (IgnoreActivityHandler.ShouldIgnoreByOperationName(activity))
160+
if (IgnoreActivityHandler.ShouldIgnoreByOperationName(activity.OperationName))
161161
{
162162
IgnoreActivityHandler.IgnoreActivity(activity, Tracer.Instance.ActiveScope?.Span as Span);
163163
activityMapping = default;
@@ -216,7 +216,7 @@ public static void ActivityStopped<T>(string sourceName, T activity)
216216
{
217217
if (activity.Instance is not null)
218218
{
219-
if (IgnoreActivityHandler.ShouldIgnoreByOperationName(activity))
219+
if (IgnoreActivityHandler.ShouldIgnoreByOperationName(activity.OperationName))
220220
{
221221
return;
222222
}

tracer/src/Datadog.Trace/Activity/Handlers/IgnoreActivityHandler.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#nullable enable
77

8+
using System;
89
using Datadog.Trace.Activity.DuckTypes;
910
using Datadog.Trace.Util;
1011

@@ -30,24 +31,13 @@ internal sealed class IgnoreActivityHandler : IActivityHandler
3031
"Experimental.System.Net.Sockets",
3132
};
3233

33-
private static readonly string[] IgnoreOperationNamesStartingWith =
34+
public static bool ShouldIgnoreByOperationName(string? operationName)
3435
{
35-
"System.Net.Http.",
36-
"Microsoft.AspNetCore.",
37-
};
38-
39-
public static bool ShouldIgnoreByOperationName<T>(T activity)
40-
where T : IActivity
41-
{
42-
foreach (var ignoreSourceName in IgnoreOperationNamesStartingWith)
43-
{
44-
if (activity.OperationName?.StartsWith(ignoreSourceName) == true)
45-
{
46-
return true;
47-
}
48-
}
49-
50-
return false;
36+
// We only have two ignored operation names for now, if we get more, we can be more
37+
// generalized, but this is called twice in hot path creation
38+
return operationName is not null
39+
&& (operationName.StartsWith("System.Net.Http.", StringComparison.Ordinal)
40+
|| operationName.StartsWith("Microsoft.AspNetCore.", StringComparison.Ordinal));
5141
}
5242

5343
public static void IgnoreActivity<T>(T activity, Span? span)

0 commit comments

Comments
 (0)