Skip to content

chore(telemetry): track whether tracing was enabled via ssi #6938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tracer/src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,20 @@ _ when x.ToBoolean() is { } boolean => boolean,
telemetry.Record(ConfigTelemetryData.SsiInjectionEnabled, value: EnvironmentHelpers.GetEnvironmentVariable("DD_INJECTION_ENABLED"), recordValue: true, ConfigurationOrigins.EnvVars);
telemetry.Record(ConfigTelemetryData.SsiAllowUnsupportedRuntimesEnabled, value: EnvironmentHelpers.GetEnvironmentVariable("DD_INJECT_FORCE"), recordValue: true, ConfigurationOrigins.EnvVars);

var installType = EnvironmentHelpers.GetEnvironmentVariable("DD_INSTRUMENTATION_INSTALL_TYPE");

var instrumentationSource = installType switch
{
"dd_dotnet_launcher" => "cmd_line",
"dd_trace_tool" => "cmd_line",
"dotnet_msi" => "env_var",
"windows_fleet_installer" => "ssi", // windows SSI on IIS
_ when !string.IsNullOrEmpty(EnvironmentHelpers.GetEnvironmentVariable("DD_INJECTION_ENABLED")) => "ssi", // "normal" ssi
_ => "unknown" // everything else
};

telemetry.Record(ConfigTelemetryData.InstrumentationSource, instrumentationSource, recordValue: true, ConfigurationOrigins.Calculated);

if (AzureAppServiceMetadata is not null)
{
telemetry.Record(ConfigTelemetryData.AasConfigurationError, AzureAppServiceMetadata.IsUnsafeToTrace, ConfigurationOrigins.Default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal static class ConfigTelemetryData
public const string CodeHotspotsEnabled = "code_hotspots_enabled";

public const string SsiInjectionEnabled = "ssi_injection_enabled";
public const string InstrumentationSource = "instrumentation_source";
public const string SsiAllowUnsupportedRuntimesEnabled = "ssi_forced_injection_enabled";

// We intentionally are using specific values here, not OR_GREATER_THAN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Datadog.Trace.Configuration.Telemetry;
using Datadog.Trace.Iast.Settings;
using Datadog.Trace.Telemetry;
using Datadog.Trace.TestHelpers;
using FluentAssertions;
using FluentAssertions.Execution;
using Moq;
Expand All @@ -21,6 +22,8 @@

namespace Datadog.Trace.Tests.Telemetry;

[Collection(nameof(EnvironmentVariablesTestCollection))]
[EnvironmentRestorer("DD_INJECTION_ENABLED", "DD_INJECT_FORCE")]
public class ConfigurationTelemetryCollectorTests
{
public static IEnumerable<object[]> GetPropagatorConfigurations()
Expand Down Expand Up @@ -238,6 +241,23 @@ public void ConfigurationDataShouldReportDefaultValues()
GetLatestValueFromConfig(data, "DD_TRACE_HEADER_TAGS", ConfigurationOrigins.Default).Should().Be(string.Empty);
GetLatestValueFromConfig(data, "DD_LOGS_INJECTION", ConfigurationOrigins.Default).Should().Be(false);
GetLatestValueFromConfig(data, "DD_TRACE_SAMPLE_RATE", ConfigurationOrigins.Default).Should().Be(1.0);
GetLatestValueFromConfig(data, "instrumentation_source").Should().Be("unknown");
}

[Fact]
public void ConfigurationDataShouldReportSSIValues()
{
Environment.SetEnvironmentVariable("DD_INJECTION_ENABLED", "tracer");
Environment.SetEnvironmentVariable("DD_INJECT_FORCE", "true");

var collector = new ConfigurationTelemetry();
var source = new NameValueConfigurationSource(new NameValueCollection());
_ = new TracerSettings(source, collector, new OverrideErrorLog());
_ = new SecuritySettings(source, collector);
var data = collector.GetData();
GetLatestValueFromConfig(data, ConfigTelemetryData.SsiInjectionEnabled).Should().Be("tracer");
GetLatestValueFromConfig(data, ConfigTelemetryData.SsiAllowUnsupportedRuntimesEnabled).Should().Be("true");
GetLatestValueFromConfig(data, ConfigTelemetryData.InstrumentationSource).Should().Be("ssi");
}

#if NETFRAMEWORK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@
"dd_trace_writer_max_payload_size_bytes": "trace_agent_max_payload_size",
"dd_trace_writer_reuse_connections": "trace_agent_reuse_connections",
"tracing_enabled": "trace_enabled",
"instrumentation_source": "instrumentation_source",
"ssi_injection_enabled": "ssi_injection_enabled",
"DD_INJECTION_ENABLED": "ssi_injection_enabled",
"ssi_forced_injection_enabled": "ssi_forced_injection_enabled",
Expand Down
Loading