Skip to content

Commit

Permalink
Fail fast when tracer versions do not match in parent and child proce…
Browse files Browse the repository at this point in the history
…sses (#6168)
  • Loading branch information
nikita-tkachenko-datadog authored and jandro996 committed Nov 14, 2023
1 parent 3c52748 commit f0f76c8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.civisibility;

import datadog.communication.ddagent.SharedCommunicationObjects;
import datadog.communication.ddagent.TracerVersion;
import datadog.trace.api.Config;
import datadog.trace.api.civisibility.CIVisibility;
import datadog.trace.api.civisibility.InstrumentationBridge;
Expand Down Expand Up @@ -52,6 +53,7 @@
import datadog.trace.civisibility.source.index.RepoIndexProvider;
import datadog.trace.civisibility.source.index.RepoIndexSourcePathResolver;
import datadog.trace.util.Strings;
import datadog.trace.util.throwable.FatalAgentMisconfigurationError;
import java.net.InetSocketAddress;
import java.nio.file.FileSystems;
import java.nio.file.Path;
Expand All @@ -74,6 +76,17 @@ public static void start(SharedCommunicationObjects sco) {
return;
}

String injectedTracerVersion = config.getCiVisibilityInjectedTracerVersion();
if (injectedTracerVersion != null
&& !injectedTracerVersion.equals(TracerVersion.TRACER_VERSION)) {
throw new FatalAgentMisconfigurationError(
"Running JVM with tracer version "
+ TracerVersion.TRACER_VERSION
+ " however parent process attempted to inject "
+ injectedTracerVersion
+ ". Do not inject the tracer into the forked JVMs manually, or ensure the manually injected version is the same as the one injected automatically");
}

sco.createRemaining(config);

GitClient.Factory gitClientFactory = buildGitClientFactory(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.civisibility.config;

import datadog.communication.ddagent.TracerVersion;
import datadog.trace.api.Config;
import datadog.trace.api.civisibility.config.Configurations;
import datadog.trace.api.civisibility.config.ModuleExecutionSettings;
Expand Down Expand Up @@ -156,6 +157,11 @@ private Map<String, String> getPropertiesPropagatedToChildProcess(
CiVisibilityConfig.CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED),
Boolean.toString(false));

propagatedSystemProperties.put(
Strings.propertyNameToSystemPropertyName(
CiVisibilityConfig.CIVISIBILITY_INJECTED_TRACER_VERSION),
TracerVersion.TRACER_VERSION);

return propagatedSystemProperties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public final class CiVisibilityConfig {
"civisibility.module.execution.settings.cache.size";
public static final String CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED =
"civisibility.coverage.segments.enabled";
public static final String CIVISIBILITY_INJECTED_TRACER_VERSION =
"civisibility.injected.tracer.version";

private CiVisibilityConfig() {}
}
8 changes: 8 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 @@ -155,6 +155,7 @@
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UNSHALLOW_ENABLED;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_TIMEOUT_MILLIS;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_INJECTED_TRACER_VERSION;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_ITR_ENABLED;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_JACOCO_GRADLE_SOURCE_SETS;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_JACOCO_PLUGIN_EXCLUDES;
Expand Down Expand Up @@ -716,6 +717,7 @@ static class HostNameHolder {
private final boolean ciVisibilityRepoIndexSharingEnabled;
private final int ciVisibilityModuleExecutionSettingsCacheSize;
private final boolean ciVisibilityCoverageSegmentsEnabled;
private final String ciVisibilityInjectedTracerVersion;

private final boolean remoteConfigEnabled;
private final boolean remoteConfigIntegrityCheckEnabled;
Expand Down Expand Up @@ -1651,6 +1653,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
configProvider.getInteger(CIVISIBILITY_MODULE_EXECUTION_SETTINGS_CACHE_SIZE, 16);
ciVisibilityCoverageSegmentsEnabled =
configProvider.getBoolean(CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED, false);
ciVisibilityInjectedTracerVersion =
configProvider.getString(CIVISIBILITY_INJECTED_TRACER_VERSION);

remoteConfigEnabled =
configProvider.getBoolean(REMOTE_CONFIG_ENABLED, DEFAULT_REMOTE_CONFIG_ENABLED);
Expand Down Expand Up @@ -2733,6 +2737,10 @@ public boolean isCiVisibilityCoverageSegmentsEnabled() {
return ciVisibilityCoverageSegmentsEnabled;
}

public String getCiVisibilityInjectedTracerVersion() {
return ciVisibilityInjectedTracerVersion;
}

public String getAppSecRulesFile() {
return appSecRulesFile;
}
Expand Down

0 comments on commit f0f76c8

Please sign in to comment.