|
10 | 10 | using System.Diagnostics.CodeAnalysis;
|
11 | 11 | using System.Linq;
|
12 | 12 | using System.Text.RegularExpressions;
|
| 13 | +using Datadog.Trace.Ci; |
| 14 | +using Datadog.Trace.Ci.CiEnvironment; |
13 | 15 | using Datadog.Trace.ClrProfiler;
|
14 | 16 | using Datadog.Trace.ClrProfiler.ServerlessInstrumentation;
|
15 | 17 | using Datadog.Trace.Configuration.ConfigurationSources.Telemetry;
|
16 | 18 | using Datadog.Trace.Configuration.Telemetry;
|
17 | 19 | using Datadog.Trace.Logging;
|
18 | 20 | using Datadog.Trace.Logging.DirectSubmission;
|
| 21 | +using Datadog.Trace.Processors; |
19 | 22 | using Datadog.Trace.Propagators;
|
20 | 23 | using Datadog.Trace.Sampling;
|
21 | 24 | using Datadog.Trace.SourceGenerators;
|
@@ -87,6 +90,11 @@ internal TracerSettings(IConfigurationSource? source, IConfigurationTelemetry te
|
87 | 90 | GCPFunctionSettings = new ImmutableGCPFunctionSettings(source, _telemetry);
|
88 | 91 | IsRunningInGCPFunctions = GCPFunctionSettings.IsGCPFunction;
|
89 | 92 |
|
| 93 | + // We don't want/need to record this value, so explicitly use null telemetry |
| 94 | + var isRunningInCiVisibility = new ConfigurationBuilder(source, NullConfigurationTelemetry.Instance) |
| 95 | + .WithKeys(ConfigurationKeys.CIVisibility.IsRunningInCiVisMode) |
| 96 | + .AsBool(false); |
| 97 | + |
90 | 98 | LambdaMetadata = LambdaMetadata.Create();
|
91 | 99 |
|
92 | 100 | IsRunningInAzureAppService = ImmutableAzureAppServiceSettings.GetIsAzureAppService(source, telemetry);
|
@@ -124,11 +132,34 @@ _ when x.ToBoolean() is { } boolean => boolean,
|
124 | 132 | .AsString();
|
125 | 133 |
|
126 | 134 | var otelServiceName = config.WithKeys(ConfigurationKeys.OpenTelemetry.ServiceName).AsStringResult();
|
127 |
| - ServiceName = config |
| 135 | + var serviceName = config |
128 | 136 | .WithKeys(ConfigurationKeys.ServiceName, "DD_SERVICE_NAME")
|
129 | 137 | .AsStringResult()
|
130 | 138 | .OverrideWith(in otelServiceName, ErrorLog);
|
131 | 139 |
|
| 140 | + var isUserProvidedTestServiceTag = true; |
| 141 | + if (isRunningInCiVisibility) |
| 142 | + { |
| 143 | + // Set the service name if not set |
| 144 | + var ciVisServiceName = serviceName; |
| 145 | + if (string.IsNullOrEmpty(serviceName)) |
| 146 | + { |
| 147 | + // Extract repository name from the git url and use it as a default service name. |
| 148 | + ciVisServiceName = CIVisibility.GetServiceNameFromRepository(CIEnvironmentValues.Instance.Repository); |
| 149 | + isUserProvidedTestServiceTag = false; |
| 150 | + } |
| 151 | + |
| 152 | + // Normalize the service name |
| 153 | + ciVisServiceName = NormalizerTraceProcessor.NormalizeService(ciVisServiceName); |
| 154 | + if (ciVisServiceName != serviceName) |
| 155 | + { |
| 156 | + serviceName = ciVisServiceName; |
| 157 | + telemetry.Record(ConfigurationKeys.ServiceName, serviceName, recordValue: true, ConfigurationOrigins.Calculated); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + ServiceName = serviceName; |
| 162 | + |
132 | 163 | ServiceVersion = config
|
133 | 164 | .WithKeys(ConfigurationKeys.ServiceVersion)
|
134 | 165 | .AsString();
|
@@ -204,6 +235,11 @@ _ when x.ToBoolean() is { } boolean => boolean,
|
204 | 235 | .Where(kvp => !string.IsNullOrWhiteSpace(kvp.Key) && !string.IsNullOrWhiteSpace(kvp.Value))
|
205 | 236 | .ToDictionary(kvp => kvp.Key.Trim(), kvp => kvp.Value.Trim());
|
206 | 237 |
|
| 238 | + if (isRunningInCiVisibility) |
| 239 | + { |
| 240 | + GlobalTags[Ci.Tags.CommonTags.UserProvidedTestServiceTag] = isUserProvidedTestServiceTag ? "true" : "false"; |
| 241 | + } |
| 242 | + |
207 | 243 | var headerTagsNormalizationFixEnabled = config
|
208 | 244 | .WithKeys(ConfigurationKeys.FeatureFlags.HeaderTagsNormalizationFixEnabled)
|
209 | 245 | .AsBool(defaultValue: true);
|
@@ -481,9 +517,19 @@ _ when x.ToBoolean() is { } boolean => boolean,
|
481 | 517 | IsRunningInAzureAppService ? ImmutableAzureAppServiceSettings.DefaultHttpClientExclusions :
|
482 | 518 | LambdaMetadata is { IsRunningInLambda: true } m ? m.DefaultHttpClientExclusions : string.Empty);
|
483 | 519 |
|
| 520 | + if (isRunningInCiVisibility) |
| 521 | + { |
| 522 | + // always add the additional exclude in ci vis |
| 523 | + const string fakeSessionEndpoint = "/session/FakeSessionIdForPollingPurposes"; |
| 524 | + urlSubstringSkips = string.IsNullOrEmpty(urlSubstringSkips) |
| 525 | + ? fakeSessionEndpoint |
| 526 | + : $"{urlSubstringSkips},{fakeSessionEndpoint}"; |
| 527 | + telemetry.Record(ConfigurationKeys.HttpClientExcludedUrlSubstrings, urlSubstringSkips, recordValue: true, ConfigurationOrigins.Calculated); |
| 528 | + } |
| 529 | + |
484 | 530 | HttpClientExcludedUrlSubstrings = !string.IsNullOrEmpty(urlSubstringSkips)
|
485 | 531 | ? TrimSplitString(urlSubstringSkips.ToUpperInvariant(), commaSeparator)
|
486 |
| - : Array.Empty<string>(); |
| 532 | + : []; |
487 | 533 |
|
488 | 534 | DbmPropagationMode = config
|
489 | 535 | .WithKeys(ConfigurationKeys.DbmPropagationMode)
|
|
0 commit comments