Skip to content

Commit

Permalink
Merge pull request #4296 from DataDog/ygree/accept-1-as-true-tag-value
Browse files Browse the repository at this point in the history
Treat `1` value as `true` for boolean tag values
  • Loading branch information
ygree authored Nov 23, 2022
2 parents 53aeb4a + 9b676a2 commit 52f8372
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private static boolean interceptMeasured(DDSpanContext span, Object value) {

private static boolean asBoolean(Object value) {
return Boolean.TRUE.equals(value)
|| "1".equals(value)
|| (!Boolean.FALSE.equals(value) && Boolean.parseBoolean(String.valueOf(value)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,36 @@ class TagInterceptorTest extends DDCoreSpecification {
cleanup:
tracer.close()
}

def "treat `1` value as `true` for boolean tag values"() {
setup:
def tracer = tracerBuilder()
.serviceName("some-service")
.writer(new LoggingWriter())
.sampler(new AllSampler())
.build()

when:
AgentSpan span = tracer.buildSpan("test").start()

then:
span.getSamplingPriority() == null

when:
span.setTag(tag, value)

then:
span.getSamplingPriority() == samplingPriority

where:
tag | value | samplingPriority
DDTags.MANUAL_DROP | true | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | "1" | PrioritySampling.USER_DROP
DDTags.MANUAL_DROP | false | null
DDTags.MANUAL_DROP | "0" | null
DDTags.MANUAL_KEEP | true | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | "1" | PrioritySampling.USER_KEEP
DDTags.MANUAL_KEEP | false | null
DDTags.MANUAL_KEEP | "0" | null
}
}

0 comments on commit 52f8372

Please sign in to comment.