Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datadog.trace.api.ConfigSetting;
import datadog.trace.api.DDTags;
import datadog.trace.api.Platform;
import datadog.trace.api.ProcessTags;
import datadog.trace.api.telemetry.Endpoint;
import datadog.trace.api.telemetry.ProductChange.ProductType;
import java.io.IOException;
Expand Down Expand Up @@ -87,6 +88,10 @@ public void beginRequest(boolean debug) {
bodyWriter.name("runtime_name").value(commonData.runtimeName);
bodyWriter.name("runtime_version").value(commonData.runtimeVersion);
bodyWriter.name("runtime_patches").value(commonData.runtimePatches); // optional
final CharSequence processTags = ProcessTags.getTagsForSerialization();
if (processTags != null) {
bodyWriter.name("process_tags").value(processTags.toString());
}
bodyWriter.endObject();

if (debug) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package datadog.telemetry


import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import datadog.telemetry.api.RequestType
import datadog.trace.api.ConfigOrigin
import datadog.trace.api.ConfigSetting
import datadog.trace.api.ProcessTags
import datadog.trace.api.telemetry.ProductChange
import okio.Buffer
import datadog.trace.test.util.DDSpecification
import okhttp3.RequestBody
import spock.lang.Specification
import okio.Buffer

import static datadog.trace.api.config.GeneralConfig.EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED
import static datadog.trace.api.telemetry.ProductChange.ProductType.APPSEC
import static datadog.trace.api.telemetry.ProductChange.ProductType.DYNAMIC_INSTRUMENTATION
import static datadog.trace.api.telemetry.ProductChange.ProductType.PROFILER

/**
* This test only verifies non-functional specifics that are not covered in TelemetryServiceSpecification
*/
class TelemetryRequestBodySpecification extends Specification {
class TelemetryRequestBodySpecification extends DDSpecification {

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

void 'test writeProducts'(){
void 'test writeProducts'() {
setup:
TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_PRODUCT_CHANGE)
final products = new HashMap<ProductChange.ProductType, Boolean>()
if(appsecChange) {
if (appsecChange) {
products.put(APPSEC, appsecEnabled)
}
if(profilerChange) {
if (profilerChange) {
products.put(PROFILER, profilerEnabled)
}
if(dynamicInstrumentationChange) {
if (dynamicInstrumentationChange) {
products.put(DYNAMIC_INSTRUMENTATION, dynamicInstrumentationEnabled)
}

Expand Down Expand Up @@ -154,4 +159,33 @@ class TelemetryRequestBodySpecification extends Specification {
buf.read(bytes)
return new String(bytes)
}

def 'Should propagate process tags when enabled #processTagsEnabled'() {
setup:
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "$processTagsEnabled")
ProcessTags.reset()
TelemetryRequestBody req = new TelemetryRequestBody(RequestType.APP_STARTED)

when:
req.beginRequest(true)
req.endRequest()

then:
def type = Types.newParameterizedType(Map, String, Object)
def adapter = new Moshi.Builder().build().adapter(type)
def parsed = (Map<String, Object>)adapter.fromJson(drainToString(req))
def parsedTags = ((Map<String, Object>)parsed.get("application")).get("process_tags")
if (processTagsEnabled) {
assert parsedTags == ProcessTags.tagsForSerialization.toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not critical, but expected parsed tags could be a data column to avoid this conditional logic here

} else {
assert parsedTags == null
}

cleanup:
injectSysConfig(EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED, "false")
ProcessTags.reset()

where:
processTagsEnabled << [true, false]
}
}
Loading