Skip to content

Commit fe96bf2

Browse files
committed
Add git repository and sha in RC request tags
Send git repository url and git commit sha as tags on each Remote Config request
1 parent 23bbe14 commit fe96bf2

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

remote-config/src/main/java/datadog/remoteconfig/PollerRequestFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import datadog.remoteconfig.tuf.RemoteConfigRequest.CachedTargetFile;
66
import datadog.remoteconfig.tuf.RemoteConfigRequest.ClientInfo.ClientState;
77
import datadog.trace.api.Config;
8+
import datadog.trace.api.git.GitInfo;
9+
import datadog.trace.api.git.GitInfoProvider;
10+
import datadog.trace.bootstrap.instrumentation.api.Tags;
811
import datadog.trace.util.TagsHelper;
912
import java.util.Arrays;
1013
import java.util.Collection;
@@ -126,6 +129,15 @@ private List<String> buildRequestTags() {
126129
Config.get().getGlobalTags().entrySet().stream()
127130
.map(entry -> entry.getKey() + ":" + entry.getValue())
128131
.collect(Collectors.toList());
132+
GitInfo gitInfo = GitInfoProvider.INSTANCE.getGitInfo();
133+
String repositoryURL = gitInfo.getRepositoryURL();
134+
if (repositoryURL != null) {
135+
tags.add(Tags.GIT_REPOSITORY_URL + ":" + repositoryURL);
136+
}
137+
String sha = gitInfo.getCommit().getSha();
138+
if (sha != null) {
139+
tags.add(Tags.GIT_COMMIT_SHA + ":" + sha);
140+
}
129141
tags.addAll(
130142
Arrays.asList(
131143
"env:" + this.env,

remote-config/src/main/java/datadog/remoteconfig/tuf/RemoteConfigRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ public String getServiceEnv() {
207207
public String getServiceVersion() {
208208
return this.serviceVersion;
209209
}
210+
211+
public List<String> getTags() {
212+
return tags;
213+
}
210214
}
211215

212216
private static class AgentInfo {

remote-config/src/test/groovy/datadog/remoteconfig/PollerRequestFactoryTest.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.remoteconfig
22

33
import datadog.remoteconfig.tuf.RemoteConfigRequest
4+
import datadog.trace.bootstrap.instrumentation.api.Tags
45
import datadog.trace.test.util.DDSpecification
56
import datadog.trace.api.Config
67

@@ -15,6 +16,7 @@ class PollerRequestFactoryTest extends DDSpecification {
1516
System.setProperty("dd.service", "Service Name")
1617
System.setProperty("dd.env", "PROD")
1718
System.setProperty("dd.tags", "version:1.0.0-SNAPSHOT")
19+
System.setProperty("dd.trace.global.tags", Tags.GIT_REPOSITORY_URL+":https://github.com/DataDog/dd-trace-java,"+Tags.GIT_COMMIT_SHA + ":1234")
1820
rebuildConfig()
1921
PollerRequestFactory factory = new PollerRequestFactory(Config.get(), TRACER_VERSION, CONTAINER_ID, INVALID_REMOTE_CONFIG_URL, null)
2022

@@ -25,5 +27,8 @@ class PollerRequestFactoryTest extends DDSpecification {
2527
request.client.tracerInfo.serviceName == "service_name"
2628
request.client.tracerInfo.serviceEnv == "prod"
2729
request.client.tracerInfo.serviceVersion == "1.0.0-snapshot"
30+
request.client.tracerInfo.tags.contains("env:PROD")
31+
request.client.tracerInfo.tags.contains(Tags.GIT_REPOSITORY_URL + ":https://github.com/DataDog/dd-trace-java")
32+
request.client.tracerInfo.tags.contains(Tags.GIT_COMMIT_SHA + ":1234")
2833
}
2934
}

0 commit comments

Comments
 (0)