11
11
12
12
namespace NewRelic . Agent . ContainerIntegrationTests . Tests . AwsSdk ;
13
13
14
- public class AwsSdkSQSTest : NewRelicIntegrationTest < AwsSdkContainerSQSTestFixture >
14
+ public abstract class AwsSdkSQSTestBase : NewRelicIntegrationTest < AwsSdkContainerSQSTestFixture >
15
15
{
16
16
private readonly AwsSdkContainerSQSTestFixture _fixture ;
17
17
18
18
private readonly string _testQueueName1 = $ "TestQueue1-{ Guid . NewGuid ( ) } ";
19
19
private readonly string _testQueueName2 = $ "TestQueue2-{ Guid . NewGuid ( ) } ";
20
+ private readonly string _testQueueName3 = $ "TestQueue3-{ Guid . NewGuid ( ) } ";
20
21
private readonly string _metricScope1 = "WebTransaction/MVC/AwsSdk/SQS_SendReceivePurge/{queueName}" ;
21
22
private readonly string _metricScope2 = "WebTransaction/MVC/AwsSdk/SQS_SendMessageToQueue/{message}/{messageQueueUrl}" ;
23
+ private bool _initCollections ;
22
24
23
- public AwsSdkSQSTest ( AwsSdkContainerSQSTestFixture fixture , ITestOutputHelper output ) : base ( fixture )
25
+ protected AwsSdkSQSTestBase ( AwsSdkContainerSQSTestFixture fixture , ITestOutputHelper output , bool initCollections ) : base ( fixture )
24
26
{
25
27
_fixture = fixture ;
26
28
_fixture . TestLogger = output ;
29
+ _initCollections = initCollections ;
30
+
31
+ _fixture . SetAdditionalEnvironmentVariable ( "AWSSDK_INITCOLLECTIONS" , initCollections . ToString ( ) ) ;
27
32
28
33
29
34
_fixture . Actions ( setupConfiguration : ( ) =>
@@ -44,6 +49,7 @@ public AwsSdkSQSTest(AwsSdkContainerSQSTestFixture fixture, ITestOutputHelper ou
44
49
45
50
_fixture . ExerciseSQS_SendReceivePurge ( _testQueueName1 ) ;
46
51
_fixture . ExerciseSQS_SendAndReceiveInSeparateTransactions ( _testQueueName2 ) ;
52
+ _fixture . ExerciseSQS_ReceiveEmptyMessage ( _testQueueName3 ) ;
47
53
48
54
_fixture . AgentLog . WaitForLogLine ( AgentLogBase . MetricDataLogLineRegex , TimeSpan . FromMinutes ( 2 ) ) ;
49
55
_fixture . AgentLog . WaitForLogLine ( AgentLogBase . TransactionTransformCompletedLogLineRegex , TimeSpan . FromMinutes ( 2 ) ) ;
@@ -60,6 +66,12 @@ public AwsSdkSQSTest(AwsSdkContainerSQSTestFixture fixture, ITestOutputHelper ou
60
66
[ Fact ]
61
67
public void Test ( )
62
68
{
69
+ // Making sure there are no application errors or wrapper exceptions
70
+ // See https://github.com/newrelic/newrelic-dotnet-agent/issues/2811
71
+
72
+ Assert . Equal ( 0 , _fixture . AgentLog . GetWrapperExceptionLineCount ( ) ) ;
73
+ Assert . Equal ( 0 , _fixture . AgentLog . GetApplicationErrorLineCount ( ) ) ;
74
+
63
75
var metrics = _fixture . AgentLog . GetMetrics ( ) . ToList ( ) ;
64
76
65
77
var expectedMetrics = new List < Assertions . ExpectedMetric >
@@ -76,9 +88,18 @@ public void Test()
76
88
new ( ) { metricName = $ "MessageBroker/SQS/Queue/Consume/Named/{ _testQueueName2 } ", callCount = 1 } ,
77
89
new ( ) { metricName = $ "MessageBroker/SQS/Queue/Consume/Named/{ _testQueueName2 } ", callCount = 1 , metricScope = "OtherTransaction/Custom/AwsSdkTestApp.SQSBackgroundService.SQSReceiverService/ProcessRequestAsync" } ,
78
90
79
- new ( ) { metricName = "Supportability/TraceContext/Accept/Success" , callCount = 1 } , // only one accept should occur (from the SQSReceiverService/ProcessRequestAsync transaction)
91
+ // Only consume metrics for queue 3
92
+ new ( ) { metricName = $ "MessageBroker/SQS/Queue/Consume/Named/{ _testQueueName3 } ", callCount = 1 } ,
93
+ new ( ) { metricName = $ "MessageBroker/SQS/Queue/Consume/Named/{ _testQueueName3 } ", callCount = 1 , metricScope = "OtherTransaction/Custom/AwsSdkTestApp.SQSBackgroundService.SQSReceiverService/ProcessRequestAsync" } ,
94
+
80
95
} ;
81
96
97
+ // If the AWS SDK is configured to NOT initialize empty collections, trace headers will not be accepted
98
+ if ( _initCollections )
99
+ {
100
+ expectedMetrics . Add ( new ( ) { metricName = "Supportability/TraceContext/Accept/Success" , callCount = 1 } ) ;
101
+ }
102
+
82
103
var sendReceivePurgeTransactionEvent = _fixture . AgentLog . TryGetTransactionEvent ( _metricScope1 ) ;
83
104
var sendReceivePurgeTransactionSample = _fixture . AgentLog . TryGetTransactionSample ( _metricScope1 ) ;
84
105
var sendReceivePurgeExpectedTransactionTraceSegments = new List < string >
@@ -102,25 +123,34 @@ public void Test()
102
123
( ) => Assert . True ( receiveMessageTransactionEvent != null , "receiveMessageTransactionEvent should not be null" )
103
124
) ;
104
125
105
- // verify that distributed trace worked as expected -- the last produce span should have the same traceId and parentId as the last consume span
106
126
var queueProduce = $ "MessageBroker/SQS/Queue/Produce/Named/{ _testQueueName2 } ";
107
127
var queueConsume = $ "MessageBroker/SQS/Queue/Consume/Named/{ _testQueueName2 } ";
108
128
109
129
var spans = _fixture . AgentLog . GetSpanEvents ( ) . ToList ( ) ;
110
130
var produceSpan = spans . LastOrDefault ( s => s . IntrinsicAttributes [ "name" ] . Equals ( queueProduce ) ) ;
111
131
var consumeSpan = spans . LastOrDefault ( s => s . IntrinsicAttributes [ "name" ] . Equals ( queueConsume ) ) ;
112
- var processRequestSpan = spans . LastOrDefault ( s => s . IntrinsicAttributes [ "name" ] . Equals ( "OtherTransaction/Custom/AwsSdkTestApp.SQSBackgroundService.SQSReceiverService/ProcessRequestAsync" ) ) ;
113
132
114
133
NrAssert . Multiple (
115
134
( ) => Assert . True ( produceSpan != null , "produceSpan should not be null" ) ,
116
135
( ) => Assert . True ( consumeSpan != null , "consumeSpan should not be null" ) ,
117
- ( ) => Assert . True ( processRequestSpan != null , "processRequestSpan should not be null" ) ,
118
136
( ) => Assert . True ( produceSpan ! . IntrinsicAttributes . ContainsKey ( "traceId" ) ) ,
119
137
( ) => Assert . True ( produceSpan ! . IntrinsicAttributes . ContainsKey ( "guid" ) ) ,
120
- ( ) => Assert . True ( consumeSpan ! . IntrinsicAttributes . ContainsKey ( "traceId" ) ) ,
121
- ( ) => Assert . True ( processRequestSpan ! . IntrinsicAttributes . ContainsKey ( "parentId" ) ) ,
122
- ( ) => Assert . Equal ( produceSpan ! . IntrinsicAttributes [ "traceId" ] , consumeSpan ! . IntrinsicAttributes [ "traceId" ] ) ,
123
- ( ) => Assert . Equal ( produceSpan ! . IntrinsicAttributes [ "guid" ] , processRequestSpan ! . IntrinsicAttributes [ "parentId" ] ) ,
138
+ ( ) => Assert . True ( consumeSpan ! . IntrinsicAttributes . ContainsKey ( "traceId" ) )
139
+ ) ;
140
+
141
+ if ( _initCollections )
142
+ {
143
+ // verify that distributed trace worked as expected -- the last produce span should have the same traceId and parentId as the last consume span
144
+ var processRequestSpan = spans . LastOrDefault ( s => s . IntrinsicAttributes [ "name" ] . Equals ( "OtherTransaction/Custom/AwsSdkTestApp.SQSBackgroundService.SQSReceiverService/ProcessRequestAsync" ) && s . IntrinsicAttributes . ContainsKey ( "parentId" ) ) ;
145
+
146
+ NrAssert . Multiple (
147
+ ( ) => Assert . True ( processRequestSpan != null , "processRequestSpan should not be null" ) ,
148
+ ( ) => Assert . Equal ( produceSpan ! . IntrinsicAttributes [ "traceId" ] , consumeSpan ! . IntrinsicAttributes [ "traceId" ] ) ,
149
+ ( ) => Assert . Equal ( produceSpan ! . IntrinsicAttributes [ "guid" ] , processRequestSpan ! . IntrinsicAttributes [ "parentId" ] )
150
+ ) ;
151
+ }
152
+
153
+ NrAssert . Multiple (
124
154
// entity relationship attributes
125
155
( ) => Assert . Equal ( produceSpan ! . AgentAttributes [ "messaging.system" ] , "aws_sqs" ) ,
126
156
( ) => Assert . Equal ( produceSpan ! . AgentAttributes [ "messaging.destination.name" ] , _testQueueName2 ) ,
@@ -133,3 +163,17 @@ public void Test()
133
163
) ;
134
164
}
135
165
}
166
+
167
+ public class AwsSdkSQSTestInitializedCollections : AwsSdkSQSTestBase
168
+ {
169
+ public AwsSdkSQSTestInitializedCollections ( AwsSdkContainerSQSTestFixture fixture , ITestOutputHelper output ) : base ( fixture , output , true )
170
+ {
171
+ }
172
+ }
173
+ public class AwsSdkSQSTestNullCollections : AwsSdkSQSTestBase
174
+ {
175
+ public AwsSdkSQSTestNullCollections ( AwsSdkContainerSQSTestFixture fixture , ITestOutputHelper output ) : base ( fixture , output , false )
176
+ {
177
+ }
178
+ }
179
+
0 commit comments