Skip to content

Track the source of installation #8956

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 2 commits into from
Jun 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
public final class AgentBootstrap {
static final String LIB_INJECTION_ENABLED_ENV_VAR = "DD_INJECTION_ENABLED";
static final String LIB_INJECTION_FORCE_SYS_PROP = "dd.inject.force";
static final String LIB_INSTRUMENTATION_SOURCE_SYS_PROP = "dd.instrumentation.source";

private static final Class<?> thisClass = AgentBootstrap.class;
private static final int MAX_EXCEPTION_CHAIN_LENGTH = 99;
Expand Down Expand Up @@ -134,6 +135,12 @@ private static void agentmainImpl(
return;
}

if (getConfig(LIB_INJECTION_ENABLED_ENV_VAR)) {
recordInstrumentationSource("ssi");
} else {
recordInstrumentationSource("cmd_line");
}

final URL agentJarURL = installAgentJar(inst);
final Class<?> agentClass;
try {
Expand Down Expand Up @@ -164,6 +171,10 @@ static boolean getConfig(String configName) {
}
}

private static void recordInstrumentationSource(String source) {
SystemUtils.trySetProperty(LIB_INSTRUMENTATION_SOURCE_SYS_PROP, source);
}

static boolean exceptionCauseChainContains(Throwable ex, String exClassName) {
Set<Throwable> stack = Collections.newSetFromMap(new IdentityHashMap<>());
Throwable t = ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public static String tryGetProperty(String property) {
}
}

public static String trySetProperty(String property, String value) {
try {
return System.setProperty(property, value);
} catch (SecurityException e) {
return null;
}
}

public static String getPropertyOrDefault(String property, String defaultValue) {
try {
return System.getProperty(property, defaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public final class ConfigDefaults {
static final boolean DEFAULT_TELEMETRY_LOG_COLLECTION_ENABLED = true;
static final int DEFAULT_TELEMETRY_DEPENDENCY_RESOLUTION_QUEUE_SIZE = 100000;

static final boolean DEFAULT_SSI_INJECTION_FORCE = false;
static final String DEFAULT_INSTRUMENTATION_SOURCE = "manual";

static final Set<String> DEFAULT_TRACE_EXPERIMENTAL_FEATURES_ENABLED =
new HashSet<>(
asList("DD_TAGS", "DD_LOGS_INJECTION", "DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@ public final class GeneralConfig {

public static final String STACK_TRACE_LENGTH_LIMIT = "stack.trace.length.limit";

public static final String SSI_INJECTION_ENABLED = "injection.enabled";
public static final String SSI_INJECTION_FORCE = "inject.force";
public static final String INSTRUMENTATION_SOURCE = "instrumentation.source";

private GeneralConfig() {}
}
11 changes: 11 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public static String getHostName() {

private final boolean traceGitMetadataEnabled;

private final boolean ssiInjectionForce;
private final String ssiInjectionEnabled;
private final String instrumentationSource;

private final Map<String, String> traceSamplingServiceRules;
private final Map<String, String> traceSamplingOperationRules;
private final String traceSamplingRules;
Expand Down Expand Up @@ -2041,6 +2045,13 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
"AppSec SCA is enabled but telemetry is disabled. AppSec SCA will not work.");
}

// Used to report telemetry on SSI injection
this.ssiInjectionEnabled = configProvider.getString(SSI_INJECTION_ENABLED);
this.ssiInjectionForce =
configProvider.getBoolean(SSI_INJECTION_FORCE, DEFAULT_SSI_INJECTION_FORCE);
this.instrumentationSource =
configProvider.getString(INSTRUMENTATION_SOURCE, DEFAULT_INSTRUMENTATION_SOURCE);

this.apmTracingEnabled = configProvider.getBoolean(GeneralConfig.APM_TRACING_ENABLED, true);

this.jdkSocketEnabled = configProvider.getBoolean(JDK_SOCKET_ENABLED, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import static datadog.trace.api.config.GeneralConfig.SITE
import static datadog.trace.api.config.GeneralConfig.TAGS
import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_IGNORED_RESOURCES
import static datadog.trace.api.config.GeneralConfig.VERSION
import static datadog.trace.api.config.GeneralConfig.SSI_INJECTION_ENABLED
import static datadog.trace.api.config.GeneralConfig.SSI_INJECTION_FORCE
import static datadog.trace.api.config.GeneralConfig.INSTRUMENTATION_SOURCE
import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_CHECK_PERIOD
import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_ENABLED
import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_METRICS_CONFIGS
Expand Down Expand Up @@ -2597,6 +2600,36 @@ class ConfigTest extends DDSpecification {
"450" | 450
}

def "ssi injection enabled"() {
when:
def prop = new Properties()
prop.setProperty(SSI_INJECTION_ENABLED, "tracer")
Config config = Config.get(prop)

then:
config.ssiInjectionEnabled == "tracer"
}

def "ssi inject force"() {
when:
def prop = new Properties()
prop.setProperty(SSI_INJECTION_FORCE, "true")
Config config = Config.get(prop)

then:
config.ssiInjectionForce == true
}

def "instrumentation source"() {
when:
def prop = new Properties()
prop.setProperty(INSTRUMENTATION_SOURCE, "ssi")
Config config = Config.get(prop)

then:
config.instrumentationSource == "ssi"
}

def "long running trace invalid flush_interval set to default: #configuredFlushInterval"() {
when:
def prop = new Properties()
Expand Down
Loading