Implement support for setting Event Sample Rate via tags
This only adds the API, no changes to the integrations.
This commit is contained in:
parent
20b134e356
commit
bbfcb26cd1
|
@ -13,4 +13,6 @@ public class DDTags {
|
|||
public static final String ERROR_MSG = "error.msg"; // string representing the error message
|
||||
public static final String ERROR_TYPE = "error.type"; // string representing the type of the error
|
||||
public static final String ERROR_STACK = "error.stack"; // human readable version of the stack
|
||||
|
||||
public static final String EVENT_SAMPLE_RATE = "_dd1.sr.eausr";
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class DDDecoratorsFactory {
|
|||
new DBStatementAsResourceName(),
|
||||
new DBTypeDecorator(),
|
||||
new ErrorFlag(),
|
||||
new EventSampleRateDecorator(),
|
||||
new OperationDecorator(),
|
||||
new PeerServiceDecorator(),
|
||||
new ResourceNameDecorator(),
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package datadog.opentracing.decorators;
|
||||
|
||||
import datadog.opentracing.DDSpanContext;
|
||||
import datadog.trace.api.DDTags;
|
||||
|
||||
public class EventSampleRateDecorator extends AbstractDecorator {
|
||||
public EventSampleRateDecorator() {
|
||||
super();
|
||||
setMatchingTag(DDTags.EVENT_SAMPLE_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
|
||||
if (value instanceof Number) {
|
||||
context.setMetric(DDTags.EVENT_SAMPLE_RATE, (Number) value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import io.opentracing.tag.Tags
|
|||
import spock.lang.Specification
|
||||
|
||||
import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
|
||||
import static datadog.trace.api.DDTags.EVENT_SAMPLE_RATE
|
||||
import static java.util.Collections.emptyMap
|
||||
|
||||
class SpanDecoratorTest extends Specification {
|
||||
|
@ -205,6 +206,30 @@ class SpanDecoratorTest extends Specification {
|
|||
type = "foo"
|
||||
}
|
||||
|
||||
def "span metrics starts empty but added with rate limiting value of #rate"() {
|
||||
expect:
|
||||
span.metrics == [:]
|
||||
|
||||
when:
|
||||
span.setTag(EVENT_SAMPLE_RATE, rate)
|
||||
|
||||
then:
|
||||
span.metrics == result
|
||||
|
||||
where:
|
||||
rate | result
|
||||
00 | [(EVENT_SAMPLE_RATE): 0]
|
||||
1 | [(EVENT_SAMPLE_RATE): 1]
|
||||
0f | [(EVENT_SAMPLE_RATE): 0]
|
||||
1f | [(EVENT_SAMPLE_RATE): 1]
|
||||
0.1 | [(EVENT_SAMPLE_RATE): 0.1]
|
||||
1.1 | [(EVENT_SAMPLE_RATE): 1.1]
|
||||
-1 | [(EVENT_SAMPLE_RATE): -1]
|
||||
10 | [(EVENT_SAMPLE_RATE): 10]
|
||||
"00" | [:]
|
||||
"str" | [:]
|
||||
}
|
||||
|
||||
def "DBStatementAsResource should not interact on Mongo queries"() {
|
||||
when:
|
||||
span.setResourceName("not-change-me")
|
||||
|
|
|
@ -45,7 +45,7 @@ class DDTracerTest extends Specification {
|
|||
tracer.sampler instanceof RateByServiceSampler
|
||||
tracer.writer.toString() == "DDAgentWriter { api=DDApi { tracesEndpoint=http://localhost:8126/v0.3/traces } }"
|
||||
|
||||
tracer.spanContextDecorators.size() == 12
|
||||
tracer.spanContextDecorators.size() == 13
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue