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 @@ -9,6 +9,7 @@
import datadog.communication.serialization.msgpack.MsgPackWriter;
import datadog.trace.api.DDTags;
import datadog.trace.api.DDTraceId;
import datadog.trace.api.TagMap;
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
import datadog.trace.api.civisibility.InstrumentationBridge;
import datadog.trace.api.civisibility.telemetry.CiVisibilityDistributionMetric;
Expand Down Expand Up @@ -84,16 +85,9 @@ public void map(List<? extends CoreSpan<?>> trace, Writable writable) {

for (final CoreSpan<?> span : trace) {
DDTraceId testSessionId = span.getTag(Tags.TEST_SESSION_ID);
span.removeTag(Tags.TEST_SESSION_ID);

Number testModuleId = span.getTag(Tags.TEST_MODULE_ID);
span.removeTag(Tags.TEST_MODULE_ID);

Number testSuiteId = span.getTag(Tags.TEST_SUITE_ID);
span.removeTag(Tags.TEST_SUITE_ID);

String itrCorrelationId = span.getTag(Tags.ITR_CORRELATION_ID);
span.removeTag(Tags.ITR_CORRELATION_ID);

int topLevelTagsCount = 0;
if (testSessionId != null) {
Expand Down Expand Up @@ -323,20 +317,26 @@ MetaWriter withWritable(Writable writable) {

@Override
public void accept(Metadata metadata) {
TagMap tags = metadata.getTags().copy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we try and estimate the overhead of this (with a test-environment run, for example)? Creating a copy of the tags map for every serialized span could be a big deal. I know there's an implementation of TagMap that is optimized for copying, but it isn't used by default still.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it will be less overhead to skip the DEFAULT_TOP_LEVEL_TAGS when iterating over the tag entries below.

Copy link
Contributor Author

@daniel-mohedano daniel-mohedano Sep 4, 2025

Choose a reason for hiding this comment

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

As discussed offline, I'll test the two implementations on test environment to see how it impacts performance 👍


for (String ignoredTag : DEFAULT_TOP_LEVEL_TAGS) {
tags.remove(ignoredTag);
}

int metaSize =
metadata.getBaggage().size()
+ metadata.getTags().size()
+ tags.size()
+ (null == metadata.getHttpStatusCode() ? 0 : 1);
int metricsSize = 0;
for (Map.Entry<String, Object> tag : metadata.getTags().entrySet()) {
for (Map.Entry<String, Object> tag : tags.entrySet()) {
if (tag.getValue() instanceof Number) {
++metricsSize;
--metaSize;
}
}
writable.writeUTF8(METRICS);
writable.startMap(metricsSize);
for (Map.Entry<String, Object> entry : metadata.getTags().entrySet()) {
for (Map.Entry<String, Object> entry : tags.entrySet()) {
if (entry.getValue() instanceof Number) {
writable.writeString(entry.getKey(), null);
writable.writeObject(entry.getValue(), null);
Expand All @@ -356,7 +356,7 @@ public void accept(Metadata metadata) {
writable.writeUTF8(HTTP_STATUS);
writable.writeUTF8(metadata.getHttpStatusCode());
}
for (Map.Entry<String, Object> entry : metadata.getTags().entrySet()) {
for (Map.Entry<String, Object> entry : tags.entrySet()) {
Object value = entry.getValue();
if (!(value instanceof Number)) {
writable.writeString(entry.getKey(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ class CiTestCycleMapperV1PayloadTest extends DDSpecification {
assert !spanContent.containsKey("parent_id")
}

def "verify result is not affected by successive mapping calls"(){
setup:
def span = generateRandomSpan(InternalSpanTypes.TEST, [
(Tags.TEST_SESSION_ID): DDTraceId.from(123),
(Tags.TEST_MODULE_ID) : 456,
(Tags.TEST_SUITE_ID) : 789,
])

when:
whenASpanIsWritten(span)
Map<String, Object> deserializedSpan = whenASpanIsWritten(span)

then:
verifyTopLevelTags(deserializedSpan, DDTraceId.from(123), 456, 789)

def spanContent = (Map<String, Object>) deserializedSpan.get("content")
assert spanContent.containsKey("trace_id")
assert spanContent.containsKey("span_id")
assert spanContent.containsKey("parent_id")
}

private static void verifyTopLevelTags(Map<String, Object> deserializedSpan, DDTraceId testSessionId, Long testModuleId, Long testSuiteId) {
Map<String, Object> deserializedSpanContent = (Map<String, Object>) deserializedSpan.get("content")
Map<String, Object> deserializedMetrics = (Map<String, Object>) deserializedSpanContent.get("metrics")
Expand Down