Skip to content

Commit 8648c43

Browse files
committed
Fixed tests and remove unnecessary test methods.
1 parent fdc0f46 commit 8648c43

4 files changed

Lines changed: 13 additions & 56 deletions

File tree

src/Agent/NewRelic/Agent/Core/OpenTelemetryBridge/Tracing/ActivityBridge.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ public void Dispose()
6262
_activityListener = null;
6363
}
6464

65-
/// <summary>
66-
/// FOR TESTING ONLY: Resets the static Activity infrastructure state that was set by this class.
67-
/// This should be called in test TearDown to ensure clean state between tests.
68-
/// </summary>
69-
public static void ResetStaticState()
70-
{
71-
// Reset the TraceIdGenerator to null (default behavior)
72-
var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == "System.Diagnostics.DiagnosticSource");
73-
if (assembly != null)
74-
{
75-
var activityType = assembly.GetType("System.Diagnostics.Activity", throwOnError: false);
76-
if (activityType != null)
77-
{
78-
var traceIdGeneratorPropertyInfo = activityType.GetProperty("TraceIdGenerator", BindingFlags.Public | BindingFlags.Static);
79-
traceIdGeneratorPropertyInfo?.SetValue(null, null);
80-
}
81-
}
82-
83-
// Reset the static setter
84-
_activityTraceFlagsSetter = null;
85-
}
86-
8765
// Only .net 5 and newer libraries and applications will use the W3C id format by default.
8866
// We need to set the default id format to W3C to ensure that the activities we create are created
8967
// with the expected format.
@@ -412,16 +390,6 @@ private bool ShouldListenToActivitySource(object activitySource)
412390
return false;
413391
}
414392

415-
// Don't listen to the agent's own activity source to prevent recursion.
416-
// When traditional agent instrumentation creates segments, they may create activities via
417-
// NewRelicActivitySourceProxy. We must not listen to these to avoid infinite recursion
418-
// where ActivityStarted tries to create a segment, which creates another activity.
419-
if (activitySourceName == NewRelicActivitySourceProxy.ActivitySourceName)
420-
{
421-
Log.Finest($"ShouldListenToActivitySource: Not listening to agent's own activity source '{activitySourceName}'.");
422-
return false;
423-
}
424-
425393
return ActivitySourceExtensions.ShouldListenToActivitySource(activitySourceName, _agent.Configuration);
426394
}
427395

src/Agent/NewRelic/Agent/Core/OpenTelemetryBridge/Tracing/ActivityBridgeSegmentHelpers.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ public static void ProcessActivityTags(this ISegment segment, object originalAct
4242
return;
4343
}
4444

45-
//TESTING
46-
foreach (var tag in tags)
47-
{
48-
Log.Finest($"{activityLogPrefix} has tag: {tag.Key} = {tag.Value}");
49-
}
50-
5145
// based on activity kind, create the appropriate segment data
5246
// remove all tags that are used in segment data creation
5347
switch (activityKind)
@@ -157,7 +151,7 @@ private static void ProcessRpcClientTags(ISegment segment, IAgent agent, IErrorS
157151
tags.TryGetAndRemoveTag<string>(["rpc.method"], out var method);
158152
tags.TryGetAndRemoveTag<string>(["rpc.service"], out var service); // deprecated attribute, rpc.method includes this information in the format /service/method, but some instrumentation may still use this tag so we'll look for it as a fallback
159153
tags.TryGetAndRemoveTag<string>(["grpc.method"], out var grpcMethod);
160-
var cleanGrpcMethod = grpcMethod.TrimStart('/'); // per spec, we need to strip leading slashes.
154+
var cleanGrpcMethod = grpcMethod?.TrimStart('/'); // per spec, we need to strip leading slashes.
161155

162156
tags.TryGetAndRemoveTag<string>(["server.address", "network.peer.address"], out var host);
163157
tags.TryGetAndRemoveTag<int?>(["server.port", "network.peer.port"], out var port);

tests/Agent/UnitTests/CompositeTests/HybridAgent/Helpers/HybridAgentTestsBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace CompositeTests.HybridAgent.Helpers;
1717

1818
public abstract class HybridAgentTestsBase
1919
{
20-
private CompositeTestAgent _compositeTestAgent;
20+
private static CompositeTestAgent _compositeTestAgent;
2121
private IAgent _agent;
2222
private NewRelicAgentOperations _newRelicAgentOperations;
2323
private ActivityBridge _activityBridge;
@@ -63,11 +63,6 @@ public virtual void TearDown()
6363
_newRelicAgentOperations = null;
6464
_activityBridge.Dispose();
6565
_compositeTestAgent.Dispose();
66-
67-
// Reset static state to ensure clean slate for next test
68-
ActivityBridge.ResetStaticState();
69-
NewRelicActivitySourceProxy.ResetStaticState();
70-
ActivityBridgeHelpers.Reset();
7166
}
7267

7368
public abstract void Tests(HybridAgentTestCase test);

tests/Agent/UnitTests/CompositeTests/HybridAgent/TestCaseDefinitions/HybridAgentTests.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,15 +1967,15 @@
19671967
],
19681968
"spans": [
19691969
{
1970-
"name": "External/localhost/Stream/GetItem",
1970+
"name": "External/localhost/gRPC/GetItem",
19711971
"parentName": "Foo",
19721972
"category": "http",
19731973
"attributes": {
19741974
"span.kind": "client",
19751975
"server.address": "localhost",
19761976
"server.port": 50051,
1977-
"http.request.method": "GetItem",
1978-
"http.statusCode": 0,
1977+
"http.method": "GetItem",
1978+
"grpc.statusCode": 0,
19791979
"http.url": "grpc://localhost:50051/my.test.Service/GetItem",
19801980
"component": "grpc"
19811981
}
@@ -2061,15 +2061,15 @@
20612061
],
20622062
"spans": [
20632063
{
2064-
"name": "External/localhost/Stream/GetItem",
2064+
"name": "External/localhost/gRPC/GetItem",
20652065
"parentName": "Foo",
20662066
"category": "http",
20672067
"attributes": {
20682068
"span.kind": "client",
20692069
"server.address": "localhost",
20702070
"server.port": 50051,
2071-
"http.request.method": "GetItem",
2072-
"http.statusCode": 14,
2071+
"http.method": "GetItem",
2072+
"grpc.statusCode": 14,
20732073
"http.url": "grpc://localhost:50051/my.test.Service/GetItem",
20742074
"component": "grpc"
20752075
}
@@ -2142,14 +2142,14 @@
21422142
],
21432143
"spans": [
21442144
{
2145-
"name": "External/localhost/Stream/ListItems",
2145+
"name": "External/localhost/gRPC/ListItems",
21462146
"parentName": "Foo",
21472147
"category": "http",
21482148
"attributes": {
21492149
"span.kind": "client",
21502150
"server.address": "localhost",
21512151
"server.port": 50052,
2152-
"http.request.method": "ListItems",
2152+
"http.method": "ListItems",
21532153
"http.url": "grpc://localhost:50052/my.test.Service/ListItems",
21542154
"component": "grpc"
21552155
}
@@ -2230,15 +2230,15 @@
22302230
],
22312231
"spans": [
22322232
{
2233-
"name": "External/grpc.example.com/Stream/UnaryCall",
2233+
"name": "External/grpc.example.com/gRPC/UnaryCall",
22342234
"parentName": "Foo",
22352235
"category": "http",
22362236
"attributes": {
22372237
"span.kind": "client",
22382238
"server.address": "grpc.example.com",
22392239
"server.port": 6000,
2240-
"http.request.method": "UnaryCall",
2241-
"http.statusCode": 0,
2240+
"http.method": "UnaryCall",
2241+
"grpc.statusCode": 0,
22422242
"http.url": "grpc://grpc.example.com:6000/pkg.alt.Service/UnaryCall",
22432243
"component": "grpc"
22442244
}

0 commit comments

Comments
 (0)