Skip to content
12 changes: 11 additions & 1 deletion tracer/src/Datadog.Trace/ClrProfiler/Instrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,17 @@ private static void StartDiagnosticManager()
// Iast hasn't yet, but doing it now is fine
// span origins is _not_ initialized yet, and we can't guarantee it will be
// so just be lazy instead
observers.Add(new AspNetCoreDiagnosticObserver(Tracer.Instance, Security.Instance, Iast.Iast.Instance, spanCodeOrigin: null));
#if NET6_0_OR_GREATER
if (Tracer.Instance.Settings.SingleSpanAspNetCoreEnabled)
{
observers.Add(new SingleSpanAspNetCoreDiagnosticObserver(Tracer.Instance, Security.Instance, Iast.Iast.Instance, null));
}
else
#endif
{
observers.Add(new AspNetCoreDiagnosticObserver(Tracer.Instance, Security.Instance, Iast.Iast.Instance, spanCodeOrigin: null));
}

observers.Add(new QuartzDiagnosticObserver());
}

Expand Down
24 changes: 22 additions & 2 deletions tracer/src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,23 @@ not null when string.Equals(value, "otlp", StringComparison.OrdinalIgnoreCase) =
.WithKeys(ConfigurationKeys.FeatureFlags.RouteTemplateResourceNamesEnabled)
.AsBool(defaultValue: true);

SingleSpanAspNetCoreEnabled = config
.WithKeys(ConfigurationKeys.FeatureFlags.SingleSpanAspNetCoreEnabled)
.AsBool(defaultValue: false);
#if !NET6_0_OR_GREATER
// single span aspnetcore is only supported in .NET 6+, so override for telemetry purposes
if (SingleSpanAspNetCoreEnabled)
{
SingleSpanAspNetCoreEnabled = false;
Log.Warning(
$"{ConfigurationKeys.FeatureFlags.SingleSpanAspNetCoreEnabled} is set to true, but is only supported in .NET 6+. Using false instead.");
telemetry.Record(ConfigurationKeys.FeatureFlags.SingleSpanAspNetCoreEnabled, false, ConfigurationOrigins.Calculated);
}
#endif

ExpandRouteTemplatesEnabled = config
.WithKeys(ConfigurationKeys.ExpandRouteTemplatesEnabled)
.AsBool(defaultValue: !RouteTemplateResourceNamesEnabled); // disabled by default if route template resource names enabled
.AsBool(defaultValue: !(RouteTemplateResourceNamesEnabled || SingleSpanAspNetCoreEnabled)); // disabled by default if route template resource names or single-span enabled

AzureServiceBusBatchLinksEnabled = config
.WithKeys(ConfigurationKeys.AzureServiceBusBatchLinksEnabled)
Expand Down Expand Up @@ -1089,10 +1103,16 @@ not null when string.Equals(value, "otlp", StringComparison.OrdinalIgnoreCase) =

/// <summary>
/// Gets a value indicating whether resource names for ASP.NET and ASP.NET Core spans should be expanded. Only applies
/// when <see cref="RouteTemplateResourceNamesEnabled"/> is <code>true</code>.
/// when <see cref="RouteTemplateResourceNamesEnabled"/> or <see cref="SingleSpanAspNetCoreEnabled"/> are <code>true</code>.
/// </summary>
internal bool ExpandRouteTemplatesEnabled { get; }

/// <summary>
/// Gets a value indicating whether single-span ASP.NET Core instrumentation should be used.
/// </summary>
/// <seealso cref="ConfigurationKeys.FeatureFlags.SingleSpanAspNetCoreEnabled"/>
internal bool SingleSpanAspNetCoreEnabled { get; }

/// <summary>
/// Gets the direct log submission settings.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@
"env_var": "DD_SITE",
"const_name": "Site"
},
{
"env_var": "DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLED",
"const_name": "SingleSpanAspNetCoreEnabled"
},
{
"env_var": "DD_SPAN_SAMPLING_RULES",
"const_name": "SpanSamplingRules"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,14 @@ DD_TRACE_SERVICE_MAPPING: |
Configuration key for a map of services to rename.
<seealso cref="Datadog.Trace.Configuration.MutableSettings.ServiceNameMappings"/>

DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLED: |
Feature Flag: Enables generating only a single span in the ASP.NET Core integration,
by only creating `aspnet_core.request` spans, without creating handler spans or tracking
specific route values. Defaults to <c>false</c>. Not compatible with
DD_TRACE_ROUTE_TEMPLATE_RESOURCE_NAMES_ENABLED (that value is ignored), but may be used
with DD_TRACE_EXPAND_ROUTE_TEMPLATES_ENABLED. Only supported on .NET 6+.
<seealso cref="Datadog.Trace.Configuration.TracerSettings.SingleSpanAspNetCoreEnabled"/>

DD_TRACE_SPAN_ATTRIBUTE_SCHEMA: |
Configuration key for setting the schema version for service naming and span attributes
Accepted values are: "v1", "v0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,12 @@
"A"
]
},
"DD_TRACE_SINGLE_SPAN_ASPNETCORE_ENABLED": {
"version": [
"A"
],
"product": "FeatureFlags"
},
"DD_TRACE_SPAN_ATTRIBUTE_SCHEMA": {
"version": [
"A"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ private void OnMvcBeforeAction(object arg)
}
}

private bool TryGetTypeAndMethod(BeforeActionStruct beforeAction, out Type type, out MethodInfo method)
internal static bool TryGetTypeAndMethod(BeforeActionStruct beforeAction, [NotNullWhen(true)] out Type type, [NotNullWhen(true)] out MethodInfo method)
{
try
{
Expand Down
Loading
Loading