Skip to content

Commit 2126aed

Browse files
fix: filter on iteration instead of using a copy of the tags
1 parent aa9d3fa commit 2126aed

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

dd-trace-core/src/main/java/datadog/trace/civisibility/writer/ddintake/CiTestCycleMapperV1.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import datadog.communication.serialization.msgpack.MsgPackWriter;
1010
import datadog.trace.api.DDTags;
1111
import datadog.trace.api.DDTraceId;
12-
import datadog.trace.api.TagMap;
1312
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
1413
import datadog.trace.api.civisibility.InstrumentationBridge;
1514
import datadog.trace.api.civisibility.telemetry.CiVisibilityDistributionMetric;
@@ -59,9 +58,14 @@ public class CiTestCycleMapperV1 implements RemoteMapper {
5958

6059
private static final UTF8BytesString SPAN_TYPE = UTF8BytesString.create("span");
6160

62-
private static final Collection<String> DEFAULT_TOP_LEVEL_TAGS =
63-
Arrays.asList(
64-
Tags.TEST_SESSION_ID, Tags.TEST_MODULE_ID, Tags.TEST_SUITE_ID, Tags.ITR_CORRELATION_ID);
61+
private static final Set<String> DEFAULT_TOP_LEVEL_TAGS =
62+
Collections.unmodifiableSet(
63+
new HashSet<>(
64+
Arrays.asList(
65+
Tags.TEST_SESSION_ID,
66+
Tags.TEST_MODULE_ID,
67+
Tags.TEST_SUITE_ID,
68+
Tags.ITR_CORRELATION_ID)));
6569

6670
private final CiVisibilityWellKnownTags wellKnownTags;
6771
private final int size;
@@ -317,29 +321,29 @@ MetaWriter withWritable(Writable writable) {
317321

318322
@Override
319323
public void accept(Metadata metadata) {
320-
TagMap tags = metadata.getTags().copy();
321-
322-
for (String ignoredTag : DEFAULT_TOP_LEVEL_TAGS) {
323-
tags.remove(ignoredTag);
324-
}
325-
326-
int metaSize =
327-
metadata.getBaggage().size()
328-
+ tags.size()
329-
+ (null == metadata.getHttpStatusCode() ? 0 : 1);
324+
int metaSize = metadata.getBaggage().size() + (null == metadata.getHttpStatusCode() ? 0 : 1);
330325
int metricsSize = 0;
331-
for (Map.Entry<String, Object> tag : tags.entrySet()) {
326+
for (Map.Entry<String, Object> tag : metadata.getTags().entrySet()) {
327+
if (DEFAULT_TOP_LEVEL_TAGS.contains(tag.getKey())) {
328+
continue;
329+
}
332330
if (tag.getValue() instanceof Number) {
333331
++metricsSize;
334-
--metaSize;
332+
} else {
333+
++metaSize;
335334
}
336335
}
337336
writable.writeUTF8(METRICS);
338337
writable.startMap(metricsSize);
339-
for (Map.Entry<String, Object> entry : tags.entrySet()) {
340-
if (entry.getValue() instanceof Number) {
341-
writable.writeString(entry.getKey(), null);
342-
writable.writeObject(entry.getValue(), null);
338+
for (Map.Entry<String, Object> entry : metadata.getTags().entrySet()) {
339+
String key = entry.getKey();
340+
if (DEFAULT_TOP_LEVEL_TAGS.contains(key)) {
341+
continue;
342+
}
343+
Object value = entry.getValue();
344+
if (value instanceof Number) {
345+
writable.writeString(key, null);
346+
writable.writeObject(value, null);
343347
}
344348
}
345349

@@ -356,10 +360,14 @@ public void accept(Metadata metadata) {
356360
writable.writeUTF8(HTTP_STATUS);
357361
writable.writeUTF8(metadata.getHttpStatusCode());
358362
}
359-
for (Map.Entry<String, Object> entry : tags.entrySet()) {
363+
for (Map.Entry<String, Object> entry : metadata.getTags().entrySet()) {
364+
String key = entry.getKey();
365+
if (DEFAULT_TOP_LEVEL_TAGS.contains(key)) {
366+
continue;
367+
}
360368
Object value = entry.getValue();
361369
if (!(value instanceof Number)) {
362-
writable.writeString(entry.getKey(), null);
370+
writable.writeString(key, null);
363371
if (!(value instanceof Iterable)) {
364372
writable.writeObjectString(value, null);
365373
} else {

0 commit comments

Comments
 (0)