From 4f5ca1139130cf4f84cb9b34130b91eb834a7c32 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:20:12 +0100 Subject: [PATCH] Fix incorrect hard-coded env var name in Java tracer configurator (#382) --- .../plugins/datadog/apm/JavaConfigurator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/JavaConfigurator.java b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/JavaConfigurator.java index b72410e6..da6c7831 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/apm/JavaConfigurator.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/apm/JavaConfigurator.java @@ -14,12 +14,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.apm.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"; @@ -98,7 +101,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 which could not be parsed. " + + "Will use default value " + defaultValue); + } } return defaultValue; } @@ -111,7 +119,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) {