Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9482232
Updating tests to account for API changes
dougqh Jan 12, 2026
8720c24
Adding tagIterator and valueIterator
dougqh Jan 12, 2026
fbec328
Adding checks for EntryIterator
dougqh Jan 12, 2026
2864bac
Removing EntryIterator and EntryChangeIterator
dougqh Jan 12, 2026
43bbea1
spotless
dougqh Jan 12, 2026
5fadff5
Merge branch 'master' into dougqh/tagmap-entryreader
dougqh Jan 13, 2026
3c0997f
Refining handling of primitive types
dougqh Jan 16, 2026
b192679
Refining comment in toBoolean
dougqh Jan 16, 2026
cffac87
Adding more TagValueConversionTest-s
dougqh Jan 16, 2026
8c51f7f
Adding Entry tests for byte and short boxes
dougqh Jan 16, 2026
17b1255
spotless
dougqh Jan 16, 2026
e18b404
Merge branch 'master' into dougqh/tagmap-entryreader
dougqh Jan 16, 2026
5698bff
Merge branch 'master' into dougqh/tagmap-entryreader
dougqh Jan 20, 2026
9d43d47
Direct TagMap.Entry support in AgentSpan / DDSpan
dougqh Jan 28, 2026
26cab22
Adding public create methods to TagMap.Entry
dougqh Jan 28, 2026
f6ceef1
spotless
dougqh Jan 28, 2026
501ade2
Merge branch 'master' into dougqh/fdirect-apis-for-tagmap-entry
dougqh Jan 29, 2026
40847ac
Fixed merge
dougqh Jan 29, 2026
d96ebfb
Clarifying comments
dougqh Jan 29, 2026
9f64448
Adding tests for TagMap.Entry.create
dougqh Jan 29, 2026
b7327b5
spotless
dougqh Jan 29, 2026
6fa193a
Comments
dougqh Jan 29, 2026
c97cdee
Merge branch 'master' into dougqh/fdirect-apis-for-tagmap-entry
dougqh Jan 29, 2026
531f63b
Adding test for TagMap.Entry setters
dougqh Jan 29, 2026
2b89bfc
Merge branch 'dougqh/fdirect-apis-for-tagmap-entry' of github.com:Dat…
dougqh Jan 29, 2026
db10ed5
Adding missing import
dougqh Jan 30, 2026
37d1009
spotless
dougqh Jan 30, 2026
6f2160f
Groovy codeNarc
dougqh Jan 30, 2026
4d0be98
Merge branch 'master' into dougqh/fdirect-apis-for-tagmap-entry
dougqh Jan 30, 2026
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 @@ -114,6 +114,11 @@ class TrackingSpanDecorator implements AgentSpan {
return delegate.setTag(key, value)
}

@Override
AgentSpan setTag(TagMap.EntryReader entry) {
return delegate.setTag(entry)
}

@Override
void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba) {
delegate.setRequestBlockingAction(rba)
Expand Down Expand Up @@ -184,6 +189,11 @@ class TrackingSpanDecorator implements AgentSpan {
return delegate.setMetric(key, value)
}

@Override
AgentSpan setMetric(TagMap.EntryReader entry) {
return delegate.setMetric(entry)
}

@Override
boolean isError() {
return delegate.isError()
Expand Down
14 changes: 13 additions & 1 deletion dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private boolean isExceptionReplayEnabled() {
public final DDSpan setTag(final String tag, final String value) {
if (value == null || value.isEmpty()) {
// Remove the tag
context.setTag(tag, null);
context.removeTag(tag);
} else {
context.setTag(tag, value);
}
Expand All @@ -405,6 +405,12 @@ public final DDSpan setTag(final String tag, final boolean value) {
return this;
}

@Override
Copy link
Contributor Author

@dougqh dougqh Jan 29, 2026

Choose a reason for hiding this comment

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

I'm going to add some tests around the new methods, but feel free to review the design/intent

public final DDSpan setTag(TagMap.EntryReader entry) {
context.setTag(entry);
return this;
}

@Override
public void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba) {
this.requestBlockingAction = rba;
Expand Down Expand Up @@ -474,6 +480,12 @@ public DDSpan setMetric(final CharSequence metric, final double value) {
return this;
}

@Override
public DDSpan setMetric(TagMap.EntryReader entry) {
context.setMetric(entry);
return this;
}

@Override
public DDSpan setFlag(CharSequence name, boolean value) {
context.setMetric(name, value ? 1 : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ public void setMetric(final CharSequence key, final Number value) {
}
}

public void setMetric(final TagMap.EntryReader entry) {
synchronized (unsafeTags) {
unsafeTags.set(entry);
}
}

public void removeTag(String tag) {
synchronized (unsafeTags) {
unsafeTags.remove(tag);
}
}

/**
* Sets a tag to the span. Tags are not propagated to the children.
*
Expand Down Expand Up @@ -790,6 +802,20 @@ public void setTag(final String tag, final String value) {
}
}

public void setTag(TagMap.EntryReader entry) {
if (entry == null) return;

// prcheck to avoid boxing
boolean intercepted =
precheckIntercept(entry.tag())
&& tagInterceptor.interceptTag(this, entry.tag(), entry.objectValue());
if (!intercepted) {
synchronized (unsafeTags) {
unsafeTags.set(entry);
}
}
}

/*
* Uses to determine if there's an opportunity to avoid primitve boxing.
* If the underlying map doesn't support efficient primitives, then boxing is used.
Expand Down
27 changes: 27 additions & 0 deletions dd-trace-core/src/test/java/datadog/trace/core/SpanTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package datadog.trace.core;

import static org.junit.jupiter.api.Assertions.assertEquals;

import datadog.trace.api.TagMap;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import org.junit.jupiter.api.Test;

public class SpanTest {
static final CoreTracer TRACER = CoreTracer.builder().build();

@Test
public void setTag_Entry() {
AgentSpan span = TRACER.startSpan("foo", "foo");
span.setTag(TagMap.Entry.create("message", "hello"));

assertEquals("hello", span.getTag("message"));
}

@Test
public void setMetric_Entry() {
AgentSpan span = TRACER.startSpan("foo", "foo");
span.setMetric(TagMap.Entry.create("metric", 20L));

assertEquals(Long.valueOf(20L), span.getTag("metric"));
}
}
31 changes: 31 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/TagMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,37 @@ final class Entry extends EntryChange implements Map.Entry<String, Object>, Entr
*/
static final byte ANY = 0;

public static final Entry create(String tag, Object value) {
// NOTE: From the static typing, it is possible that value is a primitive box, so need to call
// Any variant
return TagMap.Entry.newAnyEntry(tag, value);
}

public static final Entry create(String tag, CharSequence value) {
// NOTE: From the static typing, we know that value is not a primitive box
return TagMap.Entry.newObjectEntry(tag, value);
}

public static final Entry create(String tag, boolean value) {
return TagMap.Entry.newBooleanEntry(tag, value);
}

public static final Entry create(String tag, int value) {
return TagMap.Entry.newIntEntry(tag, value);
}

public static final Entry create(String tag, long value) {
return TagMap.Entry.newLongEntry(tag, value);
}

public static final Entry create(String tag, float value) {
return TagMap.Entry.newFloatEntry(tag, value);
}

public static final Entry create(String tag, double value) {
return TagMap.Entry.newDoubleEntry(tag, value);
}

static Entry newAnyEntry(Map.Entry<? extends String, ? extends Object> entry) {
return newAnyEntry(entry.getKey(), entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ default boolean isValid() {

AgentSpan setTag(String key, Object value);

AgentSpan setTag(TagMap.EntryReader entry);

AgentSpan setAllTags(Map<String, ?> map);

@Override
Expand All @@ -91,6 +93,8 @@ default boolean isValid() {
@Override
AgentSpan setMetric(CharSequence key, double value);

AgentSpan setMetric(TagMap.EntryReader metricEntry);

@Override
AgentSpan setSpanType(final CharSequence type);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.trace.bootstrap.instrumentation.api;

import datadog.trace.api.TagMap;
import datadog.trace.api.gateway.Flow.Action.RequestBlockingAction;
import datadog.trace.api.interceptor.MutableSpan;
import java.util.Map;
Expand Down Expand Up @@ -41,6 +42,11 @@ public AgentSpan setTag(String key, String value) {
return this;
}

@Override
public AgentSpan setTag(TagMap.EntryReader entry) {
return this;
}

@Override
public AgentSpan setTag(String key, CharSequence value) {
return this;
Expand Down Expand Up @@ -76,6 +82,11 @@ public AgentSpan setMetric(CharSequence key, double value) {
return this;
}

@Override
public AgentSpan setMetric(TagMap.EntryReader entry) {
return this;
}

@Override
public AgentSpan setSpanType(CharSequence type) {
return this;
Expand Down
Loading