3
3
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4
4
// </copyright>
5
5
6
+ using System ;
6
7
using Datadog . Trace . Ci . Configuration ;
7
8
using Datadog . Trace . Configuration ;
8
9
using Datadog . Trace . Configuration . Telemetry ;
@@ -14,6 +15,8 @@ namespace Datadog.Trace.Tests.Configuration
14
15
{
15
16
public class CIVisibilitySettingsTests : SettingsTestsBase
16
17
{
18
+ private static readonly string ExpectedExcludedSession = "/session/FakeSessionIdForPollingPurposes" . ToUpperInvariant ( ) ;
19
+
17
20
[ Theory ]
18
21
[ MemberData ( nameof ( BooleanTestCases ) , null ) ]
19
22
public void Enabled ( string value , bool ? expected )
@@ -185,5 +188,107 @@ public void ForceAgentsEvpProxy(string value, string expected)
185
188
186
189
settings . ForceAgentsEvpProxy . Should ( ) . Be ( expected ) ;
187
190
}
191
+
192
+ [ Theory ]
193
+ [ InlineData ( "some-service" , "true" ) ]
194
+ [ InlineData ( null , "false" ) ]
195
+ public void AddsUserProvidedTestServiceTagToGlobalTags ( string serviceName , string expectedTag )
196
+ {
197
+ var source = CreateConfigurationSource ( ( ConfigurationKeys . ServiceName , serviceName ) ) ;
198
+
199
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
200
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
201
+
202
+ tracerSettings . GlobalTags . Should ( )
203
+ . ContainKey ( Datadog . Trace . Ci . Tags . CommonTags . UserProvidedTestServiceTag )
204
+ . WhoseValue . Should ( )
205
+ . Be ( expectedTag ) ;
206
+ }
207
+
208
+ [ Fact ]
209
+ public void ServiceNameIsNormalized ( )
210
+ {
211
+ var originalName = "My Service Name!" ;
212
+ var normalizedName = "my_service_name" ;
213
+
214
+ var source = CreateConfigurationSource ( ( ConfigurationKeys . ServiceName , originalName ) ) ;
215
+
216
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
217
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
218
+
219
+ tracerSettings . ServiceName . Should ( ) . Be ( normalizedName ) ;
220
+ }
221
+
222
+ [ Fact ]
223
+ public void AddsFakeSessionToExcludedHttpClientUrls ( )
224
+ {
225
+ var source = CreateConfigurationSource ( ) ;
226
+
227
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
228
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
229
+
230
+ tracerSettings . HttpClientExcludedUrlSubstrings
231
+ . Should ( )
232
+ . Contain ( ExpectedExcludedSession ) ;
233
+ }
234
+
235
+ [ Fact ]
236
+ public void AddsFakeSessionToExcludedHttpClientUrls_WhenUrlsAlreadyExist ( )
237
+ {
238
+ var source = CreateConfigurationSource (
239
+ ( ConfigurationKeys . HttpClientExcludedUrlSubstrings , "/some-url/path" ) ) ;
240
+
241
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
242
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
243
+
244
+ tracerSettings . HttpClientExcludedUrlSubstrings
245
+ . Should ( )
246
+ . Contain ( ExpectedExcludedSession ) ;
247
+ }
248
+
249
+ [ Fact ]
250
+ public void AddsFakeSessionToExcludedHttpClientUrls_WhenRunningInAas ( )
251
+ {
252
+ var source = CreateConfigurationSource (
253
+ ( ConfigurationKeys . AzureAppService . AzureAppServicesContextKey , "true" ) ,
254
+ ( ConfigurationKeys . HttpClientExcludedUrlSubstrings , "/some-url/path" ) ) ;
255
+
256
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
257
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
258
+
259
+ tracerSettings . HttpClientExcludedUrlSubstrings
260
+ . Should ( )
261
+ . Contain ( ExpectedExcludedSession ) ;
262
+ }
263
+
264
+ [ Fact ]
265
+ public void WhenLogsEnabled_AddsDirectSubmission ( )
266
+ {
267
+ var source = CreateConfigurationSource (
268
+ ( ConfigurationKeys . CIVisibility . Logs , "true" ) ) ;
269
+
270
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
271
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
272
+
273
+ tracerSettings . LogSubmissionSettings
274
+ . EnabledIntegrationNames
275
+ . Should ( )
276
+ . Contain ( nameof ( IntegrationId . XUnit ) ) ;
277
+ tracerSettings . LogSubmissionSettings . BatchPeriod . Should ( ) . Be ( TimeSpan . FromSeconds ( 1 ) ) ;
278
+ }
279
+
280
+ [ Fact ]
281
+ public void WhenLogsNotEnabled_DoesNotAddDirectSubmission ( )
282
+ {
283
+ var source = CreateConfigurationSource ( ) ;
284
+
285
+ var ciVisSettings = new CIVisibilitySettings ( source , NullConfigurationTelemetry . Instance ) ;
286
+ var tracerSettings = ciVisSettings . InitializeTracerSettings ( [ source ] ) ;
287
+
288
+ tracerSettings . LogSubmissionSettings
289
+ . EnabledIntegrationNames
290
+ . Should ( )
291
+ . NotContain ( nameof ( IntegrationId . XUnit ) ) ;
292
+ }
188
293
}
189
294
}
0 commit comments