Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 0dafe38

Browse files
authored
Restore support for setting null as a tag value (Resolves #823) (#824)
1 parent c92da42 commit 0dafe38

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

jaeger-core/src/main/java/io/jaegertracing/internal/JaegerSpan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected JaegerSpan(
6868
this.startTimeMicroseconds = startTimeMicroseconds;
6969
this.startTimeNanoTicks = startTimeNanoTicks;
7070
this.computeDurationViaNanoTicks = computeDurationViaNanoTicks;
71-
this.tags = new ConcurrentHashMap<String, Object>();
71+
this.tags = new ConcurrentHashMap<>();
7272
this.references = references != null ? new ArrayList<Reference>(references) : null;
7373

7474
// Handle SAMPLING_PRIORITY tag first, as this influences whether setTagAsObject actually
@@ -111,7 +111,7 @@ public List<Reference> getReferences() {
111111
}
112112

113113
public Map<String, Object> getTags() {
114-
return new HashMap<String, Object>(tags);
114+
return new HashMap<>(tags);
115115
}
116116

117117
@Override
@@ -225,7 +225,7 @@ private JaegerSpan setTagAsObject(String key, Object value) {
225225
}
226226

227227
if (context.isSampled()) {
228-
tags.put(key, value);
228+
tags.put(key, value == null ? "null" : value);
229229
}
230230

231231
return this;

jaeger-core/src/test/java/io/jaegertracing/internal/JaegerSpanTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public void testSetAndGetBaggageItem() {
124124
assertEquals(value, jaegerSpan.getBaggageItem(key));
125125
}
126126

127+
@Test
128+
public void testSetNullTag() {
129+
String key = "tag.key";
130+
131+
jaegerSpan.setTag(key, (String)null);
132+
assertEquals("null", jaegerSpan.getTags().get(key));
133+
}
134+
127135
@Test
128136
public void testSetBooleanTag() {
129137
Boolean expected = true;

0 commit comments

Comments
 (0)