From 4458e57ab4373c36695bc2d9dbaef6f19b1f5d9b Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Fri, 26 Jan 2024 22:04:08 +0100 Subject: [PATCH 1/2] Fix incorrect hard-coded env var name in Java tracer configurator --- .../plugins/datadog/tracer/JavaConfigurator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java b/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java index 99f221373..f6193cb8d 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java @@ -13,12 +13,15 @@ import java.util.Map; import java.util.concurrent.TimeUnit; 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.tracer.signature.SignatureVerifier; final class JavaConfigurator implements TracerConfigurator { + private static final Logger LOGGER = Logger.getLogger(DatadogTracerConfigurator.class.getName()); + private static final String TRACER_DISTRIBUTION_URL_ENV_VAR = "DATADOG_JENKINS_PLUGIN_TRACER_DISTRIBUTION_URL"; private static final String DEFAULT_TRACER_DISTRIBUTION_URL = "https://dtdg.co/latest-java-tracer"; private static final String TRACER_FILE_NAME = "dd-java-agent.jar"; @@ -94,7 +97,12 @@ private byte[] getTracerSignaturePublicKey(DatadogTracerJobProperty tracerCon private T getSetting(DatadogTracerJobProperty tracerConfig, String envVariableName, T defaultValue, Function parser) { String envVariable = getEnvVariable(tracerConfig, envVariableName); if (envVariable != null) { - return parser.apply(envVariable); + try { + return parser.apply(envVariable); + } catch (Exception e) { + LOGGER.fine("Variable " + envVariableName + " has value " + envVariable + " which could not be parsed. " + + "Will use default value " + defaultValue); + } } return defaultValue; } @@ -107,7 +115,7 @@ private String getEnvVariable(DatadogTracerJobProperty tracerConfig, String n return envVariable; } } - return System.getenv(TRACER_JAR_CACHE_TTL_ENV_VAR); + return System.getenv(name); } private String validateUserSuppliedTracerUrl(String distributionUrl) { From 4b2d111ff47a337f44f84431a5770dbe00299e68 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Fri, 2 Feb 2024 12:53:05 +0100 Subject: [PATCH 2/2] Do not log env var values --- .../jenkins/plugins/datadog/tracer/JavaConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java b/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java index f6193cb8d..6ae425579 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/tracer/JavaConfigurator.java @@ -100,7 +100,7 @@ private T getSetting(DatadogTracerJobProperty tracerConfig, String envVar try { return parser.apply(envVariable); } catch (Exception e) { - LOGGER.fine("Variable " + envVariableName + " has value " + envVariable + " which could not be parsed. " + + LOGGER.fine("Variable " + envVariableName + " has value which could not be parsed. " + "Will use default value " + defaultValue); } }