diff --git a/tracer/src/Datadog.Trace.Coverage.collector/CoverageCollector.cs b/tracer/src/Datadog.Trace.Coverage.collector/CoverageCollector.cs index 7c307339b042..211aa230a83f 100644 --- a/tracer/src/Datadog.Trace.Coverage.collector/CoverageCollector.cs +++ b/tracer/src/Datadog.Trace.Coverage.collector/CoverageCollector.cs @@ -305,7 +305,7 @@ private void ProcessFolder(string folder, SearchOption searchOption) // Is not part of the spec but useful for support tickets. // We try to extract session variables (from out of process sessions) // and try to send a message to the IPC server for setting the test.code_coverage.injected tag. - var extractedContext = SpanContextPropagator.Instance.Extract( + var extractedContext = TracerManager.Instance.SpanContextPropagator.Extract( EnvironmentHelpers.GetEnvironmentVariables(), new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); diff --git a/tracer/src/Datadog.Trace.Tools.Runner/ConfigureCiCommand.cs b/tracer/src/Datadog.Trace.Tools.Runner/ConfigureCiCommand.cs index ffe32315a7c2..daf1d8c4191a 100644 --- a/tracer/src/Datadog.Trace.Tools.Runner/ConfigureCiCommand.cs +++ b/tracer/src/Datadog.Trace.Tools.Runner/ConfigureCiCommand.cs @@ -71,6 +71,8 @@ private async Task ExecuteAsync(InvocationContext context) return; } + await initResults.UploadRepositoryChangesTask().ConfigureAwait(false); + if (!TryExtractCiName(name, out var ciName)) { context.ExitCode = 1; diff --git a/tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityReporter.cs b/tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityReporter.cs index 61454f4c22c0..446890bed3c0 100644 --- a/tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityReporter.cs +++ b/tracer/src/Datadog.Trace/AppSec/Coordinator/SecurityReporter.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -98,7 +98,7 @@ internal void AddResponseHeadersToSpanAndCleanup() _httpTransport.DisposeAdditiveContext(); } - private static void AddHeaderTags(Span span, IHeadersCollection headers, Dictionary headersToCollect, string prefix) => SpanContextPropagator.Instance.AddHeadersToSpanAsTags(span, headers, headersToCollect, defaultTagPrefix: prefix); + private static void AddHeaderTags(Span span, IHeadersCollection headers, Dictionary headersToCollect, string prefix) => TracerManager.Instance.SpanContextPropagator.AddHeadersToSpanAsTags(span, headers, headersToCollect, defaultTagPrefix: prefix); private static void LogMatchesIfDebugEnabled(IReadOnlyCollection? results, bool blocked) { diff --git a/tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs b/tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs index f40827cf4f0d..dbf65ae8c94a 100644 --- a/tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs +++ b/tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs @@ -140,7 +140,7 @@ private void OnBeginRequest(object sender, EventArgs eventArgs) { // extract propagated http headers headers = requestHeaders.Wrap(); - extractedContext = SpanContextPropagator.Instance.Extract(headers.Value).MergeBaggageInto(Baggage.Current); + extractedContext = tracer.TracerManager.SpanContextPropagator.Extract(headers.Value).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { @@ -158,7 +158,7 @@ private void OnBeginRequest(object sender, EventArgs eventArgs) scope.Span.DecorateWebServerSpan(resourceName: null, httpMethod, host, url, userAgent, tags); if (headers is not null) { - SpanContextPropagator.Instance.AddHeadersToSpanAsTags(scope.Span, headers.Value, tracer.Settings.HeaderTags, defaultTagPrefix: SpanContextPropagator.HttpRequestHeadersTagPrefix); + tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(scope.Span, headers.Value, tracer.Settings.HeaderTags, defaultTagPrefix: SpanContextPropagator.HttpRequestHeadersTagPrefix); } if (tracer.Settings.IpHeaderEnabled || Security.Instance.AppsecEnabled) @@ -174,7 +174,7 @@ private void OnBeginRequest(object sender, EventArgs eventArgs) if (HttpRuntime.UsingIntegratedPipeline) { var injectedContext = new PropagationContext(scope.Span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(injectedContext, requestHeaders.Wrap()); + tracer.TracerManager.SpanContextPropagator.Inject(injectedContext, requestHeaders.Wrap()); } httpContext.Items[_httpContextScopeKey] = scope; diff --git a/tracer/src/Datadog.Trace/Ci/TestModule.cs b/tracer/src/Datadog.Trace/Ci/TestModule.cs index 3548119ba96f..d22e7cd7338f 100644 --- a/tracer/src/Datadog.Trace/Ci/TestModule.cs +++ b/tracer/src/Datadog.Trace/Ci/TestModule.cs @@ -130,7 +130,7 @@ internal TestModule(string name, string? framework, string? frameworkVersion, Da // Extract session variables (from out of process sessions) var environmentVariables = EnvironmentHelpers.GetEnvironmentVariables(); - var context = SpanContextPropagator.Instance.Extract( + var context = TracerManager.Instance.SpanContextPropagator.Extract( environmentVariables, new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); if (context.SpanContext is { } sessionContext) diff --git a/tracer/src/Datadog.Trace/Ci/TestSession.cs b/tracer/src/Datadog.Trace/Ci/TestSession.cs index 46b4ef907ea2..3174ad19d0cb 100644 --- a/tracer/src/Datadog.Trace/Ci/TestSession.cs +++ b/tracer/src/Datadog.Trace/Ci/TestSession.cs @@ -548,7 +548,7 @@ private void OnIpcMessageReceived(object message) [TestSuiteVisibilityTags.TestSessionWorkingDirectoryEnvironmentVariable] = tags.WorkingDirectory, }; - SpanContextPropagator.Instance.Inject( + TracerManager.Instance.SpanContextPropagator.Inject( new PropagationContext(span.Context, Baggage.Current), (IDictionary)environmentVariables, new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/EventBridge/ContextPropagation.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/EventBridge/ContextPropagation.cs index 82878fb00952..5fa71a7e0b62 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/EventBridge/ContextPropagation.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/EventBridge/ContextPropagation.cs @@ -83,7 +83,7 @@ private static string BuildContextJson(PropagationContext context, string? event var jsonBuilder = Util.StringBuilderCache.Acquire(); jsonBuilder.Append('{'); - SpanContextPropagator.Instance.Inject(context, jsonBuilder, new StringBuilderCarrierSetter()); + TracerManager.Instance.SpanContextPropagator.Inject(context, jsonBuilder, new StringBuilderCarrierSetter()); // Inject start time and bus name var startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Kinesis/ContextPropagation.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Kinesis/ContextPropagation.cs index 708d81eebc7c..0da87e2f99c1 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Kinesis/ContextPropagation.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Kinesis/ContextPropagation.cs @@ -69,7 +69,7 @@ public static void InjectTraceIntoData(TRecordRequest record, Sc try { - SpanContextPropagator.Instance.Inject(context, propagatedContext, default(DictionaryGetterAndSetter)); + TracerManager.Instance.SpanContextPropagator.Inject(context, propagatedContext, default(DictionaryGetterAndSetter)); jsonData[KinesisKey] = propagatedContext; var memoryStreamData = DictionaryToMemoryStream(jsonData); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs index 0c246f7627cd..03998c8cb8d7 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Lambda/LambdaCommon.cs @@ -25,7 +25,7 @@ internal abstract class LambdaCommon internal static Scope CreatePlaceholderScope(Tracer tracer, NameValueHeadersCollection headers) { - var context = SpanContextPropagator.Instance.Extract(headers).MergeBaggageInto(Baggage.Current); + var context = tracer.TracerManager.SpanContextPropagator.Extract(headers).MergeBaggageInto(Baggage.Current); var span = tracer.StartSpan( PlaceholderOperationName, diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Shared/ContextPropagation.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Shared/ContextPropagation.cs index 95991c0a17a2..80d185bbc82e 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Shared/ContextPropagation.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/Shared/ContextPropagation.cs @@ -22,7 +22,7 @@ private static void Inject(PropagationContext context, IDictionary messageAttrib // Consolidate headers into one JSON object with : var sb = Util.StringBuilderCache.Acquire(); sb.Append('{'); - SpanContextPropagator.Instance.Inject(context, sb, default(StringBuilderCarrierSetter)); + TracerManager.Instance.SpanContextPropagator.Inject(context, sb, default(StringBuilderCarrierSetter)); if (context.SpanContext?.PathwayContext is { } pathwayContext) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetMvcIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetMvcIntegration.cs index 51b7910bbed5..a4e7f98da39a 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetMvcIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetMvcIntegration.cs @@ -137,7 +137,7 @@ internal static Scope CreateScope(ControllerContextStruct controllerContext) { // extract propagated http headers headers = httpContext.Request.Headers.Wrap(); - extractedContext = SpanContextPropagator.Instance.Extract(headers.Value).MergeBaggageInto(Baggage.Current); + extractedContext = tracer.TracerManager.SpanContextPropagator.Extract(headers.Value).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { @@ -164,7 +164,7 @@ internal static Scope CreateScope(ControllerContextStruct controllerContext) if (headers is not null) { - SpanContextPropagator.Instance.AddHeadersToSpanAsTags(span, headers.Value, tracer.Settings.HeaderTags, SpanContextPropagator.HttpRequestHeadersTagPrefix); + tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(span, headers.Value, tracer.Settings.HeaderTags, SpanContextPropagator.HttpRequestHeadersTagPrefix); } if (tracer.Settings.IpHeaderEnabled || Security.Instance.AppsecEnabled) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetWebApi2Integration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetWebApi2Integration.cs index 4c4810829f45..e3e0858737d1 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetWebApi2Integration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetWebApi2Integration.cs @@ -58,7 +58,7 @@ internal static Scope CreateScope(IHttpControllerContext controllerContext, out { // extract propagated http headers headersCollection = new HttpHeadersCollection(request.Headers); - extractedContext = SpanContextPropagator.Instance.Extract(headersCollection.Value).MergeBaggageInto(Baggage.Current); + extractedContext = tracer.TracerManager.SpanContextPropagator.Extract(headersCollection.Value).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { @@ -101,7 +101,7 @@ internal static Scope CreateScope(IHttpControllerContext controllerContext, out if (headersCollection is not null) { - SpanContextPropagator.Instance.AddHeadersToSpanAsTags(scope.Span, headersCollection.Value, tracer.Settings.HeaderTags, SpanContextPropagator.HttpRequestHeadersTagPrefix, request.Headers.UserAgent.ToString()); + tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags(scope.Span, headersCollection.Value, tracer.Settings.HeaderTags, SpanContextPropagator.HttpRequestHeadersTagPrefix, request.Headers.UserAgent.ToString()); } tags.SetAnalyticsSampleRate(IntegrationId, tracer.Settings, enabledWithGlobalSetting: true); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/AzureFunctionsCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/AzureFunctionsCommon.cs index 97452dd48c0f..54129dcf9a22 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/AzureFunctionsCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/AzureFunctionsCommon.cs @@ -296,7 +296,7 @@ internal static void OverridePropagatedContext(Tracer tracer // the existing datadog headers var useNullableHeaders = !string.IsNullOrEmpty(useNullableHeadersCapability); var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, new RpcHttpHeadersCollection(typedData.Http, useNullableHeaders)); + tracer.TracerManager.SpanContextPropagator.Inject(context, new RpcHttpHeadersCollection(typedData.Http, useNullableHeaders)); } } @@ -342,7 +342,7 @@ private static PropagationContext ExtractPropagatedContextFromHttp(T context, return default; } - return SpanContextPropagator.Instance.Extract(new HttpHeadersCollection(httpRequest.Headers)); + return TracerManager.Instance.SpanContextPropagator.Extract(new HttpHeadersCollection(httpRequest.Headers)); } catch (Exception ex) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcAspNetCoreServer/GrpcDotNetServerCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcAspNetCoreServer/GrpcDotNetServerCommon.cs index 063aae8d2b13..429e30af7cb7 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcAspNetCoreServer/GrpcDotNetServerCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcAspNetCoreServer/GrpcDotNetServerCommon.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -64,7 +64,7 @@ private static PropagationContext ExtractPropagatedContext(HttpRequest request) // extract propagation details from http headers if (request.Headers is { } requestHeaders) { - return SpanContextPropagator.Instance.Extract(new HeadersCollectionAdapter(requestHeaders)); + return TracerManager.Instance.SpanContextPropagator.Extract(new HeadersCollectionAdapter(requestHeaders)); } } catch (Exception ex) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcNetClient/GrpcDotNetClientCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcNetClient/GrpcDotNetClientCommon.cs index 70ecc1f31ca9..9dc27704cd45 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcNetClient/GrpcDotNetClientCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcNetClient/GrpcDotNetClientCommon.cs @@ -56,7 +56,7 @@ internal static class GrpcDotNetClientCommon // add distributed tracing headers to the HTTP request // These will be overwritten by the HttpClient integration if that is enabled, per the RFC var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, new HttpHeadersCollection(requestMessage.Headers)); + tracer.TracerManager.SpanContextPropagator.Inject(context, new HttpHeadersCollection(requestMessage.Headers)); // Add the request metadata as tags if (grpcCall.Options.Headers is { Count: > 0 }) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Client/GrpcLegacyClientCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Client/GrpcLegacyClientCommon.cs index 2b2c314c6b27..f42d9c7153f6 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Client/GrpcLegacyClientCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Client/GrpcLegacyClientCommon.cs @@ -39,7 +39,7 @@ internal static class GrpcLegacyClientCommon { // try extracting all the details we need var requestMetadataWrapper = new MetadataHeadersCollection(requestMetadata); - var existingContext = SpanContextPropagator.Instance.Extract(requestMetadataWrapper); + var existingContext = tracer.TracerManager.SpanContextPropagator.Extract(requestMetadataWrapper); var existingSpanContext = existingContext.SpanContext; // If this operation creates the trace, then we will need to re-apply the sampling priority @@ -145,7 +145,7 @@ public static void InjectHeaders(Tracer tracer, TMethod m // Add the propagation headers var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, collection); + tracer.TracerManager.SpanContextPropagator.Inject(context, collection); } catch (Exception ex) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Server/GrpcLegacyServerCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Server/GrpcLegacyServerCommon.cs index 5bb0aa9e03d2..ef5db7a35eca 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Server/GrpcLegacyServerCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcLegacy/Server/GrpcLegacyServerCommon.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -68,7 +68,7 @@ private static PropagationContext ExtractPropagatedContext(IMetadata? metadata) { if (metadata is not null) { - return SpanContextPropagator.Instance.Extract(new MetadataHeadersCollection(metadata)); + return TracerManager.Instance.SpanContextPropagator.Extract(new MetadataHeadersCollection(metadata)); } } catch (Exception ex) diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/HttpClient/HttpMessageHandlerCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/HttpClient/HttpMessageHandlerCommon.cs index e55c07ba0e05..f3d0ceffef0a 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/HttpClient/HttpMessageHandlerCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/HttpClient/HttpMessageHandlerCommon.cs @@ -44,7 +44,7 @@ public static CallTargetState OnMethodBegin(TTarget instance, // add propagation headers to the HTTP request var context = new PropagationContext(scope?.Span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, new HttpHeadersCollection(headers)); + tracer.TracerManager.SpanContextPropagator.Inject(context, new HttpHeadersCollection(headers)); return scope is null ? CallTargetState.GetDefault() : new CallTargetState(scope); } diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_BeginGetResponse_Integration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_BeginGetResponse_Integration.cs index 07cfe82199d5..d01fe00aecea 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_BeginGetResponse_Integration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_BeginGetResponse_Integration.cs @@ -65,7 +65,7 @@ internal static CallTargetState OnMethodBegin(TTarget instance, AsyncCa // Additionally, add the request headers to a cache to indicate that distributed tracing headers were // added by us, not the application var context = new PropagationContext(span?.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, request.Headers.Wrap()); + tracer.TracerManager.SpanContextPropagator.Inject(context, request.Headers.Wrap()); HeadersInjectedCache.SetInjectedHeaders(request.Headers); } } diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponseV9_Integration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponseV9_Integration.cs index d9e2414b41d3..76f218c5e16e 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponseV9_Integration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponseV9_Integration.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -63,7 +63,7 @@ public class HttpWebRequest_EndGetResponseV9_Integration // We've already propagated baggage through the HTTP headers at this point, // and when this method is called this is presumably the "bottom" of the call chain, // and it may have been called on an entirely different thread. - existingContext = SpanContextPropagator.Instance.Extract(headers); + existingContext = TracerManager.Instance.SpanContextPropagator.Extract(headers); } var existingSpanContext = existingContext.SpanContext; diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponse_Integration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponse_Integration.cs index 8a3ddae399fd..dd3c5d00b567 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponse_Integration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/HttpWebRequest_EndGetResponse_Integration.cs @@ -77,7 +77,7 @@ internal static CallTargetReturn OnMethodEnd(TTarget // We've already propagated baggage through the HTTP headers at this point, // and when this method is called this is presumably the "bottom" of the call chain, // and it may have been called on an entirely different thread. - existingContext = SpanContextPropagator.Instance.Extract(headers); + existingContext = TracerManager.Instance.SpanContextPropagator.Extract(headers); } var existingSpanContext = existingContext.SpanContext; diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/WebRequestCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/WebRequestCommon.cs index 3235e5bfe7e8..46bd8533c8d6 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/WebRequestCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Http/WebRequest/WebRequestCommon.cs @@ -67,7 +67,7 @@ public static bool TryInjectHeaders(TTarget instance) // Additionally, add the request headers to a cache to indicate that distributed tracing headers were // added by us, not the application var context = new PropagationContext(span?.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, request.Headers.Wrap()); + tracer.TracerManager.SpanContextPropagator.Inject(context, request.Headers.Wrap()); HeadersInjectedCache.SetInjectedHeaders(request.Headers); return true; } @@ -93,14 +93,15 @@ public static CallTargetState GetResponse_OnMethodBegin(TTarget instanc // that we have injected context into PropagationContext cachedContext = default; + var tracer = Tracer.Instance; + if (HeadersInjectedCache.TryGetInjectedHeaders(request.Headers)) { var headers = request.Headers.Wrap(); - cachedContext = SpanContextPropagator.Instance.Extract(headers).MergeBaggageInto(Baggage.Current); + cachedContext = tracer.TracerManager.SpanContextPropagator.Extract(headers).MergeBaggageInto(Baggage.Current); } var cachedSpanContext = cachedContext.SpanContext; - var tracer = Tracer.Instance; int? cachedSamplingPriority = null; // If this operation creates the trace, then we need to re-apply the sampling priority @@ -132,7 +133,7 @@ public static CallTargetState GetResponse_OnMethodBegin(TTarget instanc // add propagation headers to the HTTP request var context = new PropagationContext(scope.Span.Context, Baggage.Current); var headers = request.Headers.Wrap(); - SpanContextPropagator.Instance.Inject(context, headers); + tracer.TracerManager.SpanContextPropagator.Inject(context, headers); tracer.TracerManager.Telemetry.IntegrationGeneratedSpan(IntegrationId); return new CallTargetState(scope); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/IbmMq/IbmMqHelper.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/IbmMq/IbmMqHelper.cs index 0787fe96df36..8cfea48d6836 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/IbmMq/IbmMqHelper.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/IbmMq/IbmMqHelper.cs @@ -57,7 +57,7 @@ internal static IbmMqHeadersAdapterNoop GetHeadersAdapter(IMqMessage message) span.SetTag(Tags.SpanKind, SpanKinds.Producer); var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, GetHeadersAdapter(message)); + tracer.TracerManager.SpanContextPropagator.Inject(context, GetHeadersAdapter(message)); } catch (Exception ex) { @@ -97,7 +97,7 @@ internal static IbmMqHeadersAdapterNoop GetHeadersAdapter(IMqMessage message) try { var headers = GetHeadersAdapter(message); - extractedContext = SpanContextPropagator.Instance.Extract(headers).MergeBaggageInto(Baggage.Current); + extractedContext = tracer.TracerManager.SpanContextPropagator.Extract(headers).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Kafka/KafkaHelper.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Kafka/KafkaHelper.cs index 6c77a345aa6c..9922a5dfdf7c 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Kafka/KafkaHelper.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Kafka/KafkaHelper.cs @@ -165,7 +165,7 @@ private static long GetMessageSize(T message) try { - extractedContext = SpanContextPropagator.Instance.Extract(headers).MergeBaggageInto(Baggage.Current); + extractedContext = tracer.TracerManager.SpanContextPropagator.Extract(headers).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { @@ -324,7 +324,7 @@ internal static void TryInjectHeaders( var adapter = new KafkaHeadersCollectionAdapter(message.Headers); var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, adapter); + TracerManager.Instance.SpanContextPropagator.Inject(context, adapter); if (dataStreamsManager.IsEnabled) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicGetIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicGetIntegration.cs index 90587f8a0751..1e66c42de621 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicGetIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicGetIntegration.cs @@ -79,7 +79,7 @@ internal static CallTargetReturn OnMethodEnd(TTarget { basicProperties = basicGetResult.BasicProperties; - extractedContext = SpanContextPropagator.Instance.Extract(basicPropertiesHeaders, default(ContextPropagation)).MergeBaggageInto(Baggage.Current); + extractedContext = TracerManager.Instance.SpanContextPropagator.Extract(basicPropertiesHeaders, default(ContextPropagation)).MergeBaggageInto(Baggage.Current); } catch (Exception ex) { diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicPublishIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicPublishIntegration.cs index 0521e9668842..c92f7e996379 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicPublishIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/BasicPublishIntegration.cs @@ -58,7 +58,8 @@ internal static CallTargetState OnMethodBegin( // Tags is not null if span is not null, but keep analysis happy, as there's no attribute for that if (scope != null && tags is not null) { - Tracer.Instance.CurrentTraceSettings.Schema.RemapPeerService(tags); + var tracer = Tracer.Instance; + tracer.CurrentTraceSettings.Schema.RemapPeerService(tags); string exchangeDisplayName = string.IsNullOrEmpty(exchange) ? "" : exchange; string routingKeyDisplayName = string.IsNullOrEmpty(routingKey) ? "" : routingKey.StartsWith("amq.gen-") ? "" : routingKey; @@ -80,7 +81,7 @@ internal static CallTargetState OnMethodBegin( } var context = new PropagationContext(scope.Span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, basicProperties.Headers, default(ContextPropagation)); + tracer.TracerManager.SpanContextPropagator.Inject(context, basicProperties.Headers, default(ContextPropagation)); RabbitMQIntegration.SetDataStreamsCheckpointOnProduce( Tracer.Instance, diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/RabbitMQIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/RabbitMQIntegration.cs index 73d7cf0007a1..547c4db7dc9d 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/RabbitMQIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ/RabbitMQIntegration.cs @@ -181,7 +181,9 @@ internal static CallTargetState BasicDeliver_OnMethodBegin body in 6.0.0 { - if (IsActiveScopeRabbitMQ(Tracer.Instance)) + var tracer = Tracer.Instance; + + if (IsActiveScopeRabbitMQ(tracer)) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace @@ -204,7 +206,7 @@ internal static CallTargetState BasicDeliver_OnMethodBegin(TTarget instance, IMessag // At the same time, we don't want to set an active scope now, because it's possible that GetResponse will never be called. // Instead, we generate a spancontext and inject it in the headers. GetResponse will fetch them and create an active scope with the right id. var context = new PropagationContext(scope.Span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, requestHeaders, (headers, key, value) => headers[key] = value); + tracer.TracerManager.SpanContextPropagator.Inject(context, requestHeaders, (headers, key, value) => headers[key] = value); // "Disable" tracing so that the regular WebRequest instrumentation does not fire for this request requestHeaders["x-datadog-tracing-enabled"] = "false"; diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Client/IpcTcpProcessMessageIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Client/IpcTcpProcessMessageIntegration.cs index 67790cd4facd..3bca7199b819 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Client/IpcTcpProcessMessageIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Client/IpcTcpProcessMessageIntegration.cs @@ -60,7 +60,7 @@ internal static CallTargetState OnMethodBegin(TTarget instance, IMessag if (tracer.Settings.IsIntegrationEnabled(RemotingIntegration.IntegrationId) && tracer.InternalActiveScope is var scope) { var context = new PropagationContext(scope.Span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject(context, requestHeaders, (headers, key, value) => headers[key] = value); + tracer.TracerManager.SpanContextPropagator.Inject(context, requestHeaders, (headers, key, value) => headers[key] = value); } return CallTargetState.GetDefault(); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Server/ProcessMessageIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Server/ProcessMessageIntegration.cs index df86bd9196d2..560bb2dd8335 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Server/ProcessMessageIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Remoting/Server/ProcessMessageIntegration.cs @@ -72,7 +72,7 @@ internal static CallTargetState OnMethodBegin(TTarget try { - extractedContext = SpanContextPropagator.Instance + extractedContext = TracerManager.Instance.SpanContextPropagator .Extract(requestHeaders, (headers, key) => headers[key] is { } value ? [value.ToString()] : []) .MergeBaggageInto(Baggage.Current); } diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/CoverageGetCoverageResultIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/CoverageGetCoverageResultIntegration.cs index 1fe575f81e3d..129a8b4647b9 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/CoverageGetCoverageResultIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/CoverageGetCoverageResultIntegration.cs @@ -64,7 +64,7 @@ internal static CallTargetReturn OnMethodEnd(TTarget var percentage = coverageDetails.Percent; DotnetCommon.Log.Information("CoverageGetCoverageResult.Percentage: {Value}", percentage); - var context = SpanContextPropagator.Instance.Extract( + var context = TracerManager.Instance.SpanContextPropagator.Extract( EnvironmentHelpers.GetEnvironmentVariables(), new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/DotnetCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/DotnetCommon.cs index 835fd8197f35..609c0e3eded7 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/DotnetCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/DotnetCommon.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -92,7 +92,7 @@ internal static bool IsMsBuildTask } // Let's detect if we already have a session for this test process - var context = SpanContextPropagator.Instance.Extract( + var context = TracerManager.Instance.SpanContextPropagator.Extract( EnvironmentHelpers.GetEnvironmentVariables(), new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/ManagedVanguardStopIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/ManagedVanguardStopIntegration.cs index 9d4356ef5dc5..47ab9ece1ad5 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/ManagedVanguardStopIntegration.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Testing/DotnetTest/ManagedVanguardStopIntegration.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -51,7 +51,7 @@ internal static CallTargetReturn OnMethodEnd(TTarget instance, Exceptio DotnetCommon.Log.Information("MicrosoftCodeCoverage.Percentage: {Value}", percentage); // Extract session variables (from out of process sessions) - var context = SpanContextPropagator.Instance.Extract( + var context = TracerManager.Instance.SpanContextPropagator.Extract( EnvironmentHelpers.GetEnvironmentVariables(), new DictionaryGetterAndSetter(DictionaryGetterAndSetter.EnvironmentVariableKeyProcessor)); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Wcf/WcfCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Wcf/WcfCommon.cs index 5b70b706e1bc..e4ea79f0015f 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Wcf/WcfCommon.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Wcf/WcfCommon.cs @@ -83,7 +83,7 @@ internal class WcfCommon { headers = webHeaderCollection.Wrap(); - extractedContext = SpanContextPropagator.Instance + extractedContext = tracer.TracerManager.SpanContextPropagator .Extract(headers.Value) .MergeBaggageInto(Baggage.Current); } @@ -99,7 +99,7 @@ internal class WcfCommon Log.Debug("Extracting from WCF headers if any as http headers hadn't been found."); try { - extractedContext = SpanContextPropagator.Instance + extractedContext = tracer.TracerManager.SpanContextPropagator .Extract(messageHeaders, GetHeaderValues) .MergeBaggageInto(Baggage.Current); @@ -173,7 +173,7 @@ internal class WcfCommon if (headers is not null) { var headerTagsProcessor = new SpanContextPropagator.SpanTagHeaderTagProcessor(span); - SpanContextPropagator.Instance.ExtractHeaderTags(ref headerTagsProcessor, headers.Value, tracer.Settings.HeaderTags!, SpanContextPropagator.HttpRequestHeadersTagPrefix); + tracer.TracerManager.SpanContextPropagator.ExtractHeaderTags(ref headerTagsProcessor, headers.Value, tracer.Settings.HeaderTags!, SpanContextPropagator.HttpRequestHeadersTagPrefix); } tags.SetAnalyticsSampleRate(IntegrationId, tracer.Settings, enabledWithGlobalSetting: true); diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutomaticTracer.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutomaticTracer.cs index a21f7fa03001..65b99f7b8d3b 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutomaticTracer.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/AutomaticTracer.cs @@ -54,7 +54,7 @@ SpanContext IDistributedTracer.GetSpanContext() return spanContext; } - var context = SpanContextPropagator.Instance.Extract(value); + var context = TracerManager.Instance.SpanContextPropagator.Extract(value); return context.SpanContext; } diff --git a/tracer/src/Datadog.Trace/ClrProfiler/ManualTracer.cs b/tracer/src/Datadog.Trace/ClrProfiler/ManualTracer.cs index 56b6940b73bf..daa0c17ce8b1 100644 --- a/tracer/src/Datadog.Trace/ClrProfiler/ManualTracer.cs +++ b/tracer/src/Datadog.Trace/ClrProfiler/ManualTracer.cs @@ -72,7 +72,7 @@ SpanContext IDistributedTracer.GetSpanContext() } else { - var context = SpanContextPropagator.Instance.Extract(values); + var context = TracerManager.Instance.SpanContextPropagator.Extract(values); return context.SpanContext; } } diff --git a/tracer/src/Datadog.Trace/ExtensionMethods/SpanExtensions.cs b/tracer/src/Datadog.Trace/ExtensionMethods/SpanExtensions.cs index 468bbd802d49..faa59f015f3b 100644 --- a/tracer/src/Datadog.Trace/ExtensionMethods/SpanExtensions.cs +++ b/tracer/src/Datadog.Trace/ExtensionMethods/SpanExtensions.cs @@ -79,7 +79,7 @@ internal static void SetHeaderTags(this ISpan span, T headers, IReadOnlyDicti { try { - SpanContextPropagator.Instance.AddHeadersToSpanAsTags(span, headers, headerTags, defaultTagPrefix); + TracerManager.Instance.SpanContextPropagator.AddHeadersToSpanAsTags(span, headers, headerTags, defaultTagPrefix); } catch (Exception ex) { diff --git a/tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs b/tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs index 8ff80d90a16f..c5c87e13ac62 100644 --- a/tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs +++ b/tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs @@ -54,14 +54,14 @@ public string GetDefaultResourceName(HttpRequest request) return $"{httpMethod} {resourceUrl}"; } - private PropagationContext ExtractPropagatedContext(HttpRequest request) + private PropagationContext ExtractPropagatedContext(Tracer tracer, HttpRequest request) { try { // extract propagation details from http headers if (request.Headers is { } headers) { - return SpanContextPropagator.Instance.Extract(new HeadersCollectionAdapter(headers)); + return tracer.TracerManager.SpanContextPropagator.Extract(new HeadersCollectionAdapter(headers)); } } catch (Exception ex) @@ -83,7 +83,7 @@ private void AddHeaderTagsToSpan(ISpan span, HttpRequest request, Tracer tracer) // extract propagation details from http headers if (request.Headers is { } requestHeaders) { - SpanContextPropagator.Instance.AddHeadersToSpanAsTags( + tracer.TracerManager.SpanContextPropagator.AddHeadersToSpanAsTags( span, new HeadersCollectionAdapter(requestHeaders), headerTagsInternal, @@ -107,7 +107,7 @@ public Scope StartAspNetCorePipelineScope(Tracer tracer, Security security, Http var userAgent = request.Headers[HttpHeaderNames.UserAgent]; resourceName ??= GetDefaultResourceName(request); - var extractedContext = ExtractPropagatedContext(request).MergeBaggageInto(Baggage.Current); + var extractedContext = ExtractPropagatedContext(tracer, request).MergeBaggageInto(Baggage.Current); var routeTemplateResourceNames = tracer.Settings.RouteTemplateResourceNamesEnabled; var tags = routeTemplateResourceNames ? new AspNetCoreEndpointTags() : new AspNetCoreTags(); diff --git a/tracer/src/Datadog.Trace/Propagators/DistributedContextExtractor.cs b/tracer/src/Datadog.Trace/Propagators/DistributedContextExtractor.cs deleted file mode 100644 index 792b7845f53a..000000000000 --- a/tracer/src/Datadog.Trace/Propagators/DistributedContextExtractor.cs +++ /dev/null @@ -1,88 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using System.Collections.Generic; -using Datadog.Trace.Tagging; -using Datadog.Trace.Util; - -namespace Datadog.Trace.Propagators -{ - internal class DistributedContextExtractor : IContextExtractor - { - public static readonly DistributedContextExtractor Instance = new(); - - private DistributedContextExtractor() - { - } - - public PropagatorType PropagatorType => PropagatorType.TraceContext; - - public bool TryExtract(TCarrier carrier, TCarrierGetter carrierGetter, out PropagationContext context) - where TCarrierGetter : struct, ICarrierGetter - { - context = default; - - if (carrier is not IReadOnlyDictionary) - { - return false; - } - - var traceIdLower = ParseUtility.ParseUInt64(carrier, carrierGetter, SpanContext.Keys.TraceId); - - if (traceIdLower is null or 0) - { - // a valid traceId is required to use distributed tracing - return false; - } - - var rawTraceId = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.RawTraceId); - TraceId traceId = default; - - if (!string.IsNullOrEmpty(rawTraceId)) - { - _ = HexString.TryParseTraceId(rawTraceId!, out traceId); - } - - var parentId = ParseUtility.ParseUInt64(carrier, carrierGetter, SpanContext.Keys.ParentId) ?? 0; - var samplingPriority = ParseUtility.ParseInt32(carrier, carrierGetter, SpanContext.Keys.SamplingPriority); - var origin = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.Origin); - var rawSpanId = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.RawSpanId); - var propagatedTraceTags = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.PropagatedTags); - var w3CTraceState = ParseUtility.ParseString(carrier, carrierGetter, SpanContext.Keys.AdditionalW3CTraceState); - var traceTags = TagPropagation.ParseHeader(propagatedTraceTags); - - if (traceId == TraceId.Zero) - { - traceId = GetFullTraceId((ulong)traceIdLower, traceTags); - } - - // we don't consider contexts coming from this as "remote" as it could be from a version conflict scenario - var spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, origin, rawTraceId, rawSpanId, isRemote: false) - { - PropagatedTags = traceTags, - AdditionalW3CTraceState = w3CTraceState, - }; - - context = new PropagationContext(spanContext, baggage: null); - return true; - } - - // combine the lower 64 bits from "x-datadog-trace-id" with the - // upper 64 bits from "_dd.p.tid" into a 128-bit trace id - private static TraceId GetFullTraceId(ulong lower, TraceTagCollection tags) - { - var upperHex = tags.GetTag(Tags.Propagated.TraceIdUpper); - - if (!string.IsNullOrEmpty(upperHex) && HexString.TryParseUInt64(upperHex!, out var upper)) - { - return new TraceId(upper, lower); - } - - return (TraceId)lower; - } - } -} diff --git a/tracer/src/Datadog.Trace/Propagators/SpanContextPropagator.cs b/tracer/src/Datadog.Trace/Propagators/SpanContextPropagator.cs index 2310ed6f8458..c92916870670 100644 --- a/tracer/src/Datadog.Trace/Propagators/SpanContextPropagator.cs +++ b/tracer/src/Datadog.Trace/Propagators/SpanContextPropagator.cs @@ -20,9 +20,6 @@ internal class SpanContextPropagator internal const string HttpRequestHeadersTagPrefix = "http.request.headers"; internal const string HttpResponseHeadersTagPrefix = "http.response.headers"; - private static readonly object GlobalLock = new(); - private static SpanContextPropagator? _instance; - private readonly ConcurrentDictionary _defaultTagMappingCache = new(); private readonly IContextInjector[] _injectors; private readonly IContextExtractor[] _extractors; @@ -38,45 +35,6 @@ internal SpanContextPropagator( _extractors = extractors?.ToArray() ?? []; } - public static SpanContextPropagator Instance - { - get - { - if (_instance is not null) - { - return _instance; - } - - lock (GlobalLock) - { - if (_instance is not null) - { - return _instance; - } - - _instance = new SpanContextPropagator( - [DatadogContextPropagator.Instance], - [DistributedContextExtractor.Instance, DatadogContextPropagator.Instance], - propagationExtractFirstValue: false); - - return _instance; - } - } - - internal set - { - if (value == null!) - { - ThrowHelper.ThrowArgumentNullException(nameof(value)); - } - - lock (GlobalLock) - { - _instance = value; - } - } - } - /// /// Propagates the specified context by adding new headers to a . /// This locks the sampling priority for . diff --git a/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingClient.cs b/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingClient.cs index d2c9a30fa1dd..36b8c7ed0831 100644 --- a/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingClient.cs +++ b/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingClient.cs @@ -69,7 +69,7 @@ private static void ServiceRemotingClientEvents_SendRequest(object? sender, Even { var context = new PropagationContext(span.Context, Baggage.Current); - SpanContextPropagator.Instance.Inject( + tracer.TracerManager.SpanContextPropagator.Inject( context, messageHeaders, default(ServiceRemotingRequestMessageHeaderSetter)); diff --git a/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingService.cs b/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingService.cs index 0f1faec8965b..06e0b1b7c80f 100644 --- a/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingService.cs +++ b/tracer/src/Datadog.Trace/ServiceFabric/ServiceRemotingService.cs @@ -63,7 +63,7 @@ private static void ServiceRemotingServiceEvents_ReceiveRequest(object? sender, // extract propagation context from message headers for distributed tracing if (messageHeaders != null) { - extractedContext = SpanContextPropagator.Instance + extractedContext = tracer.TracerManager.SpanContextPropagator .Extract(messageHeaders, default(ServiceRemotingRequestMessageHeaderGetter)) .MergeBaggageInto(Baggage.Current); } diff --git a/tracer/src/Datadog.Trace/SpanContextExtractor.cs b/tracer/src/Datadog.Trace/SpanContextExtractor.cs index 23febc4a6702..b257ed914b99 100644 --- a/tracer/src/Datadog.Trace/SpanContextExtractor.cs +++ b/tracer/src/Datadog.Trace/SpanContextExtractor.cs @@ -80,11 +80,12 @@ internal SpanContextExtractor(bool unusedParamNotToUsePublicApi) if (messageType != null && source == null) { ThrowHelper.ThrowArgumentNullException(nameof(source)); } else if (messageType == null && source != null) { ThrowHelper.ThrowArgumentNullException(nameof(messageType)); } - var context = SpanContextPropagator.Instance.Extract(carrier, getter); + var tracer = Tracer.Instance; + var context = tracer.TracerManager.SpanContextPropagator.Extract(carrier, getter); // DSM if (context.SpanContext is { } spanContext - && Tracer.Instance.TracerManager.DataStreamsManager is { IsEnabled: true } dsm) + && tracer.TracerManager.DataStreamsManager is { IsEnabled: true } dsm) { if (getter(carrier, DataStreamsPropagationHeaders.TemporaryBase64PathwayContext).FirstOrDefault() is { Length: > 0 } base64PathwayContext) { diff --git a/tracer/src/Datadog.Trace/SpanContextInjector.cs b/tracer/src/Datadog.Trace/SpanContextInjector.cs index 76a43622b55b..3e034a93d0ee 100644 --- a/tracer/src/Datadog.Trace/SpanContextInjector.cs +++ b/tracer/src/Datadog.Trace/SpanContextInjector.cs @@ -75,7 +75,8 @@ internal static void InjectInternal(TCarrier carrier, Action(TCarrier carrier, Action @@ -164,6 +167,8 @@ public static TracerManager Instance public PerTraceSettings PerTraceSettings { get; } + public SpanContextPropagator SpanContextPropagator { get; } + /// /// Replaces the global settings. This affects all instances /// which use the global diff --git a/tracer/src/Datadog.Trace/TracerManagerFactory.cs b/tracer/src/Datadog.Trace/TracerManagerFactory.cs index 74cb7cbc0b5f..2d16e877521a 100644 --- a/tracer/src/Datadog.Trace/TracerManagerFactory.cs +++ b/tracer/src/Datadog.Trace/TracerManagerFactory.cs @@ -150,8 +150,6 @@ internal TracerManager CreateTracerManager( telemetry.RecordProfilerSettings(profiler); telemetry.ProductChanged(TelemetryProductType.Profiler, enabled: profiler.Status.IsProfilerReady, error: null); - SpanContextPropagator.Instance = SpanContextPropagatorFactory.GetSpanContextPropagator(settings.PropagationStyleInject, settings.PropagationStyleExtract, settings.PropagationExtractFirstOnly); - dataStreamsManager ??= DataStreamsManager.Create(settings, discoveryService, defaultServiceName); if (ShouldEnableRemoteConfiguration(settings)) diff --git a/tracer/test/Datadog.Trace.IntegrationTests/Sampling/DelaySamplingDecisionTests.cs b/tracer/test/Datadog.Trace.IntegrationTests/Sampling/DelaySamplingDecisionTests.cs index 178d0a0bcd1e..eca7c45e76e3 100644 --- a/tracer/test/Datadog.Trace.IntegrationTests/Sampling/DelaySamplingDecisionTests.cs +++ b/tracer/test/Datadog.Trace.IntegrationTests/Sampling/DelaySamplingDecisionTests.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -77,7 +77,7 @@ public void SamplingDecisionIsMadeWhenPropagating() traceContext.SamplingPriority.Should().BeNull(); var headers = new NameValueCollection(); - SpanContextPropagator.Instance.Inject( + tracer.TracerManager.SpanContextPropagator.Inject( new PropagationContext(scope1.Span.Context, baggage: null), headers.Wrap()); diff --git a/tracer/test/Datadog.Trace.TestHelpers/CustomTestFramework.cs b/tracer/test/Datadog.Trace.TestHelpers/CustomTestFramework.cs index 10651578d279..7ddb24aaa586 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/CustomTestFramework.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/CustomTestFramework.cs @@ -117,6 +117,19 @@ protected override async Task RunTestCollectionsAsync(IMessageBus me }) .ToList(); + var seed = new Random().Next(); + + DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Using seed {seed} to randomize tests order")); + + var random = new Random(seed); + + Shuffle(collections, random); + + foreach (var collection in collections) + { + Shuffle(collection.TestCases, random); + } + var summary = new RunSummary(); using var runner = new ConcurrentRunner(); @@ -161,6 +174,20 @@ private static bool IsParallelizationDisabled(ITestCollection collection) return attr?.GetNamedArgument(nameof(CollectionDefinitionAttribute.DisableParallelization)) is true; } + + private static void Shuffle(IList list, Random rng) + { + int n = list.Count; + + while (n > 1) + { + n--; + int k = rng.Next(n + 1); + var value = list[k]; + list[k] = list[n]; + list[n] = value; + } + } } private class CustomTestCollectionRunner : XunitTestCollectionRunner diff --git a/tracer/test/Datadog.Trace.Tests/DistributedTracer/AutomaticTracerTests.cs b/tracer/test/Datadog.Trace.Tests/DistributedTracer/AutomaticTracerTests.cs index 9f636f3f626c..006b154a38f6 100644 --- a/tracer/test/Datadog.Trace.Tests/DistributedTracer/AutomaticTracerTests.cs +++ b/tracer/test/Datadog.Trace.Tests/DistributedTracer/AutomaticTracerTests.cs @@ -89,7 +89,7 @@ public void GetDistributedTrace() using (var scope = Tracer.Instance.StartActive("Test")) { - var context = SpanContextPropagator.Instance.Extract(automaticTracer.GetDistributedTrace()); + var context = TracerManager.Instance.SpanContextPropagator.Extract(automaticTracer.GetDistributedTrace()); var spanContext = context.SpanContext!; spanContext.Should().NotBeNull(); diff --git a/tracer/test/Datadog.Trace.Tests/ManualInstrumentation/DuckTypingTests.cs b/tracer/test/Datadog.Trace.Tests/ManualInstrumentation/DuckTypingTests.cs index 213f9c1d0386..d4f1fd8ed927 100644 --- a/tracer/test/Datadog.Trace.Tests/ManualInstrumentation/DuckTypingTests.cs +++ b/tracer/test/Datadog.Trace.Tests/ManualInstrumentation/DuckTypingTests.cs @@ -1,4 +1,4 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // @@ -86,61 +86,69 @@ public void CanDuckTypeScopeAsManualIScope() [Fact] public void CanDuckTypeManualTestSessionAsISession() { - var autoSession = TestSession.GetOrCreate("blah"); - - var session = autoSession.DuckCast(); - - // call the methods to make sure it works - var module = session.CreateModule("somemodule"); - module.Should().NotBeNull(); - - var suite = module.GetOrCreateSuite("mysuite"); - suite.Should().NotBeNull(); - - var test = suite.CreateTest("mytest"); - test.Should().NotBeNull(); - - var stats = new ManualBenchmarkDiscreteStats(100, 100, 100, 100, 100, 0, 0, 0, 0, 100, 100, 100); - var statsDuckType = stats.DuckCast(); - TestExtensionsAddBenchmarkDataIntegration.OnMethodBegin(test, BenchmarkMeasureType.RunTime, "some info", statsDuckType); - // test.AddBenchmarkData(BenchmarkMeasureType.ApplicationLaunch, info: "something", in stats); - - var parameters = new ManualTestParameters { Arguments = new(), Metadata = new() }; - var paramsDuckType = parameters.DuckCast(); - TestExtensionsSetParametersIntegration.OnMethodBegin(test, paramsDuckType); - // test.SetParameters(new TestParameters { Arguments = new(), Metadata = new() }); - - var hostInfo = new ManualBenchmarkHostInfo { RuntimeVersion = "123" }; - var jobInfo = new ManualBenchmarkJobInfo { Description = "weeble" }; - var hostInfoDuckType = hostInfo.DuckCast(); - var jobInfoDuckType = jobInfo.DuckCast(); - TestExtensionsSetBenchmarkMetadataIntegration.OnMethodBegin(test, in hostInfoDuckType, in jobInfoDuckType); - // test.SetBenchmarkMetadata(new BenchmarkHostInfo() { RuntimeVersion = "123" }, new BenchmarkJobInfo() { Description = "weeble" }); - - // basic check that things were pushed down correctly - var span = test.Should() - .BeAssignableTo() - .Subject.Instance.Should() - .BeOfType() - .Subject.GetInternalSpan() - .Should() - .BeOfType() - .Subject; - span.GetMetric("benchmark.run_time.run").Should().Be(100); - - span.GetTag("host.runtime_version").Should().Be("123"); - span.GetTag("test.configuration.job_description").Should().Be("weeble"); - - var tags = span.Tags.Should().BeOfType().Subject; - tags.Parameters - .Should() - .NotBeNull() - .And.Be(new TestParameters { Arguments = new(), Metadata = new() }.ToJSON()); - - test.Close(TestStatus.Pass); - suite.Close(); - module.Close(); - session.Close(TestStatus.Pass); + try + { + var autoSession = TestSession.GetOrCreate("blah"); + + var session = autoSession.DuckCast(); + + // call the methods to make sure it works + var module = session.CreateModule("somemodule"); + module.Should().NotBeNull(); + + var suite = module.GetOrCreateSuite("mysuite"); + suite.Should().NotBeNull(); + + var test = suite.CreateTest("mytest"); + test.Should().NotBeNull(); + + var stats = new ManualBenchmarkDiscreteStats(100, 100, 100, 100, 100, 0, 0, 0, 0, 100, 100, 100); + var statsDuckType = stats.DuckCast(); + TestExtensionsAddBenchmarkDataIntegration.OnMethodBegin(test, BenchmarkMeasureType.RunTime, "some info", statsDuckType); + // test.AddBenchmarkData(BenchmarkMeasureType.ApplicationLaunch, info: "something", in stats); + + var parameters = new ManualTestParameters { Arguments = new(), Metadata = new() }; + var paramsDuckType = parameters.DuckCast(); + TestExtensionsSetParametersIntegration.OnMethodBegin(test, paramsDuckType); + // test.SetParameters(new TestParameters { Arguments = new(), Metadata = new() }); + + var hostInfo = new ManualBenchmarkHostInfo { RuntimeVersion = "123" }; + var jobInfo = new ManualBenchmarkJobInfo { Description = "weeble" }; + var hostInfoDuckType = hostInfo.DuckCast(); + var jobInfoDuckType = jobInfo.DuckCast(); + TestExtensionsSetBenchmarkMetadataIntegration.OnMethodBegin(test, in hostInfoDuckType, in jobInfoDuckType); + // test.SetBenchmarkMetadata(new BenchmarkHostInfo() { RuntimeVersion = "123" }, new BenchmarkJobInfo() { Description = "weeble" }); + + // basic check that things were pushed down correctly + var span = test.Should() + .BeAssignableTo() + .Subject.Instance.Should() + .BeOfType() + .Subject.GetInternalSpan() + .Should() + .BeOfType() + .Subject; + span.GetMetric("benchmark.run_time.run").Should().Be(100); + + span.GetTag("host.runtime_version").Should().Be("123"); + span.GetTag("test.configuration.job_description").Should().Be("weeble"); + + var tags = span.Tags.Should().BeOfType().Subject; + tags.Parameters + .Should() + .NotBeNull() + .And.Be(new TestParameters { Arguments = new(), Metadata = new() }.ToJSON()); + + test.Close(TestStatus.Pass); + suite.Close(); + module.Close(); + session.Close(TestStatus.Pass); + } + finally + { + CIVisibility.Close(); + CIVisibility.Reset(); + } } [Fact] diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/DistributedPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/DistributedPropagatorTests.cs deleted file mode 100644 index 7bd5f8160fb9..000000000000 --- a/tracer/test/Datadog.Trace.Tests/Propagators/DistributedPropagatorTests.cs +++ /dev/null @@ -1,295 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using System.Globalization; -using Datadog.Trace.Propagators; -using Datadog.Trace.Tagging; -using FluentAssertions; -using Moq; -using Xunit; - -namespace Datadog.Trace.Tests.Propagators; - -public class DistributedPropagatorTests -{ - private const int SamplingPriority = SamplingPriorityValues.UserReject; - private const string Origin = "origin"; - private const string PropagatedTagsString = "_dd.p.key1=value1,_dd.p.key2=value2"; - private const string AdditionalW3CTraceState = "key3=value3,key4=value4"; - private const ulong SpanId = 0x1122334455667788; // 1234605616436508552 - private const string RawSpanId = "1122334455667788"; // 1234605616436508552 - private const string RawTraceId = "00000000000000001234567890abcdef"; // 1311768467294899695 - private static readonly TraceId TraceId = (TraceId)0x1234567890abcdef; // 1311768467294899695 - - private static readonly CultureInfo InvariantCulture = CultureInfo.InvariantCulture; - - private static readonly SpanContextPropagator Propagator; - - private static readonly KeyValuePair[] DefaultHeaderValues = - { - new("__DistributedKey-TraceId", TraceId.Lower.ToString(InvariantCulture)), - new("__DistributedKey-ParentId", SpanId.ToString(InvariantCulture)), - new("__DistributedKey-SamplingPriority", SamplingPriority.ToString(InvariantCulture)), - new("__DistributedKey-Origin", Origin), - new("__DistributedKey-RawTraceId", RawTraceId), - new("__DistributedKey-RawSpanId", RawSpanId), - new("__DistributedKey-PropagatedTags", PropagatedTagsString), - new("__DistributedKey-AdditionalW3CTraceState", AdditionalW3CTraceState), - }; - - private static readonly TraceTagCollection PropagatedTagsCollection = new( - new List> - { - new("_dd.p.key1", "value1"), - new("_dd.p.key2", "value2"), - }, - PropagatedTagsString); - - private static readonly TraceTagCollection EmptyPropagatedTags = new(); - - static DistributedPropagatorTests() - { - Propagator = new SpanContextPropagator( - injectors: [], - extractors: [DistributedContextExtractor.Instance], - propagationExtractFirstValue: false); - } - - public static TheoryData GetInvalidIds() => new() - { - null, - string.Empty, - "0", - "-1", - "id", - }; - - [Fact] - public void Extract_ReadOnlyDictionary() - { - // set up all key/value pairs - var headers = SetupMockReadOnlyDictionary(); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - VerifyGetCalls(headers); - - result.SpanContext - .Should() - .NotBeNull() - .And - .BeEquivalentTo( - new SpanContextMock - { - TraceId128 = TraceId, - TraceId = TraceId.Lower, - SpanId = SpanId, - RawTraceId = RawTraceId, - RawSpanId = RawSpanId, - Origin = Origin, - SamplingPriority = SamplingPriority, - PropagatedTags = PropagatedTagsCollection, - AdditionalW3CTraceState = AdditionalW3CTraceState, - }); - } - - [Fact] - public void Extract_EmptyHeadersReturnsNull() - { - // empty - var headers = new Mock>(); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - result.SpanContext.Should().BeNull(); - } - - [Fact] - public void Extract_TraceIdOnly() - { - var value = TraceId.Lower.ToString(InvariantCulture); - - // only setup TraceId, other properties remain null/empty - var headers = new Mock>(); - headers.Setup(h => h.Count).Returns(1); - headers.Setup(h => h.TryGetValue("__DistributedKey-TraceId", out value)).Returns(true); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - result.SpanContext - .Should() - .NotBeNull() - .And - .BeEquivalentTo( - new SpanContextMock - { - TraceId128 = TraceId, - TraceId = TraceId.Lower, - RawTraceId = RawTraceId, - RawSpanId = "0000000000000000", - PropagatedTags = EmptyPropagatedTags, - }); - - // TODO: add this to all tests - result.Baggage.Should().BeNull(); - } - - [Fact] - public void SpanContextRoundTrip() - { - var propagatedTags = new TraceTagCollection(); - propagatedTags.SetTag("_dd.p.key1", "value1"); - propagatedTags.SetTag("_dd.p.key2", "value2"); - - var traceContext = new TraceContext(Mock.Of(), propagatedTags); - traceContext.SetSamplingPriority(SamplingPriority); - traceContext.Origin = Origin; - traceContext.AdditionalW3CTraceState = AdditionalW3CTraceState; - - // create and populate SpanContext - IReadOnlyDictionary context = new SpanContext( - parent: SpanContext.None, - traceContext, - serviceName: null, - TraceId, - SpanId, - RawTraceId, - RawSpanId); - - // extract SpanContext - var result = Propagator.Extract(context); - - // they are not the same SpanContext instance... - result.SpanContext.Should().NotBeSameAs(context); - - // ...but they contain the same values - result.SpanContext.Should().BeEquivalentTo(context); - } - - [Theory] - [MemberData(nameof(GetInvalidIds))] - public void Extract_InvalidTraceId(string traceId) - { - // set up all key/value pairs - var headers = SetupMockReadOnlyDictionary(); - - // replace TraceId setup - var value = traceId; - headers.Setup(h => h.TryGetValue("__DistributedKey-TraceId", out value)).Returns(true); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - // invalid traceId should return a null context even if other values are set - result.SpanContext.Should().BeNull(); - } - - [Theory] - [MemberData(nameof(GetInvalidIds))] - public void Extract_InvalidSpanId(string spanId) - { - // set up all key/value pairs - var headers = SetupMockReadOnlyDictionary(); - - // replace ParentId setup - var value = spanId; - headers.Setup(h => h.TryGetValue("__DistributedKey-ParentId", out value)).Returns(true); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - result.SpanContext - .Should() - .NotBeNull() - .And - .BeEquivalentTo( - new SpanContextMock - { - // SpanId has default value - TraceId128 = TraceId, - TraceId = TraceId.Lower, - Origin = Origin, - RawTraceId = RawTraceId, - RawSpanId = RawSpanId, - SamplingPriority = SamplingPriority, - PropagatedTags = PropagatedTagsCollection, - AdditionalW3CTraceState = AdditionalW3CTraceState, - }); - } - - [Theory] - [InlineData("-1000", -1000)] - [InlineData("1000", 1000)] - [InlineData("1.0", null)] - [InlineData("1,0", null)] - [InlineData("sampling.priority", null)] - public void Extract_InvalidSamplingPriority(string samplingPriority, int? expectedSamplingPriority) - { - // if the extracted sampling priority is a valid integer, pass it along as-is, - // even if we don't recognize its value (to allow forward compatibility with newly added values). - // ignore the extracted sampling priority if it is not a valid integer. - - // set up all key/value pairs - var headers = SetupMockReadOnlyDictionary(); - - // replace SamplingPriority setup - var value = samplingPriority; - headers.Setup(h => h.TryGetValue("__DistributedKey-SamplingPriority", out value)).Returns(true); - - // extract SpanContext - var result = Propagator.Extract(headers.Object); - - result.SpanContext - .Should() - .NotBeNull() - .And - .BeEquivalentTo( - new SpanContextMock - { - TraceId128 = TraceId, - TraceId = TraceId.Lower, - SpanId = SpanId, - RawTraceId = RawTraceId, - RawSpanId = RawSpanId, - Origin = Origin, - SamplingPriority = expectedSamplingPriority, - PropagatedTags = PropagatedTagsCollection, - AdditionalW3CTraceState = AdditionalW3CTraceState, - }); - } - - private static Mock> SetupMockReadOnlyDictionary() - { - var headers = new Mock>(MockBehavior.Strict); - headers.Setup(h => h.Count).Returns(DefaultHeaderValues.Length); - - foreach (var pair in DefaultHeaderValues) - { - var value = pair.Value; - headers.Setup(h => h.TryGetValue(pair.Key, out value)).Returns(true); - } - - return headers; - } - - private static void VerifyGetCalls(Mock> headers) - { - var once = Times.Once(); - string value; - - headers.Verify(h => h.Count, once); - - foreach (var pair in DefaultHeaderValues) - { - headers.Verify(h => h.TryGetValue(pair.Key, out value), once); - } - - headers.VerifyNoOtherCalls(); - } -} diff --git a/tracer/test/Datadog.Trace.Tests/SpanContextPropagatorTests_ExtractHeaderTags.cs b/tracer/test/Datadog.Trace.Tests/SpanContextPropagatorTests_ExtractHeaderTags.cs index 6f7fd9df699e..748e73416ade 100644 --- a/tracer/test/Datadog.Trace.Tests/SpanContextPropagatorTests_ExtractHeaderTags.cs +++ b/tracer/test/Datadog.Trace.Tests/SpanContextPropagatorTests_ExtractHeaderTags.cs @@ -75,7 +75,7 @@ internal void ExtractHeaderTags_MatchesCaseInsensitiveHeaders(HeaderCollectionTy // Test var processor = new HeaderTagsProcessor(); - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); var tagsFromHeader = processor.TagsFromHeader; // Assert @@ -99,7 +99,7 @@ internal void ExtractHeaderTags_EmptyHeaders_AddsNoTags(HeaderCollectionType hea // Test var processor = new HeaderTagsProcessor(); - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); var tagsFromHeader = processor.TagsFromHeader; // Assert @@ -122,7 +122,7 @@ internal void ExtractHeaderTags_EmptyHeaderTags_AddsNoTags(HeaderCollectionType // Test var processor = new HeaderTagsProcessor(); - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerToTagMap, TestPrefix); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerToTagMap, TestPrefix); var tagsFromHeader = processor.TagsFromHeader; // Assert @@ -158,7 +158,7 @@ internal void ExtractHeaderTags_ForEmptyStringMappings_CreatesNormalizedTagWithP // Test var processor = new HeaderTagsProcessor(); - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerToTagMap, TestPrefix); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerToTagMap, TestPrefix); var tagsFromHeader = processor.TagsFromHeader; // Assert @@ -189,11 +189,11 @@ internal void ExtractHeaderTags_WithUserAgent(bool provideUserAgent) var processor = new HeaderTagsProcessor(); if (provideUserAgent) { - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix, uaInParameter); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix, uaInParameter); } else { - SpanContextPropagator.Instance.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); + TracerManager.Instance.SpanContextPropagator.ExtractHeaderTags(ref processor, headers, headerTags, TestPrefix); } var tagsFromHeader = processor.TagsFromHeader; diff --git a/tracer/test/Datadog.Trace.Tests/TracerTests.cs b/tracer/test/Datadog.Trace.Tests/TracerTests.cs index 7e25032cb721..e60007bfc3dd 100644 --- a/tracer/test/Datadog.Trace.Tests/TracerTests.cs +++ b/tracer/test/Datadog.Trace.Tests/TracerTests.cs @@ -498,8 +498,8 @@ public void OriginHeader_InjectFromChildSpan() IHeadersCollection headers = WebRequest.CreateHttp("http://localhost").Headers.Wrap(); - SpanContextPropagator.Instance.Inject(new PropagationContext(secondSpan.Context, baggage: null), headers); - var context = SpanContextPropagator.Instance.Extract(headers); + TracerManager.Instance.SpanContextPropagator.Inject(new PropagationContext(secondSpan.Context, baggage: null), headers); + var context = TracerManager.Instance.SpanContextPropagator.Extract(headers); var spanContext = context.SpanContext!; spanContext.Should().NotBeNull(); diff --git a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CiRunCommandTests.cs b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CiRunCommandTests.cs index a977dfb78bce..3ac4a9f487df 100644 --- a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CiRunCommandTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CiRunCommandTests.cs @@ -35,7 +35,6 @@ public class CiRunCommandTests : BaseRunCommandTests public CiRunCommandTests() : base("ci run", enableCiVisibilityMode: true) { - CIVisibility.UseLockedTracerManager = false; } [Fact] diff --git a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CustomTestFramework.cs b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CustomTestFramework.cs index 2e3050929695..2120a20aab32 100644 --- a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CustomTestFramework.cs +++ b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/CustomTestFramework.cs @@ -3,6 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +using Datadog.Trace.Ci; using Xunit; using Xunit.Abstractions; @@ -15,6 +16,7 @@ public class CustomTestFramework : TestHelpers.CustomTestFramework public CustomTestFramework(IMessageSink messageSink) : base(messageSink) { + CIVisibility.UseLockedTracerManager = false; } } } diff --git a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/Datadog.Trace.Tools.Runner.IntegrationTests.csproj b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/Datadog.Trace.Tools.Runner.IntegrationTests.csproj index 0e77cbacc246..93b82f8cd38d 100644 --- a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/Datadog.Trace.Tools.Runner.IntegrationTests.csproj +++ b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/Datadog.Trace.Tools.Runner.IntegrationTests.csproj @@ -17,6 +17,12 @@ + + + Always + + + diff --git a/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/xunit.runner.json b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/xunit.runner.json new file mode 100644 index 000000000000..eae9335ded8e --- /dev/null +++ b/tracer/test/Datadog.Trace.Tools.Runner.IntegrationTests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "diagnosticMessages": true, + "internalDiagnosticMessages": true +} \ No newline at end of file