Skip to content

Commit 071c16a

Browse files
authored
Merge pull request #768 from DataDog/tyler/metrics-double
Agent doesn’t like getting floats.
2 parents d45d672 + 4722621 commit 071c16a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

dd-java-agent/src/test/groovy/datadog/trace/agent/CustomLogManagerTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package datadog.trace.agent
22

33
import datadog.trace.agent.test.IntegrationTestUtils
44
import jvmbootstraptest.LogManagerSetter
5+
import spock.lang.Retry
56
import spock.lang.Shared
67
import spock.lang.Specification
8+
import spock.lang.Timeout
79

810
import java.lang.management.ManagementFactory
911
import java.lang.management.RuntimeMXBean
1012

13+
@Retry
14+
@Timeout(30)
1115
class CustomLogManagerTest extends Specification {
1216
// Run all tests using forked jvm because groovy has already set the global log manager
1317

dd-trace-ot/src/main/java/datadog/opentracing/DDSpanContext.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ public void setMetric(final String key, final Number value) {
295295
if (metrics.get() == null) {
296296
metrics.compareAndSet(null, new ConcurrentHashMap<String, Number>());
297297
}
298-
metrics.get().put(key, value);
298+
if (value instanceof Float) {
299+
metrics.get().put(key, value.doubleValue());
300+
} else {
301+
metrics.get().put(key, value);
302+
}
299303
}
300304
/**
301305
* Add a tag to the span. Tags are not propagated to the children

dd-trace-ot/src/test/groovy/datadog/trace/DDSpanContextTest.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,32 @@ class DDSpanContextTest extends Specification {
7070
"tag-with-bool" | false
7171
"tag_with_float" | 0.321
7272
}
73+
74+
def "metrics use the expected types"() {
75+
// floats should be converted to doubles.
76+
setup:
77+
def context = SpanFactory.newSpanOf(0).context
78+
context.setMetric("test", value)
79+
def metrics = context.getMetrics()
80+
81+
expect:
82+
type.isInstance(metrics["test"])
83+
84+
where:
85+
type | value
86+
Integer | 0
87+
Integer | Integer.MAX_VALUE
88+
Integer | Integer.MIN_VALUE
89+
Short | Short.MAX_VALUE
90+
Short | Short.MIN_VALUE
91+
Double | Float.MAX_VALUE
92+
Double | Float.MIN_VALUE
93+
Double | Double.MAX_VALUE
94+
Double | Double.MIN_VALUE
95+
Double | 1f
96+
Double | 1d
97+
Double | 0.5f
98+
Double | 0.5d
99+
Integer | 0x55
100+
}
73101
}

0 commit comments

Comments
 (0)