Skip to content

Commit 1c0de44

Browse files
committed
Surface process tags on telemetry payloads
1 parent 9a79db3 commit 1c0de44

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

telemetry/src/main/java/datadog/telemetry/TelemetryRequestBody.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import datadog.trace.api.ConfigSetting;
1313
import datadog.trace.api.DDTags;
1414
import datadog.trace.api.Platform;
15+
import datadog.trace.api.ProcessTags;
1516
import datadog.trace.api.telemetry.Endpoint;
1617
import datadog.trace.api.telemetry.ProductChange.ProductType;
1718
import java.io.IOException;
@@ -87,6 +88,10 @@ public void beginRequest(boolean debug) {
8788
bodyWriter.name("runtime_name").value(commonData.runtimeName);
8889
bodyWriter.name("runtime_version").value(commonData.runtimeVersion);
8990
bodyWriter.name("runtime_patches").value(commonData.runtimePatches); // optional
91+
final CharSequence processTags = ProcessTags.getTagsForSerialization();
92+
if (processTags != null) {
93+
bodyWriter.name("process_tags").value(processTags.toString());
94+
}
9095
bodyWriter.endObject();
9196

9297
if (debug) {

telemetry/src/test/groovy/datadog/telemetry/TelemetryRequestBodySpecification.groovy

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package datadog.telemetry
22

3+
4+
import com.squareup.moshi.Moshi
5+
import com.squareup.moshi.Types
36
import datadog.telemetry.api.RequestType
47
import datadog.trace.api.ConfigOrigin
58
import datadog.trace.api.ConfigSetting
9+
import datadog.trace.api.ProcessTags
610
import datadog.trace.api.telemetry.ProductChange
7-
import okio.Buffer
11+
import datadog.trace.test.util.DDSpecification
812
import okhttp3.RequestBody
9-
import spock.lang.Specification
13+
import okio.Buffer
1014

15+
import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED
1116
import static datadog.trace.api.telemetry.ProductChange.ProductType.APPSEC
1217
import static datadog.trace.api.telemetry.ProductChange.ProductType.DYNAMIC_INSTRUMENTATION
1318
import static datadog.trace.api.telemetry.ProductChange.ProductType.PROFILER
1419

1520
/**
1621
* This test only verifies non-functional specifics that are not covered in TelemetryServiceSpecification
1722
*/
18-
class TelemetryRequestBodySpecification extends Specification {
23+
class TelemetryRequestBodySpecification extends DDSpecification {
1924

2025
def 'throw SerializationException in case of JSON nesting problem'() {
2126
setup:
@@ -112,17 +117,17 @@ class TelemetryRequestBodySpecification extends Specification {
112117
drainToString(req).contains("\"debug\":true")
113118
}
114119

115-
void 'test writeProducts'(){
120+
void 'test writeProducts'() {
116121
setup:
117122
TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_PRODUCT_CHANGE)
118123
final products = new HashMap<ProductChange.ProductType, Boolean>()
119-
if(appsecChange) {
124+
if (appsecChange) {
120125
products.put(APPSEC, appsecEnabled)
121126
}
122-
if(profilerChange) {
127+
if (profilerChange) {
123128
products.put(PROFILER, profilerEnabled)
124129
}
125-
if(dynamicInstrumentationChange) {
130+
if (dynamicInstrumentationChange) {
126131
products.put(DYNAMIC_INSTRUMENTATION, dynamicInstrumentationEnabled)
127132
}
128133

@@ -154,4 +159,33 @@ class TelemetryRequestBodySpecification extends Specification {
154159
buf.read(bytes)
155160
return new String(bytes)
156161
}
162+
163+
def 'Should propagate process tags when enabled #processTagsEnabled'() {
164+
setup:
165+
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "$processTagsEnabled")
166+
ProcessTags.reset()
167+
TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_STARTED)
168+
169+
when:
170+
req.beginRequest(true)
171+
req.endRequest()
172+
173+
then:
174+
def type = Types.newParameterizedType(Map, String, Object)
175+
def adapter = new Moshi.Builder().build().adapter(type)
176+
def parsed = (Map<String, Object>)adapter.fromJson(drainToString(req))
177+
def parsedTags = ((Map<String, Object>)parsed.get("application")).get("process_tags")
178+
if (processTagsEnabled) {
179+
assert parsedTags == ProcessTags.tagsForSerialization.toString()
180+
} else {
181+
assert parsedTags == null
182+
}
183+
184+
cleanup:
185+
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false")
186+
ProcessTags.reset()
187+
188+
where:
189+
processTagsEnabled << [true, false]
190+
}
157191
}

0 commit comments

Comments
 (0)