Merge pull request #153 from DataDog/tyler/fix-tags
Null tags are intended for “deletion”
This commit is contained in:
commit
96c39d1c25
|
@ -181,6 +181,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
*/
|
||||
public synchronized void setTag(final String tag, final Object value) {
|
||||
if (value == null) {
|
||||
tags.remove(tag);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,22 +4,26 @@ import spock.lang.Specification
|
|||
|
||||
class DDSpanContextTest extends Specification {
|
||||
|
||||
def "null values for tags are ignored"() {
|
||||
def "null values for tags delete existing tags"() {
|
||||
setup:
|
||||
def context = SpanFactory.newSpanOf(0).context
|
||||
context.setTag("some.tag", "asdf")
|
||||
context.setTag(name, null)
|
||||
context.setErrorFlag(true)
|
||||
def thread = Thread.currentThread()
|
||||
|
||||
expect:
|
||||
context.getTags() == [(DDTags.THREAD_NAME): thread.name, (DDTags.THREAD_ID): thread.id]
|
||||
context.getTags() == tags
|
||||
context.serviceName == "fakeService"
|
||||
context.resourceName == "fakeResource"
|
||||
context.spanType == "fakeType"
|
||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource *errored* tags={thread.id=$thread.id, thread.name=$thread.name}"
|
||||
context.toString() == "Span [ t_id=1, s_id=1, p_id=0] trace=fakeService/fakeOperation/fakeResource *errored* tags={${extra}thread.id=${Thread.currentThread().id}, thread.name=${Thread.currentThread().name}}"
|
||||
|
||||
where:
|
||||
name << [DDTags.SERVICE_NAME, DDTags.RESOURCE_NAME, DDTags.SPAN_TYPE, "some.tag"]
|
||||
name | extra | tags
|
||||
DDTags.SERVICE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.RESOURCE_NAME | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
DDTags.SPAN_TYPE | "some.tag=asdf, " | ["some.tag": "asdf", (DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
"some.tag" | "" | [(DDTags.THREAD_NAME): Thread.currentThread().name, (DDTags.THREAD_ID): Thread.currentThread().id]
|
||||
}
|
||||
|
||||
def "special tags set certain values"() {
|
||||
|
|
Loading…
Reference in New Issue