本文整理了Java中brave.Tracer.withSampler()
方法的一些代码示例,展示了Tracer.withSampler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.withSampler()
方法的具体详情如下:
包路径:brave.Tracer
类名称:Tracer
方法名:withSampler
[英]Use this to temporarily override the sampler used when starting new traces. This also serves advanced scenarios, such as DeclarativeSampler.
Simple example:
// Ensures new traces are always started
[中]使用此选项可临时覆盖开始新记录道时使用的采样器。这也适用于高级场景,例如DeclarativeSampler。
简单的例子:
// Ensures new traces are always started
代码示例来源:origin: openzipkin/brave
/**
* Creates a potentially noop span representing this request. This is used when you need to
* provision a span in a different scope than where the request is executed.
*
* @since 4.4
*/
public Span nextSpan(Req request) {
Sampler override = httpSampler.toSampler(adapter, request, sampler);
return tracer.withSampler(override).nextSpan();
}
代码示例来源:origin: openzipkin/brave
@Test public void propagatesExtra_unsampledTrace() throws Exception {
Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE);
server.enqueue(new MockResponse());
ScopedSpan parent = tracer.startScopedSpan("test");
try {
ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
get(client, "/foo");
} finally {
parent.finish();
}
assertThat(server.takeRequest().getHeader(EXTRA_KEY))
.isEqualTo("joey");
}
代码示例来源:origin: io.zipkin.brave/brave-core
/**
* Returns a span representing the sampled status of the current server span or null if there's no
* span attached to the current thread.
*/
@Nullable
public static brave.Span getServerSpan(Tracer tracer, ServerSpanThreadBinder threadBinder) {
if (tracer == null) throw new NullPointerException("tracer == null");
if (threadBinder == null) throw new NullPointerException("threadBinder == null");
ServerSpan result = threadBinder.getCurrentServerSpan();
if (result == null || result.equals(ServerSpan.EMPTY)) return null;
if (result.getSpan() != null) return toSpan(tracer, result.getSpan());
assert result.getSample() != null && !result.getSample() : "unexpected sample state: " + result;
return tracer.withSampler(Sampler.NEVER_SAMPLE).newTrace();
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests
@Test public void propagatesExtra_unsampledTrace() throws Exception {
Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE);
server.enqueue(new MockResponse());
ScopedSpan parent = tracer.startScopedSpan("test");
try {
ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
get(client, "/foo");
} finally {
parent.finish();
}
assertThat(server.takeRequest().getHeader(EXTRA_KEY))
.isEqualTo("joey");
}
代码示例来源:origin: openzipkin-contrib/brave-opentracing
Integer samplingPriority = Integer.valueOf(sampling);
if (samplingPriority == 0) {
scopedBraveTracer = braveTracer.withSampler(Sampler.NEVER_SAMPLE);
} else if (samplingPriority > 0) {
scopedBraveTracer = braveTracer.withSampler(Sampler.ALWAYS_SAMPLE);
内容来源于网络,如有侵权,请联系作者删除!