11package datadog .trace .api .git ;
22
3- import static datadog .trace .api .git .GitInfo .DD_GIT_BRANCH ;
4- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_DATE ;
5- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_EMAIL ;
6- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_AUTHOR_NAME ;
7- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_DATE ;
8- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_EMAIL ;
9- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_COMMITTER_NAME ;
10- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_MESSAGE ;
11- import static datadog .trace .api .git .GitInfo .DD_GIT_COMMIT_SHA ;
12- import static datadog .trace .api .git .GitInfo .DD_GIT_REPOSITORY_URL ;
13- import static datadog .trace .api .git .GitInfo .DD_GIT_TAG ;
14-
153import datadog .trace .api .Config ;
16- import datadog .trace .api .ConfigCollector ;
17- import datadog .trace .api .ConfigOrigin ;
184import datadog .trace .api .config .GeneralConfig ;
5+ import datadog .trace .bootstrap .config .provider .ConfigProvider ;
196import datadog .trace .bootstrap .instrumentation .api .Tags ;
7+ import datadog .trace .util .Strings ;
208import javax .annotation .Nullable ;
219import org .slf4j .Logger ;
2210import org .slf4j .LoggerFactory ;
2311
2412public class UserSuppliedGitInfoBuilder implements GitInfoBuilder {
2513
14+ public static final String DD_GIT_REPOSITORY_URL = "git.repository.url" ;
15+ public static final String DD_GIT_BRANCH = "git.branch" ;
16+ public static final String DD_GIT_TAG = "git.tag" ;
17+ public static final String DD_GIT_COMMIT_SHA = "git.commit.sha" ;
18+ public static final String DD_GIT_COMMIT_MESSAGE = "git.commit.message" ;
19+ public static final String DD_GIT_COMMIT_AUTHOR_NAME = "git.commit.author.name" ;
20+ public static final String DD_GIT_COMMIT_AUTHOR_EMAIL = "git.commit.author.email" ;
21+ public static final String DD_GIT_COMMIT_AUTHOR_DATE = "git.commit.author.date" ;
22+ public static final String DD_GIT_COMMIT_COMMITTER_NAME = "git.commit.committer.name" ;
23+ public static final String DD_GIT_COMMIT_COMMITTER_EMAIL = "git.commit.committer.email" ;
24+ public static final String DD_GIT_COMMIT_COMMITTER_DATE = "git.commit.committer.date" ;
2625 private static final Logger log = LoggerFactory .getLogger (UserSuppliedGitInfoBuilder .class );
2726
2827 @ Override
2928 public GitInfo build (@ Nullable String repositoryPath ) {
30- String gitRepositoryUrl = System .getenv (DD_GIT_REPOSITORY_URL );
29+ ConfigProvider configProvider = ConfigProvider .getInstance ();
30+
31+ String gitRepositoryUrl = configProvider .getString (DD_GIT_REPOSITORY_URL );
3132 if (gitRepositoryUrl == null ) {
3233 gitRepositoryUrl = Config .get ().getGlobalTags ().get (Tags .GIT_REPOSITORY_URL );
3334 }
@@ -36,9 +37,9 @@ public GitInfo build(@Nullable String repositoryPath) {
3637 // using the value returned by the CI Provider, so
3738 // we need to normalize the value. Also, it can contain
3839 // the tag (e.g. origin/tags/0.1.0)
39- String gitTag = System . getenv (DD_GIT_TAG );
40+ String gitTag = configProvider . getString (DD_GIT_TAG );
4041 String gitBranch = null ;
41- final String gitBranchOrTag = System . getenv (DD_GIT_BRANCH );
42+ final String gitBranchOrTag = configProvider . getString (DD_GIT_BRANCH );
4243 if (gitBranchOrTag != null ) {
4344 if (!GitUtils .isTagReference (gitBranchOrTag )) {
4445 gitBranch = GitUtils .normalizeBranch (gitBranchOrTag );
@@ -47,21 +48,18 @@ public GitInfo build(@Nullable String repositoryPath) {
4748 }
4849 }
4950
50- String gitCommitSha = System . getenv (DD_GIT_COMMIT_SHA );
51+ String gitCommitSha = configProvider . getString (DD_GIT_COMMIT_SHA );
5152 if (gitCommitSha == null ) {
5253 gitCommitSha = Config .get ().getGlobalTags ().get (Tags .GIT_COMMIT_SHA );
5354 }
5455
55- ConfigCollector .get ().put (DD_GIT_REPOSITORY_URL , gitRepositoryUrl , ConfigOrigin .ENV );
56- ConfigCollector .get ().put (DD_GIT_COMMIT_SHA , gitCommitSha , ConfigOrigin .ENV );
57-
58- final String gitCommitMessage = System .getenv (DD_GIT_COMMIT_MESSAGE );
59- final String gitCommitAuthorName = System .getenv (DD_GIT_COMMIT_AUTHOR_NAME );
60- final String gitCommitAuthorEmail = System .getenv (DD_GIT_COMMIT_AUTHOR_EMAIL );
61- final String gitCommitAuthorDate = System .getenv (DD_GIT_COMMIT_AUTHOR_DATE );
62- final String gitCommitCommitterName = System .getenv (DD_GIT_COMMIT_COMMITTER_NAME );
63- final String gitCommitCommitterEmail = System .getenv (DD_GIT_COMMIT_COMMITTER_EMAIL );
64- final String gitCommitCommitterDate = System .getenv (DD_GIT_COMMIT_COMMITTER_DATE );
56+ final String gitCommitMessage = configProvider .getString (DD_GIT_COMMIT_MESSAGE );
57+ final String gitCommitAuthorName = configProvider .getString (DD_GIT_COMMIT_AUTHOR_NAME );
58+ final String gitCommitAuthorEmail = configProvider .getString (DD_GIT_COMMIT_AUTHOR_EMAIL );
59+ final String gitCommitAuthorDate = configProvider .getString (DD_GIT_COMMIT_AUTHOR_DATE );
60+ final String gitCommitCommitterName = configProvider .getString (DD_GIT_COMMIT_COMMITTER_NAME );
61+ final String gitCommitCommitterEmail = configProvider .getString (DD_GIT_COMMIT_COMMITTER_EMAIL );
62+ final String gitCommitCommitterDate = configProvider .getString (DD_GIT_COMMIT_COMMITTER_DATE );
6563
6664 GitInfo gitInfo =
6765 new GitInfo (
@@ -82,8 +80,8 @@ public GitInfo build(@Nullable String repositoryPath) {
8280 if (repoUrl == null || repoUrl .isEmpty ()) {
8381 log .error (
8482 "Could not resolve git repository URL (can be provided via "
85- + GitInfo . DD_GIT_REPOSITORY_URL
86- + " env var, "
83+ + Strings . propertyNameToEnvironmentVariableName ( DD_GIT_REPOSITORY_URL )
84+ + " env var or corresponding system property , "
8785 + GeneralConfig .TAGS
8886 + " config property or by embedding git metadata at build time)" );
8987 }
@@ -94,10 +92,10 @@ public GitInfo build(@Nullable String repositoryPath) {
9492 "Git commit SHA could not be resolved or is invalid: "
9593 + commitSha
9694 + " (can be provided via "
97- + GitInfo . DD_GIT_COMMIT_SHA
98- + " env var, "
95+ + Strings . propertyNameToEnvironmentVariableName ( DD_GIT_COMMIT_SHA )
96+ + " env var or corresponding system property , "
9997 + GeneralConfig .TAGS
100- + " config property or by embedding git metadata at build time; must be a full-length SHA_ " );
98+ + " config property or by embedding git metadata at build time; must be a full-length SHA " );
10199 }
102100 }
103101
0 commit comments