From 201bcbe8ed2faadfabe4d1a673f65d4db39ad47b Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:48:11 +0200 Subject: [PATCH] Use remote service to get CI provider info when configured to do so (#7689) --- .../communication/BackendApiFactory.java | 9 +- .../java/datadog/communication/IntakeApi.java | 5 +- .../ddagent/SharedCommunicationObjects.java | 16 +- .../civisibility/CiVisibilityServices.java | 84 ++- .../trace/civisibility/ci/AppVeyorInfo.java | 41 +- .../civisibility/ci/AwsCodePipelineInfo.java | 11 +- .../civisibility/ci/AzurePipelinesInfo.java | 49 +- .../trace/civisibility/ci/BitBucketInfo.java | 29 +- .../trace/civisibility/ci/BitriseInfo.java | 38 +- .../trace/civisibility/ci/BuddyInfo.java | 31 +- .../trace/civisibility/ci/BuildkiteInfo.java | 37 +- .../datadog/trace/civisibility/ci/CIInfo.java | 13 +- .../ci/CIProviderInfoFactory.java | 71 +-- .../trace/civisibility/ci/CircleCIInfo.java | 27 +- .../trace/civisibility/ci/CodefreshInfo.java | 27 +- .../trace/civisibility/ci/GitLabInfo.java | 43 +- .../civisibility/ci/GithubActionsInfo.java | 50 +- .../trace/civisibility/ci/JenkinsInfo.java | 35 +- .../trace/civisibility/ci/TeamcityInfo.java | 13 +- .../trace/civisibility/ci/TravisInfo.java | 38 +- .../trace/civisibility/ci/UnknownCIInfo.java | 11 +- .../civisibility/ci/env/CiEnvironment.java | 10 + .../ci/env/CiEnvironmentImpl.java | 22 + .../ci/env/CompositeCiEnvironment.java | 35 ++ .../git/CIProviderGitInfoBuilder.java | 12 +- .../CiVisibilityServicesTest.groovy | 33 ++ .../ci/CIProviderInfoFactoryTest.groovy | 3 +- .../civisibility/ci/CITagsProviderTest.groovy | 13 +- .../ci/GithubActionsInfoTest.groovy | 3 +- .../civisibility/ci/UnknownCIInfoTest.groovy | 7 +- .../ci/env/CiEnvironmentImplTest.groovy | 25 + .../ci/env/CompositeCiEnvironmentTest.groovy | 41 ++ .../config/ConfigurationApiImplTest.groovy | 4 +- .../git/CIProviderGitInfoBuilderTest.groovy | 5 +- .../trace/api/config/CiVisibilityConfig.java | 4 + .../trace/common/writer/WriterFactory.java | 1 + .../common/writer/ddintake/DDIntakeApi.java | 2 +- .../main/java/datadog/trace/api/Config.java | 539 +----------------- 38 files changed, 665 insertions(+), 772 deletions(-) create mode 100644 dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironment.java create mode 100644 dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironmentImpl.java create mode 100644 dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CompositeCiEnvironment.java create mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/CiVisibilityServicesTest.groovy create mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CiEnvironmentImplTest.groovy create mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CompositeCiEnvironmentTest.groovy diff --git a/communication/src/main/java/datadog/communication/BackendApiFactory.java b/communication/src/main/java/datadog/communication/BackendApiFactory.java index 296d22cb36f..f60eaa7e215 100644 --- a/communication/src/main/java/datadog/communication/BackendApiFactory.java +++ b/communication/src/main/java/datadog/communication/BackendApiFactory.java @@ -34,8 +34,13 @@ public BackendApiFactory(Config config, SharedCommunicationObjects sharedCommuni "Agentless mode is enabled and api key is not set. Please set application key"); } String traceId = config.getIdGenerationStrategy().generateTraceId().toString(); - long timeoutMillis = config.getCiVisibilityBackendApiTimeoutMillis(); - return new IntakeApi(agentlessUrl, apiKey, traceId, timeoutMillis, retryPolicyFactory, true); + return new IntakeApi( + agentlessUrl, + apiKey, + traceId, + retryPolicyFactory, + sharedCommunicationObjects.okHttpClient, + true); } DDAgentFeaturesDiscovery featuresDiscovery = diff --git a/communication/src/main/java/datadog/communication/IntakeApi.java b/communication/src/main/java/datadog/communication/IntakeApi.java index ff29dc89124..3f1fe9df67f 100644 --- a/communication/src/main/java/datadog/communication/IntakeApi.java +++ b/communication/src/main/java/datadog/communication/IntakeApi.java @@ -37,16 +37,15 @@ public IntakeApi( HttpUrl hostUrl, String apiKey, String traceId, - long timeoutMillis, HttpRetryPolicy.Factory retryPolicyFactory, + OkHttpClient httpClient, boolean responseCompression) { this.hostUrl = hostUrl; this.apiKey = apiKey; this.traceId = traceId; this.retryPolicyFactory = retryPolicyFactory; this.responseCompression = responseCompression; - - httpClient = OkHttpUtils.buildHttpClient(hostUrl, timeoutMillis); + this.httpClient = httpClient; } @Override diff --git a/communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java b/communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java index 8c02098fe81..14de312dadc 100644 --- a/communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java +++ b/communication/src/main/java/datadog/communication/ddagent/SharedCommunicationObjects.java @@ -36,11 +36,21 @@ public void createRemaining(Config config) { } } if (okHttpClient == null) { - String unixDomainSocket = SocketUtils.discoverApmSocket(config); - String namedPipe = config.getAgentNamedPipe(); + String unixDomainSocket; + String namedPipe; + HttpUrl url; + if (!config.isCiVisibilityAgentlessEnabled()) { + unixDomainSocket = SocketUtils.discoverApmSocket(config); + namedPipe = config.getAgentNamedPipe(); + url = agentUrl; + } else { + unixDomainSocket = null; + namedPipe = null; + url = null; + } okHttpClient = OkHttpUtils.buildHttpClient( - agentUrl, unixDomainSocket, namedPipe, getHttpClientTimeout(config)); + url, unixDomainSocket, namedPipe, getHttpClientTimeout(config)); } } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java index 93e1271316b..31fd0ff0cfd 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java @@ -1,12 +1,20 @@ package datadog.trace.civisibility; +import com.squareup.moshi.JsonAdapter; +import com.squareup.moshi.Moshi; +import com.squareup.moshi.Types; import datadog.communication.BackendApi; import datadog.communication.BackendApiFactory; import datadog.communication.ddagent.SharedCommunicationObjects; +import datadog.communication.http.HttpRetryPolicy; +import datadog.communication.http.OkHttpUtils; import datadog.trace.api.Config; import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector; import datadog.trace.api.git.GitInfoProvider; import datadog.trace.civisibility.ci.CIProviderInfoFactory; +import datadog.trace.civisibility.ci.env.CiEnvironment; +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl; +import datadog.trace.civisibility.ci.env.CompositeCiEnvironment; import datadog.trace.civisibility.config.CachingJvmInfoFactory; import datadog.trace.civisibility.config.JvmInfoFactory; import datadog.trace.civisibility.config.JvmInfoFactoryImpl; @@ -19,19 +27,22 @@ import datadog.trace.civisibility.source.ByteCodeMethodLinesResolver; import datadog.trace.civisibility.source.CompilerAidedMethodLinesResolver; import datadog.trace.civisibility.source.MethodLinesResolver; -import datadog.trace.civisibility.source.index.CachingRepoIndexBuilderFactory; -import datadog.trace.civisibility.source.index.ConventionBasedResourceResolver; -import datadog.trace.civisibility.source.index.PackageResolver; -import datadog.trace.civisibility.source.index.PackageResolverImpl; -import datadog.trace.civisibility.source.index.RepoIndexFetcher; -import datadog.trace.civisibility.source.index.RepoIndexProvider; -import datadog.trace.civisibility.source.index.ResourceResolver; +import datadog.trace.civisibility.source.index.*; import datadog.trace.civisibility.utils.ProcessHierarchyUtils; +import java.lang.reflect.Type; import java.net.InetSocketAddress; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; +import java.util.Collections; +import java.util.Map; import javax.annotation.Nullable; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Services that do not need repository root location to be instantiated. Can be shared between @@ -39,8 +50,12 @@ */ public class CiVisibilityServices { + private static final Logger logger = LoggerFactory.getLogger(CiVisibilityServices.class); + private static final String GIT_FOLDER_NAME = ".git"; + static final String DD_ENV_VARS_PROVIDER_KEY_HEADER = "DD-Env-Vars-Provider-Key"; + final Config config; final CiVisibilityMetricCollector metricCollector; final BackendApi backendApi; @@ -63,13 +78,15 @@ public class CiVisibilityServices { new BackendApiFactory(config, sco).createBackendApi(BackendApiFactory.Intake.API); this.jvmInfoFactory = new CachingJvmInfoFactory(config, new JvmInfoFactoryImpl()); this.gitClientFactory = new GitClient.Factory(config, metricCollector); - this.ciProviderInfoFactory = new CIProviderInfoFactory(config); + + CiEnvironment environment = buildCiEnvironment(config, sco); + this.ciProviderInfoFactory = new CIProviderInfoFactory(config, environment); this.methodLinesResolver = new BestEffortMethodLinesResolver( new CompilerAidedMethodLinesResolver(), new ByteCodeMethodLinesResolver()); this.gitInfoProvider = gitInfoProvider; - gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder()); + gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder(config, environment)); gitInfoProvider.registerGitInfoBuilder( new CILocalGitInfoBuilder(gitClientFactory, GIT_FOLDER_NAME)); gitInfoProvider.registerGitInfoBuilder(new GitClientGitInfoBuilder(config, gitClientFactory)); @@ -94,6 +111,55 @@ public class CiVisibilityServices { } } + @NotNull + private static CiEnvironment buildCiEnvironment(Config config, SharedCommunicationObjects sco) { + String remoteEnvVarsProviderUrl = config.getCiVisibilityRemoteEnvVarsProviderUrl(); + if (remoteEnvVarsProviderUrl != null) { + String remoteEnvVarsProviderKey = config.getCiVisibilityRemoteEnvVarsProviderKey(); + CiEnvironment remoteEnvironment = + new CiEnvironmentImpl( + getRemoteEnvironment( + remoteEnvVarsProviderUrl, remoteEnvVarsProviderKey, sco.okHttpClient)); + CiEnvironment localEnvironment = new CiEnvironmentImpl(System.getenv()); + return new CompositeCiEnvironment(remoteEnvironment, localEnvironment); + } else { + return new CiEnvironmentImpl(System.getenv()); + } + } + + static Map getRemoteEnvironment(String url, String key, OkHttpClient httpClient) { + HttpRetryPolicy.Factory retryPolicyFactory = new HttpRetryPolicy.Factory(5, 100, 2.0, true); + + HttpUrl httpUrl = HttpUrl.get(url); + Request request = + new Request.Builder() + .url(httpUrl) + .header(DD_ENV_VARS_PROVIDER_KEY_HEADER, key) + .get() + .build(); + try (okhttp3.Response response = + OkHttpUtils.sendWithRetries(httpClient, retryPolicyFactory, request)) { + + if (response.isSuccessful()) { + Moshi moshi = new Moshi.Builder().build(); + Type type = Types.newParameterizedType(Map.class, String.class, String.class); + JsonAdapter> adapter = moshi.adapter(type); + return adapter.fromJson(response.body().source()); + } else { + logger.warn( + "Could not get remote CI environment (HTTP code " + + response.code() + + ")" + + (response.body() != null ? ": " + response.body().string() : "")); + return Collections.emptyMap(); + } + + } catch (Exception e) { + logger.warn("Could not get remote CI environment", e); + return Collections.emptyMap(); + } + } + CiVisibilityRepoServices repoServices(Path path) { return new CiVisibilityRepoServices(this, path); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java index 80315deb1d8..d5e97d581b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class AppVeyorInfo implements CIProviderInfo { @@ -31,13 +32,19 @@ class AppVeyorInfo implements CIProviderInfo { public static final String APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL = "APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"; + private final CiEnvironment environment; + + AppVeyorInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { - final String repoProvider = System.getenv(APPVEYOR_REPO_PROVIDER); - final String messageSubject = System.getenv(APPVEYOR_REPO_COMMIT_MESSAGE_SUBJECT); - final String messageBody = System.getenv(APPVEYOR_REPO_COMMIT_MESSAGE_BODY); + final String repoProvider = environment.get(APPVEYOR_REPO_PROVIDER); + final String messageSubject = environment.get(APPVEYOR_REPO_COMMIT_MESSAGE_SUBJECT); + final String messageBody = environment.get(APPVEYOR_REPO_COMMIT_MESSAGE_BODY); return new GitInfo( - buildGitRepositoryUrl(repoProvider, System.getenv(APPVEYOR_REPO_NAME)), + buildGitRepositoryUrl(repoProvider, environment.get(APPVEYOR_REPO_NAME)), buildGitBranch(repoProvider), buildGitTag(repoProvider), new CommitInfo( @@ -60,23 +67,23 @@ private static String getCommitMessage(String messageSubject, String messageBody @Override public CIInfo buildCIInfo() { final String url = - buildPipelineUrl(System.getenv(APPVEYOR_REPO_NAME), System.getenv(APPVEYOR_BUILD_ID)); - return CIInfo.builder() + buildPipelineUrl(environment.get(APPVEYOR_REPO_NAME), environment.get(APPVEYOR_BUILD_ID)); + return CIInfo.builder(environment) .ciProviderName(APPVEYOR_PROVIDER_NAME) - .ciPipelineId(System.getenv(APPVEYOR_BUILD_ID)) - .ciPipelineName(System.getenv(APPVEYOR_REPO_NAME)) - .ciPipelineNumber(System.getenv(APPVEYOR_PIPELINE_NUMBER)) + .ciPipelineId(environment.get(APPVEYOR_BUILD_ID)) + .ciPipelineName(environment.get(APPVEYOR_REPO_NAME)) + .ciPipelineNumber(environment.get(APPVEYOR_PIPELINE_NUMBER)) .ciPipelineUrl(url) .ciJobUrl(url) - .ciWorkspace(expandTilde(System.getenv(APPVEYOR_WORKSPACE_PATH))) + .ciWorkspace(expandTilde(environment.get(APPVEYOR_WORKSPACE_PATH))) .build(); } private String buildGitBranch(final String repoProvider) { if ("github".equals(repoProvider)) { - String branch = System.getenv(APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH); + String branch = environment.get(APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH); if (branch == null || branch.isEmpty()) { - branch = System.getenv(APPVEYOR_REPO_BRANCH); + branch = environment.get(APPVEYOR_REPO_BRANCH); } return normalizeBranch(branch); } @@ -85,14 +92,14 @@ private String buildGitBranch(final String repoProvider) { private String buildGitTag(final String repoProvider) { if ("github".equals(repoProvider)) { - return normalizeTag(System.getenv(APPVEYOR_REPO_TAG_NAME)); + return normalizeTag(environment.get(APPVEYOR_REPO_TAG_NAME)); } return null; } private String buildGitCommit() { - if ("github".equals(System.getenv(APPVEYOR_REPO_PROVIDER))) { - return System.getenv(APPVEYOR_REPO_COMMIT); + if ("github".equals(environment.get(APPVEYOR_REPO_PROVIDER))) { + return environment.get(APPVEYOR_REPO_COMMIT); } return null; } @@ -110,8 +117,8 @@ private String buildPipelineUrl(final String repoName, final String buildId) { private PersonInfo buildGitCommitAuthor() { return new PersonInfo( - System.getenv(APPVEYOR_REPO_COMMIT_AUTHOR_NAME), - System.getenv(APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL)); + environment.get(APPVEYOR_REPO_COMMIT_AUTHOR_NAME), + environment.get(APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL)); } @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AwsCodePipelineInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AwsCodePipelineInfo.java index fcae8d11248..72d672e0528 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AwsCodePipelineInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AwsCodePipelineInfo.java @@ -2,6 +2,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class AwsCodePipelineInfo implements CIProviderInfo { @@ -11,6 +12,12 @@ class AwsCodePipelineInfo implements CIProviderInfo { public static final String AWS_CODEPIPELINE_ACTION_EXECUTION_ID = "DD_ACTION_EXECUTION_ID"; public static final String AWS_CODEPIPELINE_ARN = "CODEBUILD_BUILD_ARN"; + private final CiEnvironment environment; + + AwsCodePipelineInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return GitInfo.NOOP; @@ -18,9 +25,9 @@ public GitInfo buildCIGitInfo() { @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(AWS_CODEPIPELINE_PROVIDER_NAME) - .ciPipelineId(System.getenv(AWS_CODEPIPELINE_EXECUTION_ID)) + .ciPipelineId(environment.get(AWS_CODEPIPELINE_EXECUTION_ID)) .ciEnvVars( AWS_CODEPIPELINE_EXECUTION_ID, AWS_CODEPIPELINE_ACTION_EXECUTION_ID, diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AzurePipelinesInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AzurePipelinesInfo.java index 65cabf1d603..708a6bea6be 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AzurePipelinesInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AzurePipelinesInfo.java @@ -10,6 +10,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class AzurePipelinesInfo implements CIProviderInfo { @@ -39,6 +40,12 @@ class AzurePipelinesInfo implements CIProviderInfo { public static final String AZURE_BUILD_REQUESTED_FOR_ID = "BUILD_REQUESTEDFORID"; public static final String AZURE_BUILD_REQUESTED_FOR_EMAIL = "BUILD_REQUESTEDFOREMAIL"; + private final CiEnvironment environment; + + AzurePipelinesInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( @@ -49,27 +56,27 @@ public GitInfo buildCIGitInfo() { buildGitCommit(), buildGitCommitAuthor(), PersonInfo.NOOP, - System.getenv(AZURE_BUILD_SOURCEVERSION_MESSAGE))); + environment.get(AZURE_BUILD_SOURCEVERSION_MESSAGE))); } @Override public CIInfo buildCIInfo() { - final String uri = System.getenv(AZURE_SYSTEM_TEAMFOUNDATIONSERVERURI); - final String project = System.getenv(AZURE_SYSTEM_TEAMPROJECTID); - final String buildId = System.getenv(AZURE_BUILD_BUILDID); - final String jobId = System.getenv(AZURE_SYSTEM_JOBID); - final String taskId = System.getenv(AZURE_SYSTEM_TASKINSTANCEID); + final String uri = environment.get(AZURE_SYSTEM_TEAMFOUNDATIONSERVERURI); + final String project = environment.get(AZURE_SYSTEM_TEAMPROJECTID); + final String buildId = environment.get(AZURE_BUILD_BUILDID); + final String jobId = environment.get(AZURE_SYSTEM_JOBID); + final String taskId = environment.get(AZURE_SYSTEM_TASKINSTANCEID); - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(AZURE_PROVIDER_NAME) - .ciPipelineId(System.getenv(AZURE_BUILD_BUILDID)) - .ciPipelineName(System.getenv(AZURE_PIPELINE_NAME)) + .ciPipelineId(environment.get(AZURE_BUILD_BUILDID)) + .ciPipelineName(environment.get(AZURE_PIPELINE_NAME)) .ciPipelineNumber(buildId) .ciPipelineUrl(buildCiPipelineUrl(uri, project, buildId)) - .ciStageName(System.getenv(AZURE_SYSTEM_STAGEDISPLAYNAME)) - .ciJobName(System.getenv(AZURE_SYSTEM_JOBDISPLAYNAME)) + .ciStageName(environment.get(AZURE_SYSTEM_STAGEDISPLAYNAME)) + .ciJobName(environment.get(AZURE_SYSTEM_JOBDISPLAYNAME)) .ciJobUrl(buildCiJobUrl(uri, project, buildId, jobId, taskId)) - .ciWorkspace(expandTilde(System.getenv(AZURE_WORKSPACE_PATH))) + .ciWorkspace(expandTilde(environment.get(AZURE_WORKSPACE_PATH))) .ciEnvVars(AZURE_SYSTEM_TEAMPROJECTID, AZURE_BUILD_BUILDID, AZURE_SYSTEM_JOBID) .build(); } @@ -92,26 +99,26 @@ private String buildGitTag() { } } - private static String getGitBranchOrTag() { - String gitBranchOrTag = System.getenv(AZURE_SYSTEM_PULLREQUEST_SOURCEBRANCH); + private String getGitBranchOrTag() { + String gitBranchOrTag = environment.get(AZURE_SYSTEM_PULLREQUEST_SOURCEBRANCH); if (gitBranchOrTag == null || gitBranchOrTag.isEmpty()) { - gitBranchOrTag = System.getenv(AZURE_BUILD_SOURCEBRANCH); + gitBranchOrTag = environment.get(AZURE_BUILD_SOURCEBRANCH); } return gitBranchOrTag; } private String buildGitCommit() { - String commit = System.getenv(AZURE_SYSTEM_PULLREQUEST_SOURCECOMMITID); + String commit = environment.get(AZURE_SYSTEM_PULLREQUEST_SOURCECOMMITID); if (commit == null || commit.isEmpty()) { - commit = System.getenv(AZURE_BUILD_SOURCEVERSION); + commit = environment.get(AZURE_BUILD_SOURCEVERSION); } return commit; } private String buildGitRepositoryUrl() { - String repoUrl = System.getenv(AZURE_SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI); + String repoUrl = environment.get(AZURE_SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI); if (repoUrl == null || repoUrl.isEmpty()) { - repoUrl = System.getenv(AZURE_BUILD_REPOSITORY_URI); + repoUrl = environment.get(AZURE_BUILD_REPOSITORY_URI); } return filterSensitiveInfo(repoUrl); } @@ -132,8 +139,8 @@ private String buildCiPipelineUrl(final String uri, final String project, final private PersonInfo buildGitCommitAuthor() { return new PersonInfo( - System.getenv(AZURE_BUILD_REQUESTED_FOR_ID), - System.getenv(AZURE_BUILD_REQUESTED_FOR_EMAIL)); + environment.get(AZURE_BUILD_REQUESTED_FOR_ID), + environment.get(AZURE_BUILD_REQUESTED_FOR_EMAIL)); } @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java index 80c1e705dc5..63b9eace1e5 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import datadog.trace.util.Strings; class BitBucketInfo implements CIProviderInfo { @@ -25,21 +26,27 @@ class BitBucketInfo implements CIProviderInfo { public static final String BITBUCKET_GIT_BRANCH = "BITBUCKET_BRANCH"; public static final String BITBUCKET_GIT_TAG = "BITBUCKET_TAG"; + private final CiEnvironment environment; + + BitBucketInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( getRepositoryURL(), - normalizeBranch(System.getenv(BITBUCKET_GIT_BRANCH)), - normalizeTag(System.getenv(BITBUCKET_GIT_TAG)), - new CommitInfo(System.getenv(BITBUCKET_GIT_COMMIT))); + normalizeBranch(environment.get(BITBUCKET_GIT_BRANCH)), + normalizeTag(environment.get(BITBUCKET_GIT_TAG)), + new CommitInfo(environment.get(BITBUCKET_GIT_COMMIT))); } - private static String getRepositoryURL() { - String gitRepoUrl = System.getenv(BITBUCKET_GIT_REPOSITORY_URL); + private String getRepositoryURL() { + String gitRepoUrl = environment.get(BITBUCKET_GIT_REPOSITORY_URL); if (Strings.isNotBlank(gitRepoUrl)) { return filterSensitiveInfo(gitRepoUrl); } - String httpsRepoUrl = System.getenv(BITBUCKET_HTTPS_REPOSITORY_URL); + String httpsRepoUrl = environment.get(BITBUCKET_HTTPS_REPOSITORY_URL); if (Strings.isNotBlank(httpsRepoUrl)) { return filterSensitiveInfo(httpsRepoUrl); } @@ -48,18 +55,18 @@ private static String getRepositoryURL() { @Override public CIInfo buildCIInfo() { - final String repo = System.getenv(BITBUCKET_REPO_FULL_NAME); - final String number = System.getenv(BITBUCKET_BUILD_NUMBER); + final String repo = environment.get(BITBUCKET_REPO_FULL_NAME); + final String number = environment.get(BITBUCKET_BUILD_NUMBER); final String url = buildPipelineUrl(repo, number); - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(BITBUCKET_PROVIDER_NAME) .ciPipelineId(buildPipelineId()) .ciPipelineName(repo) .ciPipelineNumber(number) .ciPipelineUrl(url) .ciJobUrl(url) - .ciWorkspace(expandTilde(System.getenv(BITBUCKET_WORKSPACE_PATH))) + .ciWorkspace(expandTilde(environment.get(BITBUCKET_WORKSPACE_PATH))) .build(); } @@ -69,7 +76,7 @@ private String buildPipelineUrl(final String repo, final String number) { } private String buildPipelineId() { - String id = System.getenv(BITBUCKET_PIPELINE_ID); + String id = environment.get(BITBUCKET_PIPELINE_ID); if (id != null) { id = Strings.replace(id, "{", ""); id = Strings.replace(id, "}", ""); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitriseInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitriseInfo.java index 7428fe5ff24..b5af995835a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitriseInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitriseInfo.java @@ -9,6 +9,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class BitriseInfo implements CIProviderInfo { @@ -30,40 +31,47 @@ class BitriseInfo implements CIProviderInfo { public static final String BITRISE_GIT_COMMITER_NAME = "GIT_CLONE_COMMIT_COMMITER_NAME"; public static final String BITRISE_GIT_COMMITER_EMAIL = "GIT_CLONE_COMMIT_COMMITER_EMAIL"; + private final CiEnvironment environment; + + BitriseInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( - filterSensitiveInfo(System.getenv(BITRISE_GIT_REPOSITORY_URL)), - normalizeBranch(System.getenv(BITRISE_GIT_BRANCH)), - normalizeTag(System.getenv(BITRISE_GIT_TAG)), + filterSensitiveInfo(environment.get(BITRISE_GIT_REPOSITORY_URL)), + normalizeBranch(environment.get(BITRISE_GIT_BRANCH)), + normalizeTag(environment.get(BITRISE_GIT_TAG)), new CommitInfo( buildGitCommit(), new PersonInfo( - System.getenv(BITRISE_GIT_AUTHOR_NAME), System.getenv(BITRISE_GIT_AUTHOR_EMAIL)), + environment.get(BITRISE_GIT_AUTHOR_NAME), + environment.get(BITRISE_GIT_AUTHOR_EMAIL)), new PersonInfo( - System.getenv(BITRISE_GIT_COMMITER_NAME), - System.getenv(BITRISE_GIT_COMMITER_EMAIL)), - System.getenv(BITRISE_GIT_MESSAGE))); + environment.get(BITRISE_GIT_COMMITER_NAME), + environment.get(BITRISE_GIT_COMMITER_EMAIL)), + environment.get(BITRISE_GIT_MESSAGE))); } @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(BITRISE_PROVIDER_NAME) - .ciPipelineId(System.getenv(BITRISE_PIPELINE_ID)) - .ciPipelineName(System.getenv(BITRISE_PIPELINE_NAME)) - .ciPipelineNumber(System.getenv(BITRISE_PIPELINE_NUMBER)) - .ciPipelineUrl(System.getenv(BITRISE_PIPELINE_URL)) - .ciWorkspace(expandTilde(System.getenv(BITRISE_WORKSPACE_PATH))) + .ciPipelineId(environment.get(BITRISE_PIPELINE_ID)) + .ciPipelineName(environment.get(BITRISE_PIPELINE_NAME)) + .ciPipelineNumber(environment.get(BITRISE_PIPELINE_NUMBER)) + .ciPipelineUrl(environment.get(BITRISE_PIPELINE_URL)) + .ciWorkspace(expandTilde(environment.get(BITRISE_WORKSPACE_PATH))) .build(); } private String buildGitCommit() { - final String fromCommit = System.getenv(BITRISE_GIT_PR_COMMIT); + final String fromCommit = environment.get(BITRISE_GIT_PR_COMMIT); if (fromCommit != null && !fromCommit.isEmpty()) { return fromCommit; } else { - return System.getenv(BITRISE_GIT_COMMIT); + return environment.get(BITRISE_GIT_COMMIT); } } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java index 2315f806f2f..8118c9c22c8 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class BuddyInfo implements CIProviderInfo { @@ -26,33 +27,39 @@ class BuddyInfo implements CIProviderInfo { public static final String BUDDY_GIT_COMMIT_AUTHOR = "BUDDY_EXECUTION_REVISION_COMMITTER_NAME"; public static final String BUDDY_GIT_COMMIT_EMAIL = "BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL"; + private final CiEnvironment environment; + + BuddyInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( - filterSensitiveInfo(System.getenv(BUDDY_GIT_REPOSITORY_URL)), - normalizeBranch(System.getenv(BUDDY_GIT_BRANCH)), - normalizeTag(System.getenv(BUDDY_GIT_TAG)), + filterSensitiveInfo(environment.get(BUDDY_GIT_REPOSITORY_URL)), + normalizeBranch(environment.get(BUDDY_GIT_BRANCH)), + normalizeTag(environment.get(BUDDY_GIT_TAG)), new CommitInfo( - System.getenv(BUDDY_GIT_COMMIT), + environment.get(BUDDY_GIT_COMMIT), PersonInfo.NOOP, buildGitCommiter(), - System.getenv(BUDDY_GIT_COMMIT_MESSAGE))); + environment.get(BUDDY_GIT_COMMIT_MESSAGE))); } @Override public CIInfo buildCIInfo() { - String pipelineNumber = System.getenv(BUDDY_PIPELINE_EXECUTION_ID); - return CIInfo.builder() + String pipelineNumber = environment.get(BUDDY_PIPELINE_EXECUTION_ID); + return CIInfo.builder(environment) .ciProviderName(BUDDY_PROVIDER_NAME) .ciPipelineId(getPipelineId(pipelineNumber)) - .ciPipelineName(System.getenv(BUDDY_PIPELINE_NAME)) + .ciPipelineName(environment.get(BUDDY_PIPELINE_NAME)) .ciPipelineNumber(pipelineNumber) - .ciPipelineUrl(System.getenv(BUDDY_PIPELINE_EXECUTION_URL)) + .ciPipelineUrl(environment.get(BUDDY_PIPELINE_EXECUTION_URL)) .build(); } - private static String getPipelineId(String pipelineNumber) { - String pipelineId = System.getenv(BUDDY_PIPELINE_ID); + private String getPipelineId(String pipelineNumber) { + String pipelineId = environment.get(BUDDY_PIPELINE_ID); if (pipelineId == null) { return pipelineNumber; } @@ -64,7 +71,7 @@ private static String getPipelineId(String pipelineNumber) { private PersonInfo buildGitCommiter() { return new PersonInfo( - System.getenv(BUDDY_GIT_COMMIT_AUTHOR), System.getenv(BUDDY_GIT_COMMIT_EMAIL)); + environment.get(BUDDY_GIT_COMMIT_AUTHOR), environment.get(BUDDY_GIT_COMMIT_EMAIL)); } @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java index 72ba40ee611..4aa2a6781b9 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java @@ -10,6 +10,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -36,32 +37,38 @@ class BuildkiteInfo implements CIProviderInfo { public static final String BUILDKITE_AGENT_ID = "BUILDKITE_AGENT_ID"; private static final String BUILDKITE_CI_NODE_LABEL_PREFIX = "BUILDKITE_AGENT_META_DATA_"; + private final CiEnvironment environment; + + BuildkiteInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( - filterSensitiveInfo(System.getenv(BUILDKITE_GIT_REPOSITORY_URL)), - normalizeBranch(System.getenv(BUILDKITE_GIT_BRANCH)), - normalizeTag(System.getenv(BUILDKITE_GIT_TAG)), + filterSensitiveInfo(environment.get(BUILDKITE_GIT_REPOSITORY_URL)), + normalizeBranch(environment.get(BUILDKITE_GIT_BRANCH)), + normalizeTag(environment.get(BUILDKITE_GIT_TAG)), new CommitInfo( - System.getenv(BUILDKITE_GIT_COMMIT), + environment.get(BUILDKITE_GIT_COMMIT), buildGitCommitAuthor(), PersonInfo.NOOP, - System.getenv(BUILDKITE_GIT_MESSAGE))); + environment.get(BUILDKITE_GIT_MESSAGE))); } @Override public CIInfo buildCIInfo() { - final String ciPipelineUrl = System.getenv(BUILDKITE_BUILD_URL); + final String ciPipelineUrl = environment.get(BUILDKITE_BUILD_URL); - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(BUILDKITE_PROVIDER_NAME) - .ciPipelineId(System.getenv(BUILDKITE_PIPELINE_ID)) - .ciPipelineName(System.getenv(BUILDKITE_PIPELINE_NAME)) - .ciPipelineNumber(System.getenv(BUILDKITE_PIPELINE_NUMBER)) + .ciPipelineId(environment.get(BUILDKITE_PIPELINE_ID)) + .ciPipelineName(environment.get(BUILDKITE_PIPELINE_NAME)) + .ciPipelineNumber(environment.get(BUILDKITE_PIPELINE_NUMBER)) .ciPipelineUrl(ciPipelineUrl) - .ciJobUrl(String.format("%s#%s", ciPipelineUrl, System.getenv(BUILDKITE_JOB_ID))) - .ciWorkspace(expandTilde(System.getenv(BUILDKITE_WORKSPACE_PATH))) - .ciNodeName(System.getenv(BUILDKITE_AGENT_ID)) + .ciJobUrl(String.format("%s#%s", ciPipelineUrl, environment.get(BUILDKITE_JOB_ID))) + .ciWorkspace(expandTilde(environment.get(BUILDKITE_WORKSPACE_PATH))) + .ciNodeName(environment.get(BUILDKITE_AGENT_ID)) .ciNodeLabels(buildCiNodeLabels()) .ciEnvVars(BUILDKITE_PIPELINE_ID, BUILDKITE_JOB_ID) .build(); @@ -69,7 +76,7 @@ public CIInfo buildCIInfo() { private String buildCiNodeLabels() { List labels = new ArrayList<>(); - for (Map.Entry e : System.getenv().entrySet()) { + for (Map.Entry e : environment.get().entrySet()) { String envVar = e.getKey(); if (envVar.startsWith(BUILDKITE_CI_NODE_LABEL_PREFIX)) { String labelKey = @@ -83,7 +90,7 @@ private String buildCiNodeLabels() { private PersonInfo buildGitCommitAuthor() { return new PersonInfo( - System.getenv(BUILDKITE_GIT_AUTHOR_NAME), System.getenv(BUILDKITE_GIT_AUTHOR_EMAIL)); + environment.get(BUILDKITE_GIT_AUTHOR_NAME), environment.get(BUILDKITE_GIT_AUTHOR_EMAIL)); } @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIInfo.java index 3c7ffc31825..9fb2bbfb81f 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIInfo.java @@ -2,6 +2,7 @@ import static datadog.trace.api.git.GitUtils.filterSensitiveInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import datadog.trace.civisibility.utils.FileUtils; import java.io.File; import java.util.HashMap; @@ -11,11 +12,13 @@ public class CIInfo { public static final CIInfo NOOP = new CIInfo(); - public static Builder builder() { - return new Builder(); + public static Builder builder(CiEnvironment environment) { + return new Builder(environment); } public static final class Builder { + private final CiEnvironment environment; + private String ciProviderName; private String ciPipelineId; private String ciPipelineName; @@ -30,6 +33,10 @@ public static final class Builder { private Map ciEnvVars; private Map additionalTags; + public Builder(CiEnvironment environment) { + this.environment = environment; + } + public Builder ciProviderName(String ciProviderName) { this.ciProviderName = ciProviderName; return this; @@ -92,7 +99,7 @@ public Builder ciEnvVars(String... ciEnvVarKeysArray) { ciEnvVars = new HashMap<>(); for (String ciEnvVarKey : ciEnvVarKeysArray) { - final String envVarVal = filterSensitiveInfo(System.getenv(ciEnvVarKey)); + final String envVarVal = filterSensitiveInfo(environment.get(ciEnvVarKey)); if (envVarVal != null && !envVarVal.isEmpty()) { ciEnvVars.put(ciEnvVarKey, envVarVal); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIProviderInfoFactory.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIProviderInfoFactory.java index 37a651678b7..df6dd218a88 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIProviderInfoFactory.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CIProviderInfoFactory.java @@ -1,61 +1,64 @@ package datadog.trace.civisibility.ci; import datadog.trace.api.Config; +import datadog.trace.civisibility.ci.env.CiEnvironment; import java.nio.file.Path; public class CIProviderInfoFactory { private final String targetFolder; private final Config config; + private final CiEnvironment environment; - public CIProviderInfoFactory(Config config) { - this(config, ".git"); + public CIProviderInfoFactory(Config config, CiEnvironment environment) { + this(config, ".git", environment); } - CIProviderInfoFactory(Config config, String targetFolder) { + CIProviderInfoFactory(Config config, String targetFolder, CiEnvironment environment) { this.targetFolder = targetFolder; this.config = config; + this.environment = environment; } public CIProviderInfo createCIProviderInfo(Path currentPath) { if (!config.isCiVisibilityCiProviderIntegrationEnabled()) { - return new UnknownCIInfo(targetFolder, currentPath); + return new UnknownCIInfo(environment, targetFolder, currentPath); } // CI and Git information is obtained // from different environment variables // depending on which CI server is running the build. - if (System.getenv(JenkinsInfo.JENKINS) != null) { - return new JenkinsInfo(); - } else if (System.getenv(GitLabInfo.GITLAB) != null) { - return new GitLabInfo(); - } else if (System.getenv(TravisInfo.TRAVIS) != null) { - return new TravisInfo(); - } else if (System.getenv(CircleCIInfo.CIRCLECI) != null) { - return new CircleCIInfo(); - } else if (System.getenv(AppVeyorInfo.APPVEYOR) != null) { - return new AppVeyorInfo(); - } else if (System.getenv(AzurePipelinesInfo.AZURE) != null) { - return new AzurePipelinesInfo(); - } else if (System.getenv(BitBucketInfo.BITBUCKET) != null) { - return new BitBucketInfo(); - } else if (System.getenv(GithubActionsInfo.GHACTIONS) != null) { - return new GithubActionsInfo(); - } else if (System.getenv(BuildkiteInfo.BUILDKITE) != null) { - return new BuildkiteInfo(); - } else if (System.getenv(BitriseInfo.BITRISE) != null) { - return new BitriseInfo(); - } else if (System.getenv(BuddyInfo.BUDDY) != null) { - return new BuddyInfo(); - } else if (System.getenv(CodefreshInfo.CODEFRESH) != null) { - return new CodefreshInfo(); - } else if (System.getenv(TeamcityInfo.TEAMCITY) != null) { - return new TeamcityInfo(); - } else if (System.getenv(AwsCodePipelineInfo.AWS_CODEPIPELINE) != null - && System.getenv(AwsCodePipelineInfo.AWS_CODEPIPELINE).startsWith("codepipeline")) { - return new AwsCodePipelineInfo(); + if (environment.get(JenkinsInfo.JENKINS) != null) { + return new JenkinsInfo(environment); + } else if (environment.get(GitLabInfo.GITLAB) != null) { + return new GitLabInfo(environment); + } else if (environment.get(TravisInfo.TRAVIS) != null) { + return new TravisInfo(environment); + } else if (environment.get(CircleCIInfo.CIRCLECI) != null) { + return new CircleCIInfo(environment); + } else if (environment.get(AppVeyorInfo.APPVEYOR) != null) { + return new AppVeyorInfo(environment); + } else if (environment.get(AzurePipelinesInfo.AZURE) != null) { + return new AzurePipelinesInfo(environment); + } else if (environment.get(BitBucketInfo.BITBUCKET) != null) { + return new BitBucketInfo(environment); + } else if (environment.get(GithubActionsInfo.GHACTIONS) != null) { + return new GithubActionsInfo(environment); + } else if (environment.get(BuildkiteInfo.BUILDKITE) != null) { + return new BuildkiteInfo(environment); + } else if (environment.get(BitriseInfo.BITRISE) != null) { + return new BitriseInfo(environment); + } else if (environment.get(BuddyInfo.BUDDY) != null) { + return new BuddyInfo(environment); + } else if (environment.get(CodefreshInfo.CODEFRESH) != null) { + return new CodefreshInfo(environment); + } else if (environment.get(TeamcityInfo.TEAMCITY) != null) { + return new TeamcityInfo(environment); + } else if (environment.get(AwsCodePipelineInfo.AWS_CODEPIPELINE) != null + && environment.get(AwsCodePipelineInfo.AWS_CODEPIPELINE).startsWith("codepipeline")) { + return new AwsCodePipelineInfo(environment); } else { - return new UnknownCIInfo(targetFolder, currentPath); + return new UnknownCIInfo(environment, targetFolder, currentPath); } } } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CircleCIInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CircleCIInfo.java index 690bcac6f38..f18fab7c949 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CircleCIInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CircleCIInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class CircleCIInfo implements CIProviderInfo { @@ -25,26 +26,32 @@ class CircleCIInfo implements CIProviderInfo { public static final String CIRCLECI_GIT_TAG = "CIRCLE_TAG"; public static final String CIRCLECI_JOB_NAME = "CIRCLE_JOB"; + private final CiEnvironment environment; + + CircleCIInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( - filterSensitiveInfo(System.getenv(CIRCLECI_GIT_REPOSITORY_URL)), - normalizeBranch(System.getenv(CIRCLECI_GIT_BRANCH)), - normalizeTag(System.getenv(CIRCLECI_GIT_TAG)), - new CommitInfo(System.getenv(CIRCLECI_GIT_COMMIT))); + filterSensitiveInfo(environment.get(CIRCLECI_GIT_REPOSITORY_URL)), + normalizeBranch(environment.get(CIRCLECI_GIT_BRANCH)), + normalizeTag(environment.get(CIRCLECI_GIT_TAG)), + new CommitInfo(environment.get(CIRCLECI_GIT_COMMIT))); } @Override public CIInfo buildCIInfo() { - final String pipelineId = System.getenv(CIRCLECI_PIPELINE_ID); - return CIInfo.builder() + final String pipelineId = environment.get(CIRCLECI_PIPELINE_ID); + return CIInfo.builder(environment) .ciProviderName(CIRCLECI_PROVIDER_NAME) .ciPipelineId(pipelineId) - .ciPipelineName(System.getenv(CIRCLECI_PIPELINE_NAME)) + .ciPipelineName(environment.get(CIRCLECI_PIPELINE_NAME)) .ciPipelineUrl(buildPipelineUrl(pipelineId)) - .ciJobName(System.getenv(CIRCLECI_JOB_NAME)) - .ciJobUrl(System.getenv(CIRCLECI_BUILD_URL)) - .ciWorkspace(expandTilde(System.getenv(CIRCLECI_WORKSPACE_PATH))) + .ciJobName(environment.get(CIRCLECI_JOB_NAME)) + .ciJobUrl(environment.get(CIRCLECI_BUILD_URL)) + .ciWorkspace(expandTilde(environment.get(CIRCLECI_WORKSPACE_PATH))) .ciEnvVars(CIRCLECI_PIPELINE_ID, CIRCLECI_BUILD_NUM) .build(); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CodefreshInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CodefreshInfo.java index a639ff53ca9..5dcdbe1abcb 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CodefreshInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CodefreshInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; public class CodefreshInfo implements CIProviderInfo { public static final String CODEFRESH = "CF_BUILD_ID"; @@ -20,6 +21,12 @@ public class CodefreshInfo implements CIProviderInfo { private static final String CF_COMMIT_MESSAGE = "CF_COMMIT_MESSAGE"; private static final String CF_COMMIT_AUTHOR = "CF_COMMIT_AUTHOR"; + private final CiEnvironment environment; + + CodefreshInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( @@ -27,10 +34,10 @@ public GitInfo buildCIGitInfo() { buildGitBranch(), buildGitTag(), new CommitInfo( - System.getenv(CF_REVISION), - new PersonInfo(System.getenv(CF_COMMIT_AUTHOR), null), + environment.get(CF_REVISION), + new PersonInfo(environment.get(CF_COMMIT_AUTHOR), null), PersonInfo.NOOP, - System.getenv(CF_COMMIT_MESSAGE))); + environment.get(CF_COMMIT_MESSAGE))); } private String buildGitBranch() { @@ -51,18 +58,18 @@ private String buildGitTag() { } } - private static String getGitBranchOrTag() { - return System.getenv(CF_BRANCH); + private String getGitBranchOrTag() { + return environment.get(CF_BRANCH); } @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(CODEFRESH_PROVIDER_NAME) - .ciPipelineId(System.getenv(CODEFRESH)) - .ciPipelineName(System.getenv(CF_PIPELINE_NAME)) - .ciPipelineUrl(System.getenv(CF_BUILD_URL)) - .ciJobName(System.getenv(CF_STEP_NAME)) + .ciPipelineId(environment.get(CODEFRESH)) + .ciPipelineName(environment.get(CF_PIPELINE_NAME)) + .ciPipelineUrl(environment.get(CF_BUILD_URL)) + .ciJobName(environment.get(CF_STEP_NAME)) .ciEnvVars(CODEFRESH) .build(); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GitLabInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GitLabInfo.java index ba31b498ef7..ce99e955371 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GitLabInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GitLabInfo.java @@ -10,6 +10,7 @@ import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.GitUtils; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import de.thetaphi.forbiddenapis.SuppressForbidden; @SuppressForbidden @@ -38,46 +39,52 @@ class GitLabInfo implements CIProviderInfo { public static final String GITLAB_CI_RUNNER_ID = "CI_RUNNER_ID"; public static final String GITLAB_CI_RUNNER_TAGS = "CI_RUNNER_TAGS"; + private final CiEnvironment environment; + + GitLabInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( - filterSensitiveInfo(System.getenv(GITLAB_GIT_REPOSITORY_URL)), - normalizeBranch(System.getenv(GITLAB_GIT_BRANCH)), - normalizeTag(System.getenv(GITLAB_GIT_TAG)), + filterSensitiveInfo(environment.get(GITLAB_GIT_REPOSITORY_URL)), + normalizeBranch(environment.get(GITLAB_GIT_BRANCH)), + normalizeTag(environment.get(GITLAB_GIT_TAG)), new CommitInfo( - System.getenv(GITLAB_GIT_COMMIT), + environment.get(GITLAB_GIT_COMMIT), buildGitCommitAuthor(), PersonInfo.NOOP, - System.getenv(GITLAB_GIT_COMMIT_MESSAGE))); + environment.get(GITLAB_GIT_COMMIT_MESSAGE))); } @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(GITLAB_PROVIDER_NAME) - .ciPipelineId(System.getenv(GITLAB_PIPELINE_ID)) - .ciPipelineName(System.getenv(GITLAB_PIPELINE_NAME)) - .ciPipelineNumber(System.getenv(GITLAB_PIPELINE_NUMBER)) - .ciPipelineUrl(System.getenv(GITLAB_PIPELINE_URL)) - .ciStageName(System.getenv(GITLAB_STAGE_NAME)) - .ciJobName(System.getenv(GITLAB_JOB_NAME)) - .ciJobUrl(System.getenv(GITLAB_JOB_URL)) - .ciWorkspace(expandTilde(System.getenv(GITLAB_WORKSPACE_PATH))) - .ciNodeName(System.getenv(GITLAB_CI_RUNNER_ID)) - .ciNodeLabels(System.getenv(GITLAB_CI_RUNNER_TAGS)) + .ciPipelineId(environment.get(GITLAB_PIPELINE_ID)) + .ciPipelineName(environment.get(GITLAB_PIPELINE_NAME)) + .ciPipelineNumber(environment.get(GITLAB_PIPELINE_NUMBER)) + .ciPipelineUrl(environment.get(GITLAB_PIPELINE_URL)) + .ciStageName(environment.get(GITLAB_STAGE_NAME)) + .ciJobName(environment.get(GITLAB_JOB_NAME)) + .ciJobUrl(environment.get(GITLAB_JOB_URL)) + .ciWorkspace(expandTilde(environment.get(GITLAB_WORKSPACE_PATH))) + .ciNodeName(environment.get(GITLAB_CI_RUNNER_ID)) + .ciNodeLabels(environment.get(GITLAB_CI_RUNNER_TAGS)) .ciEnvVars(GITLAB_PROJECT_URL, GITLAB_PIPELINE_ID, GITLAB_JOB_ID) .build(); } private PersonInfo buildGitCommitAuthor() { - final String gitAuthor = System.getenv(GITLAB_GIT_COMMIT_AUTHOR); + final String gitAuthor = environment.get(GITLAB_GIT_COMMIT_AUTHOR); if (gitAuthor == null || gitAuthor.isEmpty()) { return PersonInfo.NOOP; } final PersonInfo personInfo = GitUtils.splitAuthorAndEmail(gitAuthor); return new PersonInfo( - personInfo.getName(), personInfo.getEmail(), System.getenv(GITLAB_GIT_COMMIT_TIMESTAMP)); + personInfo.getName(), personInfo.getEmail(), environment.get(GITLAB_GIT_COMMIT_TIMESTAMP)); } @Override diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java index 6260c2e3070..ee38ed4aefc 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java @@ -12,6 +12,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import datadog.trace.util.Strings; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -47,50 +48,57 @@ class GithubActionsInfo implements CIProviderInfo { public static final String GIT_PULL_REQUEST_BASE_BRANCH_SHA = "git.pull_request.base_branch_sha"; public static final String GIT_COMMIT_HEAD_SHA = "git.commit.head_sha"; + private final CiEnvironment environment; + + GithubActionsInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( buildGitRepositoryUrl( - filterSensitiveInfo(System.getenv(GHACTIONS_URL)), System.getenv(GHACTIONS_REPOSITORY)), + filterSensitiveInfo(environment.get(GHACTIONS_URL)), + environment.get(GHACTIONS_REPOSITORY)), buildGitBranch(), buildGitTag(), - new CommitInfo(System.getenv(GHACTIONS_SHA))); + new CommitInfo(environment.get(GHACTIONS_SHA))); } @Override public CIInfo buildCIInfo() { final String pipelineUrl = buildPipelineUrl( - filterSensitiveInfo(System.getenv(GHACTIONS_URL)), - System.getenv(GHACTIONS_REPOSITORY), - System.getenv(GHACTIONS_PIPELINE_ID), - System.getenv(GHACTIONS_PIPELINE_RETRY)); + filterSensitiveInfo(environment.get(GHACTIONS_URL)), + environment.get(GHACTIONS_REPOSITORY), + environment.get(GHACTIONS_PIPELINE_ID), + environment.get(GHACTIONS_PIPELINE_RETRY)); final String jobUrl = buildJobUrl( - filterSensitiveInfo(System.getenv(GHACTIONS_URL)), - System.getenv(GHACTIONS_REPOSITORY), - System.getenv(GHACTIONS_SHA)); + filterSensitiveInfo(environment.get(GHACTIONS_URL)), + environment.get(GHACTIONS_REPOSITORY), + environment.get(GHACTIONS_SHA)); - CIInfo.Builder builder = CIInfo.builder(); + CIInfo.Builder builder = CIInfo.builder(environment); setAdditionalTagsIfApplicable(builder); return builder .ciProviderName(GHACTIONS_PROVIDER_NAME) - .ciPipelineId(System.getenv(GHACTIONS_PIPELINE_ID)) - .ciPipelineName(System.getenv(GHACTIONS_PIPELINE_NAME)) - .ciPipelineNumber(System.getenv(GHACTIONS_PIPELINE_NUMBER)) + .ciPipelineId(environment.get(GHACTIONS_PIPELINE_ID)) + .ciPipelineName(environment.get(GHACTIONS_PIPELINE_NAME)) + .ciPipelineNumber(environment.get(GHACTIONS_PIPELINE_NUMBER)) .ciPipelineUrl(pipelineUrl) - .ciJobName(System.getenv(GHACTIONS_JOB)) + .ciJobName(environment.get(GHACTIONS_JOB)) .ciJobUrl(jobUrl) - .ciWorkspace(expandTilde(System.getenv(GHACTIONS_WORKSPACE_PATH))) + .ciWorkspace(expandTilde(environment.get(GHACTIONS_WORKSPACE_PATH))) .ciEnvVars( GHACTIONS_URL, GHACTIONS_REPOSITORY, GHACTIONS_PIPELINE_ID, GHACTIONS_PIPELINE_RETRY) .build(); } - private static void setAdditionalTagsIfApplicable(CIInfo.Builder builder) { - String baseRef = System.getenv(GITHUB_BASE_REF); + private void setAdditionalTagsIfApplicable(CIInfo.Builder builder) { + String baseRef = environment.get(GITHUB_BASE_REF); if (!Strings.isNotBlank(baseRef)) { return; } @@ -99,7 +107,7 @@ private static void setAdditionalTagsIfApplicable(CIInfo.Builder builder) { Map additionalTags = new HashMap<>(); additionalTags.put(GIT_PULL_REQUEST_BASE_BRANCH, baseRef); - Path eventPath = Paths.get(System.getenv(GITHUB_EVENT_PATH)); + Path eventPath = Paths.get(environment.get(GITHUB_EVENT_PATH)); String event = new String(Files.readAllBytes(eventPath), StandardCharsets.UTF_8); Moshi moshi = new Moshi.Builder().build(); @@ -147,10 +155,10 @@ private String buildGitTag() { } } - private static String getGitBranchOrTag() { - String gitBranchOrTag = System.getenv(GHACTIONS_HEAD_REF); + private String getGitBranchOrTag() { + String gitBranchOrTag = environment.get(GHACTIONS_HEAD_REF); if (gitBranchOrTag == null || gitBranchOrTag.isEmpty()) { - gitBranchOrTag = System.getenv(GHACTIONS_REF); + gitBranchOrTag = environment.get(GHACTIONS_REF); } return gitBranchOrTag; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/JenkinsInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/JenkinsInfo.java index a4d65533428..bb3d56f81e3 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/JenkinsInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/JenkinsInfo.java @@ -9,6 +9,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import datadog.trace.util.Strings; import de.thetaphi.forbiddenapis.SuppressForbidden; import java.util.Arrays; @@ -37,34 +38,40 @@ class JenkinsInfo implements CIProviderInfo { public static final String JENKINS_NODE_NAME = "NODE_NAME"; public static final String JENKINS_NODE_LABELS = "NODE_LABELS"; + private final CiEnvironment environment; + + JenkinsInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo( filterSensitiveInfo(buildGitRepositoryUrl()), buildGitBranch(), buildGitTag(), - new CommitInfo(System.getenv(JENKINS_GIT_COMMIT))); + new CommitInfo(environment.get(JENKINS_GIT_COMMIT))); } @Override public CIInfo buildCIInfo() { final String gitBranch = buildGitBranch(); - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(JENKINS_PROVIDER_NAME) - .ciPipelineId(System.getenv(JENKINS_PIPELINE_ID)) + .ciPipelineId(environment.get(JENKINS_PIPELINE_ID)) .ciPipelineName(buildCiPipelineName(gitBranch)) - .ciPipelineNumber(System.getenv(JENKINS_PIPELINE_NUMBER)) - .ciPipelineUrl(System.getenv(JENKINS_PIPELINE_URL)) - .ciWorkspace(expandTilde(System.getenv(JENKINS_WORKSPACE_PATH))) - .ciNodeName(System.getenv(JENKINS_NODE_NAME)) + .ciPipelineNumber(environment.get(JENKINS_PIPELINE_NUMBER)) + .ciPipelineUrl(environment.get(JENKINS_PIPELINE_URL)) + .ciWorkspace(expandTilde(environment.get(JENKINS_WORKSPACE_PATH))) + .ciNodeName(environment.get(JENKINS_NODE_NAME)) .ciNodeLabels(buildCiNodeLabels()) .ciEnvVars(JENKINS_DD_CUSTOM_TRACE_ID) .build(); } private String buildCiNodeLabels() { - String labels = System.getenv(JENKINS_NODE_LABELS); + String labels = environment.get(JENKINS_NODE_LABELS); if (labels == null || labels.isEmpty()) { return labels; } @@ -73,13 +80,13 @@ private String buildCiNodeLabels() { } private String buildGitRepositoryUrl() { - return System.getenv(JENKINS_GIT_REPOSITORY_URL) != null - ? System.getenv(JENKINS_GIT_REPOSITORY_URL) - : System.getenv(JENKINS_GIT_REPOSITORY_URL_ALT); + return environment.get(JENKINS_GIT_REPOSITORY_URL) != null + ? environment.get(JENKINS_GIT_REPOSITORY_URL) + : environment.get(JENKINS_GIT_REPOSITORY_URL_ALT); } private String buildGitBranch() { - final String gitBranchOrTag = System.getenv(JENKINS_GIT_BRANCH); + final String gitBranchOrTag = environment.get(JENKINS_GIT_BRANCH); if (!isTagReference(gitBranchOrTag)) { return normalizeBranch(gitBranchOrTag); } else { @@ -88,7 +95,7 @@ private String buildGitBranch() { } private String buildGitTag() { - final String gitBranchOrTag = System.getenv(JENKINS_GIT_BRANCH); + final String gitBranchOrTag = environment.get(JENKINS_GIT_BRANCH); if (isTagReference(gitBranchOrTag)) { return normalizeTag(gitBranchOrTag); } else { @@ -97,7 +104,7 @@ private String buildGitTag() { } private String buildCiPipelineName(final String branch) { - final String jobName = System.getenv(JENKINS_PIPELINE_NAME); + final String jobName = environment.get(JENKINS_PIPELINE_NAME); return filterJenkinsJobName(jobName, branch); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TeamcityInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TeamcityInfo.java index ed2a0f2de20..996576f134a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TeamcityInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TeamcityInfo.java @@ -3,6 +3,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; public class TeamcityInfo implements CIProviderInfo { public static final String TEAMCITY = "TEAMCITY_VERSION"; @@ -10,6 +11,12 @@ public class TeamcityInfo implements CIProviderInfo { private static final String TEAMCITY_BUILDCONF_NAME = "TEAMCITY_BUILDCONF_NAME"; private static final String BUILD_URL = "BUILD_URL"; + private final CiEnvironment environment; + + TeamcityInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { return new GitInfo(null, null, null, new CommitInfo(null)); @@ -17,10 +24,10 @@ public GitInfo buildCIGitInfo() { @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(TEAMCITY_PROVIDER_NAME) - .ciJobName(System.getenv(TEAMCITY_BUILDCONF_NAME)) - .ciJobUrl(System.getenv(BUILD_URL)) + .ciJobName(environment.get(TEAMCITY_BUILDCONF_NAME)) + .ciJobUrl(environment.get(BUILD_URL)) .build(); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TravisInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TravisInfo.java index 830f9056291..8bcad157624 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TravisInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/TravisInfo.java @@ -8,6 +8,7 @@ import datadog.trace.api.git.CommitInfo; import datadog.trace.api.git.GitInfo; import datadog.trace.api.git.PersonInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; class TravisInfo implements CIProviderInfo { @@ -27,46 +28,51 @@ class TravisInfo implements CIProviderInfo { public static final String TRAVIS_GIT_TAG = "TRAVIS_TAG"; public static final String TRAVIS_GIT_COMMIT_MESSAGE = "TRAVIS_COMMIT_MESSAGE"; + private final CiEnvironment environment; + + TravisInfo(CiEnvironment environment) { + this.environment = environment; + } + @Override public GitInfo buildCIGitInfo() { - return new GitInfo( buildGitRepositoryUrl(), buildGitBranch(), - normalizeTag(System.getenv(TRAVIS_GIT_TAG)), + normalizeTag(environment.get(TRAVIS_GIT_TAG)), new CommitInfo( - System.getenv(TRAVIS_GIT_COMMIT), + environment.get(TRAVIS_GIT_COMMIT), PersonInfo.NOOP, PersonInfo.NOOP, - System.getenv(TRAVIS_GIT_COMMIT_MESSAGE))); + environment.get(TRAVIS_GIT_COMMIT_MESSAGE))); } @Override public CIInfo buildCIInfo() { - return CIInfo.builder() + return CIInfo.builder(environment) .ciProviderName(TRAVIS_PROVIDER_NAME) - .ciPipelineId(System.getenv(TRAVIS_PIPELINE_ID)) + .ciPipelineId(environment.get(TRAVIS_PIPELINE_ID)) .ciPipelineName(buildCiPipelineName()) - .ciPipelineNumber(System.getenv(TRAVIS_PIPELINE_NUMBER)) - .ciPipelineUrl(System.getenv(TRAVIS_PIPELINE_URL)) - .ciJobUrl(System.getenv(TRAVIS_JOB_URL)) - .ciWorkspace(expandTilde(System.getenv(TRAVIS_WORKSPACE_PATH))) + .ciPipelineNumber(environment.get(TRAVIS_PIPELINE_NUMBER)) + .ciPipelineUrl(environment.get(TRAVIS_PIPELINE_URL)) + .ciJobUrl(environment.get(TRAVIS_JOB_URL)) + .ciWorkspace(expandTilde(environment.get(TRAVIS_WORKSPACE_PATH))) .build(); } private String buildGitBranch() { - final String fromBranch = System.getenv(TRAVIS_GIT_PR_BRANCH); + final String fromBranch = environment.get(TRAVIS_GIT_PR_BRANCH); if (fromBranch != null && !fromBranch.isEmpty()) { return normalizeBranch(fromBranch); } else { - return normalizeBranch(System.getenv(TRAVIS_GIT_BRANCH)); + return normalizeBranch(environment.get(TRAVIS_GIT_BRANCH)); } } private String buildGitRepositoryUrl() { - String repoSlug = System.getenv(TRAVIS_PR_REPOSITORY_SLUG); + String repoSlug = environment.get(TRAVIS_PR_REPOSITORY_SLUG); if (repoSlug == null || repoSlug.isEmpty()) { - repoSlug = System.getenv(TRAVIS_REPOSITORY_SLUG); + repoSlug = environment.get(TRAVIS_REPOSITORY_SLUG); } if (repoSlug == null || repoSlug.isEmpty()) { @@ -76,9 +82,9 @@ private String buildGitRepositoryUrl() { } private String buildCiPipelineName() { - String repoSlug = System.getenv(TRAVIS_PR_REPOSITORY_SLUG); + String repoSlug = environment.get(TRAVIS_PR_REPOSITORY_SLUG); if (repoSlug == null || repoSlug.isEmpty()) { - repoSlug = System.getenv(TRAVIS_REPOSITORY_SLUG); + repoSlug = environment.get(TRAVIS_REPOSITORY_SLUG); } return repoSlug; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/UnknownCIInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/UnknownCIInfo.java index 02dfed2bd4a..72ddbb4017c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/UnknownCIInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/UnknownCIInfo.java @@ -4,6 +4,7 @@ import datadog.trace.api.civisibility.telemetry.tag.Provider; import datadog.trace.api.git.GitInfo; +import datadog.trace.civisibility.ci.env.CiEnvironment; import java.nio.file.Path; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,14 +29,12 @@ class UnknownCIInfo implements CIProviderInfo { public static final String UNKNOWN_PROVIDER_NAME = "unknown"; + private final CiEnvironment environment; private final String targetFolder; private final Path currentPath; - UnknownCIInfo(Path currentPath) { - this(".git", currentPath); - } - - UnknownCIInfo(String targetFolder, Path currentPath) { + UnknownCIInfo(CiEnvironment environment, String targetFolder, Path currentPath) { + this.environment = environment; this.targetFolder = targetFolder; this.currentPath = currentPath; } @@ -58,7 +57,7 @@ public CIInfo buildCIInfo() { LOGGER.debug("Could not get real path for workspace folder {}", workspace, e); } - return CIInfo.builder().ciWorkspace(workspace.toAbsolutePath().toString()).build(); + return CIInfo.builder(environment).ciWorkspace(workspace.toAbsolutePath().toString()).build(); } protected String getTargetFolder() { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironment.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironment.java new file mode 100644 index 00000000000..f649701e382 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironment.java @@ -0,0 +1,10 @@ +package datadog.trace.civisibility.ci.env; + +import java.util.Map; + +public interface CiEnvironment { + + String get(String name); + + Map get(); +} diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironmentImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironmentImpl.java new file mode 100644 index 00000000000..0030df98768 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CiEnvironmentImpl.java @@ -0,0 +1,22 @@ +package datadog.trace.civisibility.ci.env; + +import java.util.Map; + +public class CiEnvironmentImpl implements CiEnvironment { + + private final Map env; + + public CiEnvironmentImpl(Map env) { + this.env = env; + } + + @Override + public String get(String name) { + return env.get(name); + } + + @Override + public Map get() { + return env; + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CompositeCiEnvironment.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CompositeCiEnvironment.java new file mode 100644 index 00000000000..2a723606d76 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/env/CompositeCiEnvironment.java @@ -0,0 +1,35 @@ +package datadog.trace.civisibility.ci.env; + +import java.util.HashMap; +import java.util.Map; + +public class CompositeCiEnvironment implements CiEnvironment { + + private final CiEnvironment[] delegates; + + public CompositeCiEnvironment(CiEnvironment... delegates) { + this.delegates = delegates; + } + + @Override + public String get(String name) { + for (CiEnvironment delegate : delegates) { + String value = delegate.get(name); + if (value != null) { + return value; + } + } + return null; + } + + @Override + public Map get() { + Map combinedEnvironment = new HashMap<>(); + for (int i = delegates.length - 1; i >= 0; i--) { + // iterating over delegates in reverse order, + // since delegates with lower indices have higher priority + combinedEnvironment.putAll(delegates[i].get()); + } + return combinedEnvironment; + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/CIProviderGitInfoBuilder.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/CIProviderGitInfoBuilder.java index 7a138f2f10e..b4a6d6f0d30 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/CIProviderGitInfoBuilder.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/CIProviderGitInfoBuilder.java @@ -5,15 +5,25 @@ import datadog.trace.api.git.GitInfoBuilder; import datadog.trace.civisibility.ci.CIProviderInfo; import datadog.trace.civisibility.ci.CIProviderInfoFactory; +import datadog.trace.civisibility.ci.env.CiEnvironment; import java.nio.file.Path; import java.nio.file.Paths; import javax.annotation.Nullable; public class CIProviderGitInfoBuilder implements GitInfoBuilder { + + private final Config config; + private final CiEnvironment environment; + + public CIProviderGitInfoBuilder(Config config, CiEnvironment environment) { + this.config = config; + this.environment = environment; + } + @Override public GitInfo build(@Nullable String repositoryPath) { Path currentPath = repositoryPath != null ? Paths.get(repositoryPath) : null; - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get()); + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(config, environment); CIProviderInfo ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(currentPath); return ciProviderInfo.buildCIGitInfo(); } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/CiVisibilityServicesTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/CiVisibilityServicesTest.groovy new file mode 100644 index 00000000000..8e7cbf71a5a --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/CiVisibilityServicesTest.groovy @@ -0,0 +1,33 @@ +package datadog.trace.civisibility + +import datadog.trace.agent.test.server.http.TestHttpServer +import datadog.trace.agent.test.utils.OkHttpUtils +import spock.lang.Specification + +import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer + +class CiVisibilityServicesTest extends Specification { + + def "test get remote environment"() { + given: + def key = "the-key" + + TestHttpServer remoteEnvironmentServer = httpServer { + handlers { + prefix("/") { + if (request.getHeader(CiVisibilityServices.DD_ENV_VARS_PROVIDER_KEY_HEADER) == key) { + response.status(200).send(""" { "a": 1, "b": "2" } """) + } else { + response.status(404).send() + } + } + } + } + + expect: + CiVisibilityServices.getRemoteEnvironment(remoteEnvironmentServer.address.toString(), key, OkHttpUtils.client()) == ["a": "1", "b": "2"] + + cleanup: + remoteEnvironmentServer.stop() + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CIProviderInfoFactoryTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CIProviderInfoFactoryTest.groovy index 62d9ec6108b..08b21a8d318 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CIProviderInfoFactoryTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CIProviderInfoFactoryTest.groovy @@ -1,6 +1,7 @@ package datadog.trace.civisibility.ci import datadog.trace.api.Config +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import org.junit.Rule import org.junit.contrib.java.lang.system.EnvironmentVariables import org.junit.contrib.java.lang.system.RestoreSystemProperties @@ -38,7 +39,7 @@ class CIProviderInfoFactoryTest extends Specification { environmentVariables.set(ciKeySelector, "true") when: - def ciProviderInfoFactory = new CIProviderInfoFactory(Config.get()) + def ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(Paths.get("").toAbsolutePath()) then: diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy index 616f7ea18db..e51a2224f3a 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy @@ -5,6 +5,7 @@ import datadog.trace.api.git.GitInfo import datadog.trace.api.git.GitInfoProvider import datadog.trace.api.git.UserSuppliedGitInfoBuilder import datadog.trace.bootstrap.instrumentation.api.Tags +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import datadog.trace.civisibility.git.CILocalGitInfoBuilder import datadog.trace.civisibility.git.CIProviderGitInfoBuilder import datadog.trace.civisibility.git.tree.GitClient @@ -46,7 +47,7 @@ abstract class CITagsProviderTest extends Specification { } when: - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) def ciInfo = ciProviderInfo.buildCIInfo() def ciTagsProvider = ciTagsProvider() @@ -71,7 +72,7 @@ abstract class CITagsProviderTest extends Specification { environmentVariables.set(GitInfo.DD_GIT_COMMIT_SHA, "1234567890123456789012345678901234567890") when: - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) def ciInfo = ciProviderInfo.buildCIInfo() def ciTagsProvider = ciTagsProvider() @@ -90,7 +91,7 @@ abstract class CITagsProviderTest extends Specification { environmentVariables.set(GitInfo.DD_GIT_REPOSITORY_URL, "local supplied repo url") when: - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) def ciInfo = ciProviderInfo.buildCIInfo() def ciTagsProvider = ciTagsProvider() @@ -107,7 +108,7 @@ abstract class CITagsProviderTest extends Specification { } when: - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) def ciInfo = ciProviderInfo.buildCIInfo() def ciTagsProvider = ciTagsProvider() @@ -139,7 +140,7 @@ abstract class CITagsProviderTest extends Specification { then: if (isCi()) { - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) def ciInfo = ciProviderInfo.buildCIInfo() def tags = ciTagsProvider.getCiTags(ciInfo) @@ -173,7 +174,7 @@ abstract class CITagsProviderTest extends Specification { GitInfoProvider gitInfoProvider = new GitInfoProvider() gitInfoProvider.registerGitInfoBuilder(new UserSuppliedGitInfoBuilder()) - gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder()) + gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder(Config.get(), new CiEnvironmentImpl(System.getenv()))) gitInfoProvider.registerGitInfoBuilder(new CILocalGitInfoBuilder(gitClientFactory, GIT_FOLDER_FOR_TESTS)) return new CITagsProvider(gitInfoProvider) } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy index 784e5e3d529..c54503cb0a7 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy @@ -1,5 +1,6 @@ package datadog.trace.civisibility.ci +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import java.nio.file.Paths @@ -36,7 +37,7 @@ class GithubActionsInfoTest extends CITagsProviderTest { environmentVariables.set(GithubActionsInfo.GITHUB_EVENT_PATH, githubEventPath.toString()) when: - def cIInfo = new GithubActionsInfo().buildCIInfo() + def cIInfo = new GithubActionsInfo(new CiEnvironmentImpl(System.getenv())).buildCIInfo() then: cIInfo.getAdditionalTags() == [ diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/UnknownCIInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/UnknownCIInfoTest.groovy index 333f554c8d4..77d1dda2f7b 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/UnknownCIInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/UnknownCIInfoTest.groovy @@ -4,6 +4,7 @@ import datadog.trace.api.Config import datadog.trace.api.git.GitInfoProvider import datadog.trace.api.git.UserSuppliedGitInfoBuilder import datadog.trace.bootstrap.instrumentation.api.Tags +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import datadog.trace.civisibility.git.CILocalGitInfoBuilder import datadog.trace.civisibility.git.CIProviderGitInfoBuilder import datadog.trace.civisibility.git.tree.GitClient @@ -44,7 +45,7 @@ class UnknownCIInfoTest extends CITagsProviderTest { ] when: - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS) + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(workspaceForTests) def ciInfo = ciProviderInfo.buildCIInfo() def ciTagsProvider = ciTagsProvider() @@ -61,9 +62,9 @@ class UnknownCIInfoTest extends CITagsProviderTest { GitInfoProvider gitInfoProvider = new GitInfoProvider() gitInfoProvider.registerGitInfoBuilder(new UserSuppliedGitInfoBuilder()) - gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder()) + gitInfoProvider.registerGitInfoBuilder(new CIProviderGitInfoBuilder(Config.get(), new CiEnvironmentImpl(System.getenv()))) gitInfoProvider.registerGitInfoBuilder(new CILocalGitInfoBuilder(gitClientFactory, "this-target-folder-does-not-exist")) - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), "this-target-folder-does-not-exist") + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), "this-target-folder-does-not-exist", new CiEnvironmentImpl(System.getenv())) def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(workspaceForTests) def ciInfo = ciProviderInfo.buildCIInfo() diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CiEnvironmentImplTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CiEnvironmentImplTest.groovy new file mode 100644 index 00000000000..fa8f664cb7c --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CiEnvironmentImplTest.groovy @@ -0,0 +1,25 @@ +package datadog.trace.civisibility.ci.env + + +import spock.lang.Specification + +class CiEnvironmentImplTest extends Specification { + + def "test returns an environment variable"() { + setup: + def environmentVariables = ["MY_ENV_VAR": "MY_VALUE"] + def environment = new CiEnvironmentImpl(environmentVariables) + + expect: + environment.get("MY_ENV_VAR") == "MY_VALUE" + } + + def "test returns all environment variables"() { + setup: + def environmentVariables = ["MY_ENV_VAR": "MY_VALUE", "MY_OTHER_ENV_VAR": "MY_OTHER_VALUE"] + def environment = new CiEnvironmentImpl(environmentVariables) + + expect: + environment.get() == ["MY_ENV_VAR": "MY_VALUE", "MY_OTHER_ENV_VAR": "MY_OTHER_VALUE"] + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CompositeCiEnvironmentTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CompositeCiEnvironmentTest.groovy new file mode 100644 index 00000000000..1f28d0f5859 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/env/CompositeCiEnvironmentTest.groovy @@ -0,0 +1,41 @@ +package datadog.trace.civisibility.ci.env + + +import spock.lang.Specification + +class CompositeCiEnvironmentTest extends Specification { + + def "test uses delegate"() { + setup: + def environmentVariables = ["MY_ENV_VAR": "MY_VALUE", "MY_OTHER_ENV_VAR": "MY_OTHER_VALUE"] + def delegate = new CiEnvironmentImpl(environmentVariables) + def environment = new CompositeCiEnvironment(delegate) + + expect: + environment.get("MY_ENV_VAR") == "MY_VALUE" + environment.get() == ["MY_ENV_VAR": "MY_VALUE", "MY_OTHER_ENV_VAR": "MY_OTHER_VALUE"] + } + + def "test uses multiple delegates"() { + setup: + def delegateA = new CiEnvironmentImpl(["A": "1", "AA": "2"]) + def delegateB = new CiEnvironmentImpl(["B": "3", "BB": "4"]) + def environment = new CompositeCiEnvironment(delegateA, delegateB) + + expect: + environment.get("A") == "1" + environment.get("B") == "3" + environment.get() == ["A": "1", "AA": "2", "B": "3", "BB": "4"] + } + + def "test delegates priority"() { + setup: + def delegateA = new CiEnvironmentImpl(["A": "1", "B": "2"]) + def delegateB = new CiEnvironmentImpl(["B": "3", "C": "4"]) + def environment = new CompositeCiEnvironment(delegateA, delegateB) + + expect: + environment.get("B") == "2" + environment.get() == ["A": "1", "B": "2", "C": "4"] + } +} diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy index f56830ff3dc..b630e86fab9 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy @@ -395,7 +395,6 @@ class ConfigurationApiImplTest extends Specification { String apiKey = "api-key" String traceId = "a-trace-id" - long timeoutMillis = 1000 HttpRetryPolicy retryPolicy = Stub(HttpRetryPolicy) retryPolicy.shouldRetry(_) >> false @@ -403,7 +402,8 @@ class ConfigurationApiImplTest extends Specification { HttpRetryPolicy.Factory retryPolicyFactory = Stub(HttpRetryPolicy.Factory) retryPolicyFactory.create() >> retryPolicy - return new IntakeApi(intakeUrl, apiKey, traceId, timeoutMillis, retryPolicyFactory, responseCompression) + OkHttpClient client = OkHttpUtils.buildHttpClient(intakeUrl, REQUEST_TIMEOUT_MILLIS) + return new IntakeApi(intakeUrl, apiKey, traceId, retryPolicyFactory, client, responseCompression) } private static TracerEnvironment givenTracerEnvironment() { diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/CIProviderGitInfoBuilderTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/CIProviderGitInfoBuilderTest.groovy index 1ad5ad74617..1177e64183b 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/CIProviderGitInfoBuilderTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/CIProviderGitInfoBuilderTest.groovy @@ -1,6 +1,7 @@ package datadog.trace.civisibility.git - +import datadog.trace.api.Config +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import org.junit.Rule import org.junit.contrib.java.lang.system.EnvironmentVariables import spock.lang.Specification @@ -19,7 +20,7 @@ class CIProviderGitInfoBuilderTest extends Specification { def "test builds empty git info in an unknown repository"() { setup: - def builder = new CIProviderGitInfoBuilder() + def builder = new CIProviderGitInfoBuilder(Config.get(), new CiEnvironmentImpl(System.getenv())) when: def gitInfo = builder.build(null) diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index 248bf228ab1..a929649e703 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -69,6 +69,10 @@ public final class CiVisibilityConfig { "civisibility.rum.flush.wait.millis"; public static final String CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER = "civisibility.auto.instrumentation.provider"; + public static final String CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_URL = + "civisibility.remote.env.vars.provider.url"; + public static final String CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_KEY = + "civisibility.remote.env.vars.provider.key"; /* COVERAGE SETTINGS */ public static final String CIVISIBILITY_CODE_COVERAGE_ENABLED = diff --git a/dd-trace-core/src/main/java/datadog/trace/common/writer/WriterFactory.java b/dd-trace-core/src/main/java/datadog/trace/common/writer/WriterFactory.java index b4af03b90e7..ef73a0b6fb7 100644 --- a/dd-trace-core/src/main/java/datadog/trace/common/writer/WriterFactory.java +++ b/dd-trace-core/src/main/java/datadog/trace/common/writer/WriterFactory.java @@ -188,6 +188,7 @@ private static RemoteApi createDDIntakeRemoteApi( } return DDIntakeApi.builder() .hostUrl(hostUrl) + .httpClient(commObjects.okHttpClient) .apiKey(config.getApiKey()) .trackType(trackType) .build(); diff --git a/dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeApi.java b/dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeApi.java index 165d1a951ab..7abad42d2f1 100644 --- a/dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeApi.java +++ b/dd-trace-core/src/main/java/datadog/trace/common/writer/ddintake/DDIntakeApi.java @@ -77,7 +77,7 @@ public DDIntakeApiBuilder hostUrl(final HttpUrl hostUrl) { return this; } - DDIntakeApiBuilder httpClient(final OkHttpClient httpClient) { + public DDIntakeApiBuilder httpClient(final OkHttpClient httpClient) { this.httpClient = httpClient; return this; } diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index c461a36806f..75b95385375 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -1,500 +1,22 @@ package datadog.trace.api; -import static datadog.trace.api.ConfigDefaults.DEFAULT_AGENT_HOST; -import static datadog.trace.api.ConfigDefaults.DEFAULT_AGENT_TIMEOUT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_AGENT_WRITER_TYPE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_ANALYTICS_SAMPLE_RATE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_API_SECURITY_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_API_SECURITY_REQUEST_SAMPLE_RATE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_MAX_STACK_TRACES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_MAX_STACK_TRACE_DEPTH; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_RASP_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_REPORTING_INBAND; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_STACK_TRACE_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_TRACE_RATE_LIMIT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_WAF_METRICS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_APPSEC_WAF_TIMEOUT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_AGENTLESS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_AUTO_CONFIGURATION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_BACKEND_API_TIMEOUT_MILLIS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_COMPILER_PLUGIN_AUTO_CONFIGURATION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_COMPILER_PLUGIN_VERSION; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_GIT_COMMAND_TIMEOUT_MILLIS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_GIT_REMOTE_NAME; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_GIT_UNSHALLOW_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_GIT_UPLOAD_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_GIT_UPLOAD_TIMEOUT_MILLIS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_JACOCO_PLUGIN_EXCLUDES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_JACOCO_PLUGIN_VERSION; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_RESOURCE_FOLDER_NAMES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_SIGNAL_SERVER_HOST; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_SIGNAL_SERVER_PORT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CIVISIBILITY_SOURCE_DATA_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CLIENT_IP_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CLOCK_SYNC_PERIOD; -import static datadog.trace.api.ConfigDefaults.DEFAULT_COUCHBASE_INTERNAL_SPANS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CWS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_CWS_TLS_REFRESH; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DATA_JOBS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DATA_STREAMS_BUCKET_DURATION; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DATA_STREAMS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DB_CLIENT_HOST_SPLIT_BY_HOST; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DB_CLIENT_HOST_SPLIT_BY_INSTANCE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DB_CLIENT_HOST_SPLIT_BY_INSTANCE_TYPE_SUFFIX; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DB_DBM_PROPAGATION_MODE_MODE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_CAPTURE_TIMEOUT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_CLASSFILE_DUMP_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_CODE_ORIGIN_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_DIAGNOSTICS_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_EXCEPTION_CAPTURE_INTERMEDIATE_SPANS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_EXCEPTION_CAPTURE_INTERVAL_SECONDS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_EXCEPTION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_EXCEPTION_MAX_CAPTURED_FRAMES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_EXCEPTION_ONLY_LOCAL_ROOT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_INSTRUMENT_THE_WORLD; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_MAX_EXCEPTION_PER_SECOND; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_MAX_PAYLOAD_SIZE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_METRICS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_POLL_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_SYMBOL_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_SYMBOL_FLUSH_THRESHOLD; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_SYMBOL_FORCE_UPLOAD; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_UPLOAD_BATCH_SIZE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_UPLOAD_FLUSH_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_UPLOAD_TIMEOUT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DEBUGGER_VERIFY_BYTECODE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_DOGSTATSD_START_DELAY; -import static datadog.trace.api.ConfigDefaults.DEFAULT_ELASTICSEARCH_BODY_AND_PARAMS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_ELASTICSEARCH_BODY_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_ELASTICSEARCH_PARAMS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_GRPC_CLIENT_ERROR_STATUSES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_GRPC_SERVER_ERROR_STATUSES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HEALTH_METRICS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_CLIENT_ERROR_STATUSES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_CLIENT_SPLIT_BY_DOMAIN; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_CLIENT_TAG_QUERY_STRING; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_SERVER_ERROR_STATUSES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_SERVER_ROUTE_BASED_NAMING; -import static datadog.trace.api.ConfigDefaults.DEFAULT_HTTP_SERVER_TAG_QUERY_STRING; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_ANONYMOUS_CLASSES_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_DEBUG_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_HARDCODED_SECRET_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_REDACTION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_REDACTION_NAME_PATTERN; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_REDACTION_VALUE_PATTERN; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_STACKTRACE_LEAK_SUPPRESS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_TRUNCATION_MAX_VALUE_LENGTH; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_WEAK_CIPHER_ALGORITHMS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_IAST_WEAK_HASH_ALGORITHMS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_JMX_FETCH_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_JMX_FETCH_MULTIPLE_RUNTIME_SERVICES_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_JMX_FETCH_MULTIPLE_RUNTIME_SERVICES_LIMIT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_LOGS_INJECTION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PARTIAL_FLUSH_MIN_SPANS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PERF_METRICS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PRIORITY_SAMPLING_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PRIORITY_SAMPLING_FORCE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PROPAGATION_EXTRACT_LOG_HEADER_NAMES_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_PROPAGATION_STYLE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_INTEGRITY_CHECK_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_MAX_EXTRA_SERVICES; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_MAX_PAYLOAD_SIZE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_POLL_INTERVAL_SECONDS; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_TARGETS_KEY; -import static datadog.trace.api.ConfigDefaults.DEFAULT_REMOTE_CONFIG_TARGETS_KEY_ID; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SCOPE_DEPTH_LIMIT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SCOPE_ITERATION_KEEP_ALIVE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SECURE_RANDOM; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SERVICE_NAME; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SERVLET_ROOT_CONTEXT_SERVICE_NAME; -import static datadog.trace.api.ConfigDefaults.DEFAULT_SITE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_STARTUP_LOGS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_DEPENDENCY_RESOLUTION_QUEUE_SIZE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_EXTENDED_HEARTBEAT_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_HEARTBEAT_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_LOG_COLLECTION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TELEMETRY_METRICS_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_128_BIT_TRACEID_GENERATION_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_AGENT_PORT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_AGENT_V05_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_ANALYTICS_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_HTTP_RESOURCE_REMOVE_TRAILING_SLASH; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_LONG_RUNNING_FLUSH_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_LONG_RUNNING_INITIAL_FLUSH_INTERVAL; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_PROPAGATION_EXTRACT_FIRST; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_PROPAGATION_STYLE; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_RATE_LIMIT; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_REPORT_HOSTNAME; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_RESOLVER_ENABLED; -import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_X_DATADOG_TAGS_MAX_LENGTH; -import static datadog.trace.api.ConfigDefaults.DEFAULT_WRITER_BAGGAGE_INJECT; -import static datadog.trace.api.DDTags.APM_ENABLED; -import static datadog.trace.api.DDTags.HOST_TAG; -import static datadog.trace.api.DDTags.INTERNAL_HOST_NAME; -import static datadog.trace.api.DDTags.LANGUAGE_TAG_KEY; -import static datadog.trace.api.DDTags.LANGUAGE_TAG_VALUE; -import static datadog.trace.api.DDTags.PID_TAG; +import static datadog.trace.api.ConfigDefaults.*; +import static datadog.trace.api.DDTags.*; import static datadog.trace.api.DDTags.PROFILING_ENABLED; -import static datadog.trace.api.DDTags.RUNTIME_ID_TAG; -import static datadog.trace.api.DDTags.RUNTIME_VERSION_TAG; -import static datadog.trace.api.DDTags.SCHEMA_VERSION_TAG_KEY; -import static datadog.trace.api.DDTags.SERVICE; -import static datadog.trace.api.DDTags.SERVICE_TAG; -import static datadog.trace.api.config.AppSecConfig.API_SECURITY_ENABLED; -import static datadog.trace.api.config.AppSecConfig.API_SECURITY_ENABLED_EXPERIMENTAL; -import static datadog.trace.api.config.AppSecConfig.API_SECURITY_REQUEST_SAMPLE_RATE; -import static datadog.trace.api.config.AppSecConfig.APPSEC_AUTOMATED_USER_EVENTS_TRACKING; -import static datadog.trace.api.config.AppSecConfig.APPSEC_AUTO_USER_INSTRUMENTATION_MODE; -import static datadog.trace.api.config.AppSecConfig.APPSEC_HTTP_BLOCKED_TEMPLATE_HTML; -import static datadog.trace.api.config.AppSecConfig.APPSEC_HTTP_BLOCKED_TEMPLATE_JSON; -import static datadog.trace.api.config.AppSecConfig.APPSEC_IP_ADDR_HEADER; -import static datadog.trace.api.config.AppSecConfig.APPSEC_MAX_STACK_TRACES; -import static datadog.trace.api.config.AppSecConfig.APPSEC_MAX_STACK_TRACE_DEPTH; -import static datadog.trace.api.config.AppSecConfig.APPSEC_OBFUSCATION_PARAMETER_KEY_REGEXP; -import static datadog.trace.api.config.AppSecConfig.APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP; -import static datadog.trace.api.config.AppSecConfig.APPSEC_RASP_ENABLED; -import static datadog.trace.api.config.AppSecConfig.APPSEC_REPORTING_INBAND; -import static datadog.trace.api.config.AppSecConfig.APPSEC_REPORT_TIMEOUT_SEC; -import static datadog.trace.api.config.AppSecConfig.APPSEC_RULES_FILE; -import static datadog.trace.api.config.AppSecConfig.APPSEC_SCA_ENABLED; -import static datadog.trace.api.config.AppSecConfig.APPSEC_STACK_TRACE_ENABLED; -import static datadog.trace.api.config.AppSecConfig.APPSEC_STANDALONE_ENABLED; -import static datadog.trace.api.config.AppSecConfig.APPSEC_TRACE_RATE_LIMIT; -import static datadog.trace.api.config.AppSecConfig.APPSEC_WAF_METRICS; -import static datadog.trace.api.config.AppSecConfig.APPSEC_WAF_TIMEOUT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_ADDITIONAL_CHILD_PROCESS_JVM_ARGS; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AGENT_JAR_URI; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AUTO_CONFIGURATION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_BACKEND_API_TIMEOUT_MILLIS; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_EXCLUDES; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_INCLUDES; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_LINES_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_REPORT_DUMP_DIR; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_CODE_COVERAGE_ROOT_PACKAGES_LIMIT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_AUTO_CONFIGURATION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_DEBUG_PORT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_EARLY_FLAKE_DETECTION_LOWER_LIMIT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_EXECUTION_SETTINGS_CACHE_SIZE; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_FLAKY_RETRY_COUNT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_FLAKY_RETRY_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_FLAKY_RETRY_ONLY_KNOWN_FLAKES; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_COMMAND_TIMEOUT_MILLIS; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_REMOTE_NAME; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UNSHALLOW_DEFER; -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_GRADLE_SOURCE_SETS; -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_PLUGIN_VERSION; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_JVM_INFO_CACHE_SIZE; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_MODULE_ID; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_MODULE_NAME; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_REPO_INDEX_SHARING_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_RESOURCE_FOLDER_NAMES; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SESSION_ID; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SIGNAL_CLIENT_TIMEOUT_MILLIS; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_HOST; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SIGNAL_SERVER_PORT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_TELEMETRY_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_TEST_COMMAND; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_TEST_SKIPPING_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_TOTAL_FLAKY_RETRY_COUNT; -import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_TRACE_SANITATION_ENABLED; -import static datadog.trace.api.config.CiVisibilityConfig.TEST_SESSION_NAME; -import static datadog.trace.api.config.CrashTrackingConfig.CRASH_TRACKING_AGENTLESS; -import static datadog.trace.api.config.CrashTrackingConfig.CRASH_TRACKING_AGENTLESS_DEFAULT; -import static datadog.trace.api.config.CrashTrackingConfig.CRASH_TRACKING_TAGS; +import static datadog.trace.api.config.AppSecConfig.*; +import static datadog.trace.api.config.CiVisibilityConfig.*; +import static datadog.trace.api.config.CrashTrackingConfig.*; import static datadog.trace.api.config.CwsConfig.CWS_ENABLED; import static datadog.trace.api.config.CwsConfig.CWS_TLS_REFRESH; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_CAPTURE_TIMEOUT; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_CLASSFILE_DUMP_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_CODE_ORIGIN_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_DIAGNOSTICS_INTERVAL; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_CAPTURE_INTERMEDIATE_SPANS_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_CAPTURE_INTERVAL_SECONDS; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_CAPTURE_MAX_FRAMES; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_MAX_CAPTURED_FRAMES; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCEPTION_ONLY_LOCAL_ROOT; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_EXCLUDE_FILES; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_INSTRUMENT_THE_WORLD; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_MAX_EXCEPTION_PER_SECOND; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_MAX_PAYLOAD_SIZE; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_METRICS_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_POLL_INTERVAL; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_PROBE_FILE_LOCATION; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_REDACTED_IDENTIFIERS; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_REDACTED_TYPES; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_REDACTION_EXCLUDED_IDENTIFIERS; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_SYMBOL_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_SYMBOL_FLUSH_THRESHOLD; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_SYMBOL_FORCE_UPLOAD; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_SYMBOL_INCLUDES; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_UPLOAD_BATCH_SIZE; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_UPLOAD_FLUSH_INTERVAL; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_UPLOAD_TIMEOUT; -import static datadog.trace.api.config.DebuggerConfig.DEBUGGER_VERIFY_BYTECODE; -import static datadog.trace.api.config.DebuggerConfig.EXCEPTION_REPLAY_ENABLED; -import static datadog.trace.api.config.DebuggerConfig.THIRD_PARTY_EXCLUDES; -import static datadog.trace.api.config.DebuggerConfig.THIRD_PARTY_INCLUDES; -import static datadog.trace.api.config.GeneralConfig.API_KEY; -import static datadog.trace.api.config.GeneralConfig.API_KEY_FILE; -import static datadog.trace.api.config.GeneralConfig.APPLICATION_KEY; -import static datadog.trace.api.config.GeneralConfig.APPLICATION_KEY_FILE; -import static datadog.trace.api.config.GeneralConfig.AZURE_APP_SERVICES; -import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_COMMAND_PATTERN; -import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.DATA_STREAMS_BUCKET_DURATION_SECONDS; -import static datadog.trace.api.config.GeneralConfig.DATA_STREAMS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_ARGS; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_HOST; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_NAMED_PIPE; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_PATH; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_PORT; -import static datadog.trace.api.config.GeneralConfig.DOGSTATSD_START_DELAY; -import static datadog.trace.api.config.GeneralConfig.ENV; -import static datadog.trace.api.config.GeneralConfig.GLOBAL_TAGS; -import static datadog.trace.api.config.GeneralConfig.HEALTH_METRICS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.HEALTH_METRICS_STATSD_HOST; -import static datadog.trace.api.config.GeneralConfig.HEALTH_METRICS_STATSD_PORT; -import static datadog.trace.api.config.GeneralConfig.LOG_LEVEL; -import static datadog.trace.api.config.GeneralConfig.PERF_METRICS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.PRIMARY_TAG; -import static datadog.trace.api.config.GeneralConfig.RUNTIME_ID_ENABLED; -import static datadog.trace.api.config.GeneralConfig.RUNTIME_METRICS_ENABLED; +import static datadog.trace.api.config.DebuggerConfig.*; +import static datadog.trace.api.config.GeneralConfig.*; import static datadog.trace.api.config.GeneralConfig.SERVICE_NAME; -import static datadog.trace.api.config.GeneralConfig.SITE; -import static datadog.trace.api.config.GeneralConfig.STARTUP_LOGS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.STATSD_CLIENT_QUEUE_SIZE; -import static datadog.trace.api.config.GeneralConfig.STATSD_CLIENT_SOCKET_BUFFER; -import static datadog.trace.api.config.GeneralConfig.STATSD_CLIENT_SOCKET_TIMEOUT; -import static datadog.trace.api.config.GeneralConfig.TAGS; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_DEPENDENCY_COLLECTION_ENABLED; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_DEPENDENCY_RESOLUTION_QUEUE_SIZE; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_EXTENDED_HEARTBEAT_INTERVAL; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_HEARTBEAT_INTERVAL; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_LOG_COLLECTION_ENABLED; -import static datadog.trace.api.config.GeneralConfig.TELEMETRY_METRICS_INTERVAL; -import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_BUFFERING_ENABLED; -import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_ENABLED; -import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_IGNORED_RESOURCES; -import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_MAX_AGGREGATES; -import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_MAX_PENDING; -import static datadog.trace.api.config.GeneralConfig.TRACE_DEBUG; -import static datadog.trace.api.config.GeneralConfig.TRACE_TAGS; -import static datadog.trace.api.config.GeneralConfig.TRACE_TRIAGE; -import static datadog.trace.api.config.GeneralConfig.TRIAGE_REPORT_DIR; -import static datadog.trace.api.config.GeneralConfig.TRIAGE_REPORT_TRIGGER; -import static datadog.trace.api.config.GeneralConfig.VERSION; -import static datadog.trace.api.config.IastConfig.IAST_ANONYMOUS_CLASSES_ENABLED; -import static datadog.trace.api.config.IastConfig.IAST_CONTEXT_MODE; -import static datadog.trace.api.config.IastConfig.IAST_DEBUG_ENABLED; -import static datadog.trace.api.config.IastConfig.IAST_DETECTION_MODE; -import static datadog.trace.api.config.IastConfig.IAST_HARDCODED_SECRET_ENABLED; -import static datadog.trace.api.config.IastConfig.IAST_REDACTION_ENABLED; -import static datadog.trace.api.config.IastConfig.IAST_REDACTION_NAME_PATTERN; -import static datadog.trace.api.config.IastConfig.IAST_REDACTION_VALUE_PATTERN; -import static datadog.trace.api.config.IastConfig.IAST_SOURCE_MAPPING_ENABLED; -import static datadog.trace.api.config.IastConfig.IAST_SOURCE_MAPPING_MAX_SIZE; -import static datadog.trace.api.config.IastConfig.IAST_STACKTRACE_LEAK_SUPPRESS; -import static datadog.trace.api.config.IastConfig.IAST_TELEMETRY_VERBOSITY; -import static datadog.trace.api.config.IastConfig.IAST_TRUNCATION_MAX_VALUE_LENGTH; -import static datadog.trace.api.config.IastConfig.IAST_WEAK_CIPHER_ALGORITHMS; -import static datadog.trace.api.config.IastConfig.IAST_WEAK_HASH_ALGORITHMS; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_CHECK_PERIOD; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_CONFIG; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_CONFIG_DIR; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_ENABLED; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_INITIAL_REFRESH_BEANS_PERIOD; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_METRICS_CONFIGS; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_MULTIPLE_RUNTIME_SERVICES_ENABLED; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_MULTIPLE_RUNTIME_SERVICES_LIMIT; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_REFRESH_BEANS_PERIOD; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_START_DELAY; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_STATSD_HOST; -import static datadog.trace.api.config.JmxFetchConfig.JMX_FETCH_STATSD_PORT; -import static datadog.trace.api.config.JmxFetchConfig.JMX_TAGS; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_FILE_OLD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_FILE_VERY_OLD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_OLD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_VERY_OLD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_BACKPRESSURE_SAMPLE_LIMIT_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_BACKPRESSURE_SAMPLING_ENABLED; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_BACKPRESSURE_SAMPLING_ENABLED_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_ENABLED; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_DIRECT_ALLOCATION_SAMPLE_LIMIT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_DIRECT_ALLOCATION_SAMPLE_LIMIT_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_HISTOGRAM_MAX_COLLECTION_SIZE; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_HISTOGRAM_MAX_COLLECTION_SIZE_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_HISTOGRAM_TOP_ITEMS; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_HISTOGRAM_TOP_ITEMS_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_RECORD_MESSAGE; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_RECORD_MESSAGE_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_SAMPLE_LIMIT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCEPTION_SAMPLE_LIMIT_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_EXCLUDE_AGENT_THREADS; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_PROXY_HOST; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_PROXY_PASSWORD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_PROXY_PORT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_PROXY_PORT_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_PROXY_USERNAME; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_START_DELAY; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_START_DELAY_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_START_FORCE_FIRST; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_START_FORCE_FIRST_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_TAGS; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_TEMPLATE_OVERRIDE_FILE; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_COMPRESSION; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_COMPRESSION_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_PERIOD; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_PERIOD_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_SUMMARY_ON_413; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_SUMMARY_ON_413_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_TIMEOUT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_UPLOAD_TIMEOUT_DEFAULT; -import static datadog.trace.api.config.ProfilingConfig.PROFILING_URL; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIGURATION_ENABLED; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_ENABLED; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_INTEGRITY_CHECK_ENABLED; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_MAX_EXTRA_SERVICES; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_MAX_PAYLOAD_SIZE; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_POLL_INTERVAL_SECONDS; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_TARGETS_KEY; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_TARGETS_KEY_ID; -import static datadog.trace.api.config.RemoteConfigConfig.REMOTE_CONFIG_URL; -import static datadog.trace.api.config.TraceInstrumentationConfig.AXIS_PROMOTE_RESOURCE_NAME; -import static datadog.trace.api.config.TraceInstrumentationConfig.COUCHBASE_INTERNAL_SPANS_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_HOST; -import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE; -import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE_TYPE_SUFFIX; -import static datadog.trace.api.config.TraceInstrumentationConfig.DB_DBM_PROPAGATION_MODE_MODE; -import static datadog.trace.api.config.TraceInstrumentationConfig.ELASTICSEARCH_BODY_AND_PARAMS_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.ELASTICSEARCH_BODY_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.ELASTICSEARCH_PARAMS_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.GOOGLE_PUBSUB_IGNORED_GRPC_METHODS; -import static datadog.trace.api.config.TraceInstrumentationConfig.GRPC_CLIENT_ERROR_STATUSES; -import static datadog.trace.api.config.TraceInstrumentationConfig.GRPC_IGNORED_INBOUND_METHODS; -import static datadog.trace.api.config.TraceInstrumentationConfig.GRPC_IGNORED_OUTBOUND_METHODS; -import static datadog.trace.api.config.TraceInstrumentationConfig.GRPC_SERVER_ERROR_STATUSES; -import static datadog.trace.api.config.TraceInstrumentationConfig.GRPC_SERVER_TRIM_PACKAGE_RESOURCE; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_CLIENT_TAG_HEADERS; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_CLIENT_TAG_QUERY_STRING; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_DECODED_RESOURCE_PRESERVE_SPACES; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_ROUTE_BASED_NAMING; -import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING; -import static datadog.trace.api.config.TraceInstrumentationConfig.HYSTRIX_MEASURED_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.HYSTRIX_TAGS_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.IGNITE_CACHE_INCLUDE_KEYS; -import static datadog.trace.api.config.TraceInstrumentationConfig.INTEGRATION_SYNAPSE_LEGACY_OPERATION_NAME; -import static datadog.trace.api.config.TraceInstrumentationConfig.JAX_RS_EXCEPTION_AS_ERROR_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.JMS_PROPAGATION_DISABLED_QUEUES; -import static datadog.trace.api.config.TraceInstrumentationConfig.JMS_PROPAGATION_DISABLED_TOPICS; -import static datadog.trace.api.config.TraceInstrumentationConfig.JMS_UNACKNOWLEDGED_MAX_AGE; -import static datadog.trace.api.config.TraceInstrumentationConfig.KAFKA_CLIENT_BASE64_DECODING_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.KAFKA_CLIENT_PROPAGATION_DISABLED_TOPICS; -import static datadog.trace.api.config.TraceInstrumentationConfig.LOGS_INJECTION; -import static datadog.trace.api.config.TraceInstrumentationConfig.LOGS_INJECTION_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.MESSAGE_BROKER_SPLIT_BY_DESTINATION; -import static datadog.trace.api.config.TraceInstrumentationConfig.OBFUSCATION_QUERY_STRING_REGEXP; -import static datadog.trace.api.config.TraceInstrumentationConfig.PLAY_REPORT_HTTP_STATUS; -import static datadog.trace.api.config.TraceInstrumentationConfig.RABBIT_INCLUDE_ROUTINGKEY_IN_RESOURCE; -import static datadog.trace.api.config.TraceInstrumentationConfig.RABBIT_PROPAGATION_DISABLED_EXCHANGES; -import static datadog.trace.api.config.TraceInstrumentationConfig.RABBIT_PROPAGATION_DISABLED_QUEUES; -import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ASYNC_TIMEOUT_ERROR; -import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_PRINCIPAL_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ROOT_CONTEXT_SERVICE_NAME; -import static datadog.trace.api.config.TraceInstrumentationConfig.SPARK_APP_NAME_AS_SERVICE; -import static datadog.trace.api.config.TraceInstrumentationConfig.SPARK_TASK_HISTOGRAM_ENABLED; -import static datadog.trace.api.config.TraceInstrumentationConfig.SPRING_DATA_REPOSITORY_INTERFACE_RESOURCE_NAME; -import static datadog.trace.api.config.TracerConfig.AGENT_HOST; -import static datadog.trace.api.config.TracerConfig.AGENT_NAMED_PIPE; -import static datadog.trace.api.config.TracerConfig.AGENT_PORT_LEGACY; -import static datadog.trace.api.config.TracerConfig.AGENT_TIMEOUT; -import static datadog.trace.api.config.TracerConfig.AGENT_UNIX_DOMAIN_SOCKET; -import static datadog.trace.api.config.TracerConfig.BAGGAGE_MAPPING; -import static datadog.trace.api.config.TracerConfig.CLIENT_IP_ENABLED; -import static datadog.trace.api.config.TracerConfig.CLOCK_SYNC_PERIOD; -import static datadog.trace.api.config.TracerConfig.ENABLE_TRACE_AGENT_V05; -import static datadog.trace.api.config.TracerConfig.HEADER_TAGS; -import static datadog.trace.api.config.TracerConfig.HTTP_CLIENT_ERROR_STATUSES; -import static datadog.trace.api.config.TracerConfig.HTTP_SERVER_ERROR_STATUSES; -import static datadog.trace.api.config.TracerConfig.ID_GENERATION_STRATEGY; -import static datadog.trace.api.config.TracerConfig.PARTIAL_FLUSH_ENABLED; -import static datadog.trace.api.config.TracerConfig.PARTIAL_FLUSH_MIN_SPANS; -import static datadog.trace.api.config.TracerConfig.PRIORITY_SAMPLING; -import static datadog.trace.api.config.TracerConfig.PRIORITY_SAMPLING_FORCE; -import static datadog.trace.api.config.TracerConfig.PROPAGATION_EXTRACT_LOG_HEADER_NAMES_ENABLED; -import static datadog.trace.api.config.TracerConfig.PROPAGATION_STYLE_EXTRACT; -import static datadog.trace.api.config.TracerConfig.PROPAGATION_STYLE_INJECT; -import static datadog.trace.api.config.TracerConfig.PROXY_NO_PROXY; -import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS; -import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS_COMMA_ALLOWED; -import static datadog.trace.api.config.TracerConfig.RESPONSE_HEADER_TAGS; -import static datadog.trace.api.config.TracerConfig.SCOPE_DEPTH_LIMIT; -import static datadog.trace.api.config.TracerConfig.SCOPE_INHERIT_ASYNC_PROPAGATION; -import static datadog.trace.api.config.TracerConfig.SCOPE_ITERATION_KEEP_ALIVE; -import static datadog.trace.api.config.TracerConfig.SCOPE_STRICT_MODE; -import static datadog.trace.api.config.TracerConfig.SECURE_RANDOM; -import static datadog.trace.api.config.TracerConfig.SERVICE_MAPPING; -import static datadog.trace.api.config.TracerConfig.SPAN_SAMPLING_RULES; -import static datadog.trace.api.config.TracerConfig.SPAN_SAMPLING_RULES_FILE; -import static datadog.trace.api.config.TracerConfig.SPAN_TAGS; -import static datadog.trace.api.config.TracerConfig.SPLIT_BY_TAGS; -import static datadog.trace.api.config.TracerConfig.TRACE_128_BIT_TRACEID_GENERATION_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_ARGS; -import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_PATH; -import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_PORT; -import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_URL; -import static datadog.trace.api.config.TracerConfig.TRACE_ANALYTICS_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_CLIENT_IP_HEADER; -import static datadog.trace.api.config.TracerConfig.TRACE_CLIENT_IP_RESOLVER_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_GIT_METADATA_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_HTTP_CLIENT_PATH_RESOURCE_NAME_MAPPING; -import static datadog.trace.api.config.TracerConfig.TRACE_HTTP_RESOURCE_REMOVE_TRAILING_SLASH; -import static datadog.trace.api.config.TracerConfig.TRACE_HTTP_SERVER_PATH_RESOURCE_NAME_MAPPING; -import static datadog.trace.api.config.TracerConfig.TRACE_PEER_SERVICE_COMPONENT_OVERRIDES; -import static datadog.trace.api.config.TracerConfig.TRACE_PEER_SERVICE_DEFAULTS_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_PEER_SERVICE_MAPPING; -import static datadog.trace.api.config.TracerConfig.TRACE_POST_PROCESSING_TIMEOUT; -import static datadog.trace.api.config.TracerConfig.TRACE_PROPAGATION_EXTRACT_FIRST; -import static datadog.trace.api.config.TracerConfig.TRACE_PROPAGATION_STYLE; -import static datadog.trace.api.config.TracerConfig.TRACE_PROPAGATION_STYLE_EXTRACT; -import static datadog.trace.api.config.TracerConfig.TRACE_PROPAGATION_STYLE_INJECT; -import static datadog.trace.api.config.TracerConfig.TRACE_RATE_LIMIT; -import static datadog.trace.api.config.TracerConfig.TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_REPORT_HOSTNAME; -import static datadog.trace.api.config.TracerConfig.TRACE_RESOLVER_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLE_RATE; -import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLING_OPERATION_RULES; -import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLING_RULES; -import static datadog.trace.api.config.TracerConfig.TRACE_SAMPLING_SERVICE_RULES; -import static datadog.trace.api.config.TracerConfig.TRACE_SPAN_ATTRIBUTE_SCHEMA; -import static datadog.trace.api.config.TracerConfig.TRACE_STRICT_WRITES_ENABLED; -import static datadog.trace.api.config.TracerConfig.TRACE_X_DATADOG_TAGS_MAX_LENGTH; -import static datadog.trace.api.config.TracerConfig.WRITER_BAGGAGE_INJECT; -import static datadog.trace.api.config.TracerConfig.WRITER_TYPE; +import static datadog.trace.api.config.IastConfig.*; +import static datadog.trace.api.config.JmxFetchConfig.*; +import static datadog.trace.api.config.ProfilingConfig.*; +import static datadog.trace.api.config.RemoteConfigConfig.*; +import static datadog.trace.api.config.TraceInstrumentationConfig.*; +import static datadog.trace.api.config.TracerConfig.*; import static datadog.trace.api.iast.IastDetectionMode.DEFAULT; import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY; import static datadog.trace.util.CollectionUtils.tryMakeImmutableList; @@ -523,30 +45,13 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.UnknownHostException; +import java.net.*; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.BitSet; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.SortedSet; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.function.Supplier; @@ -853,6 +358,8 @@ public static String getHostName() { private final boolean ciVisibilityTelemetryEnabled; private final long ciVisibilityRumFlushWaitMillis; private final boolean ciVisibilityAutoInjected; + private final String ciVisibilityRemoteEnvVarsProviderUrl; + private final String ciVisibilityRemoteEnvVarsProviderKey; private final boolean remoteConfigEnabled; private final boolean remoteConfigIntegrityCheckEnabled; @@ -1928,6 +1435,10 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) configProvider.getLong(CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS, 500); ciVisibilityAutoInjected = Strings.isNotBlank(configProvider.getString(CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER)); + ciVisibilityRemoteEnvVarsProviderUrl = + configProvider.getString(CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_URL); + ciVisibilityRemoteEnvVarsProviderKey = + configProvider.getString(CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_KEY); remoteConfigEnabled = configProvider.getBoolean( @@ -3291,6 +2802,14 @@ public boolean isCiVisibilityAutoInjected() { return ciVisibilityAutoInjected; } + public String getCiVisibilityRemoteEnvVarsProviderUrl() { + return ciVisibilityRemoteEnvVarsProviderUrl; + } + + public String getCiVisibilityRemoteEnvVarsProviderKey() { + return ciVisibilityRemoteEnvVarsProviderKey; + } + public String getAppSecRulesFile() { return appSecRulesFile; }