Skip to content
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

Update APM auto-instrumentation to match any Java process #433

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 @@ -111,6 +111,7 @@ private static TopLevelItem getTopLevelItem(Run<?, ?> run) {
private static Map<String, String> getCommonEnvVariables(DatadogGlobalConfiguration datadogConfig,
DatadogTracerJobProperty<?> tracerConfig) {
Map<String, String> variables = new HashMap<>();
variables.put("DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER", "jenkins");
variables.put("DD_CIVISIBILITY_ENABLED", "true");
variables.put("DD_ENV", "ci");
variables.put("DD_SERVICE", tracerConfig.getServiceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.util.function.Function;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;
import org.datadog.jenkins.plugins.datadog.apm.signature.SignatureVerifier;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;

final class JavaConfigurator implements TracerConfigurator {

Expand Down Expand Up @@ -153,12 +153,11 @@ private static Map<String, String> getEnvVariables(DatadogTracerJobProperty<?> t
Map<String, String> variables = new HashMap<>();

String tracerAgent = "-javaagent:" + tracerFile.getRemote();
variables.put("MAVEN_OPTS", PropertyUtils.prepend(envs, "MAVEN_OPTS", tracerAgent));
variables.put("GRADLE_OPTS", PropertyUtils.prepend(envs, "GRADLE_OPTS", "-Dorg.gradle.jvmargs=" + tracerAgent));
variables.put("JAVA_TOOL_OPTIONS", PropertyUtils.prepend(envs, "JAVA_TOOL_OPTIONS", tracerAgent));

String proxyConfiguration = getProxyConfiguration(tracerConfig, node);
if (proxyConfiguration != null) {
variables.put("JAVA_TOOL_OPTIONS", PropertyUtils.prepend(envs, "JAVA_TOOL_OPTIONS", proxyConfiguration));
variables.put("JAVA_TOOL_OPTIONS", PropertyUtils.prepend(variables, "JAVA_TOOL_OPTIONS", proxyConfiguration));
}

Map<String, String> additionalVariables = tracerConfig.getAdditionalVariables();
Expand Down Expand Up @@ -197,19 +196,19 @@ private static String getProxyConfiguration(DatadogTracerJobProperty<?> tracerCo

StringBuilder proxyOptions = new StringBuilder();
if (proxyHost != null) {
proxyOptions.append("-Dhttp.proxyHost=").append(proxyHost);
proxyOptions.append("-Dhttp.proxyHost=").append(proxyHost).append(" ");
}
if (proxyPort > 0) {
proxyOptions.append("-Dhttp.proxyPort=").append(proxyPort);
proxyOptions.append("-Dhttp.proxyPort=").append(proxyPort).append(" ");
}
if (noProxyHost != null) {
proxyOptions.append("-Dhttp.nonProxyHosts=").append(noProxyHost);
proxyOptions.append("-Dhttp.nonProxyHosts=").append(noProxyHost).append(" ");
}
if (userName != null) {
proxyOptions.append("-Dhttp.proxyUser=").append(userName);
proxyOptions.append("-Dhttp.proxyUser=").append(userName).append(" ");
}
if (password != null) {
proxyOptions.append("-Dhttp.proxyPassword=").append(Secret.toString(password));
proxyOptions.append("-Dhttp.proxyPassword=").append(Secret.toString(password)).append(" ");
}
return proxyOptions.length() > 0 ? proxyOptions.toString() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<strong>Java</strong>
<p>
Injection works for any JVM-based language (Java, Kotlin, Groovy, Scala, etc).
Any Maven or Gradle build that the job executes will be traced.
Any Java process will be traced.
</p>
<p>
<code>MAVEN_OPTS</code> and <code>GRADLE_OPTS</code> environment variables are used for injection.
If these variables are overridden inside the job (with their existing value being discarded rather than preserved),
the injection will not happen.
<code>JAVA_TOOL_OPTIONS</code> environment variable is used for injection.
If this variable is overridden inside the job (with its existing value being discarded rather than preserved),
the injection will not work.
</p>

<strong>JS</strong>
Expand Down
Loading