本文整理了Java中brave.Tracer.joinSpan()
方法的一些代码示例,展示了Tracer.joinSpan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.joinSpan()
方法的具体详情如下:
包路径:brave.Tracer
类名称:Tracer
方法名:joinSpan
[英]Joining is re-using the same trace and span ids extracted from an incoming RPC request. This should not be used for messaging operations, as #nextSpan(TraceContextOrSamplingFlags)is a better choice.
When this incoming context is sampled, we assume this is a shared span, one where the caller and the current tracer report to the same span IDs. If no sampling decision occurred yet, we have exclusive access to this span ID.
Here's an example of conditionally joining a span, depending on if a trace context was extracted from an incoming request.
extracted = extractor.extract(request);
Note: When Propagation.Factory#supportsJoin() is false, this will always fork a new child via #newChild(TraceContext).
[中]加入是重新使用从传入RPC请求中提取的相同跟踪和跨度ID。这不应用于消息传递操作,因为#nextSpan(TraceContextOrSamplingFlags)是更好的选择。
当对这个传入的上下文进行采样时,我们假设这是一个共享范围,调用方和当前跟踪器向同一个范围ID报告。如果尚未做出采样决定,我们可以独占访问此span ID。
下面是一个有条件地加入范围的示例,具体取决于是否从传入请求中提取了跟踪上下文。
extracted = extractor.extract(request);
*注:*传播时。Factory#supportsJoin()为false,这将始终通过#newChild(TraceContext)生成一个新的子对象。
代码示例来源:origin: openzipkin/brave
/** Creates a potentially noop span representing this request */
Span nextSpan(TraceContextOrSamplingFlags extracted, Req request) {
Boolean sampled = extracted.sampled();
// only recreate the context if the http sampler made a decision
if (sampled == null && (sampled = sampler.trySample(adapter, request)) != null) {
extracted = extracted.sampled(sampled.booleanValue());
}
return extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
}
代码示例来源:origin: openzipkin/brave
/** Creates a potentially noop span representing this request */
// copy/pasted from HttpServerHandler.nextSpan
Span nextSpan(TraceContextOrSamplingFlags extracted, HttpRequest request) {
Boolean sampled = extracted.sampled();
// only recreate the context if the http sampler made a decision
if (sampled == null && (sampled = sampler.trySample(adapter, request)) != null) {
extracted = extracted.sampled(sampled.booleanValue());
}
return extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
}
代码示例来源:origin: openzipkin/brave
void joinWithSpanInScope(Tracer tracer, TraceContext context) {
Span span = tracer.joinSpan(context).name("encode").start();
try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) {
span.tag("foo", "bar");
span.tag("baz", "qux");
} finally {
span.finish();
}
}
代码示例来源:origin: openzipkin/brave
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call,
final Metadata headers, final ServerCallHandler<ReqT, RespT> next) {
TraceContextOrSamplingFlags extracted = extractor.extract(headers);
Span span = extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
// If grpc propagation is enabled, make sure we refresh the server method
if (grpcPropagationFormatEnabled) {
Tags tags = span.context().findExtra(Tags.class);
if (tags != null) tags.put(RPC_METHOD, call.getMethodDescriptor().getFullMethodName());
}
span.kind(Span.Kind.SERVER);
parser.onStart(call, headers, span.customizer());
// startCall invokes user interceptors, so we place the span in scope here
ServerCall.Listener<ReqT> result;
SpanInScope scope = tracer.withSpanInScope(span);
try { // retrolambda can't resolve this try/finally
result = next.startCall(new TracingServerCall<>(span, call, parser), headers);
} catch (RuntimeException | Error e) {
span.error(e);
span.finish();
throw e;
} finally {
scope.close();
}
// This ensures the server implementation can see the span in scope
return new ScopingServerCallListener<>(tracer, span, result, parser);
}
代码示例来源:origin: line/armeria
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
final TraceContextOrSamplingFlags contextOrFlags = extractor.extract(req.headers());
final Span span = contextOrFlags.context() != null ? tracer.joinSpan(contextOrFlags.context())
: tracer.nextSpan(contextOrFlags);
// For no-op spans, nothing special to do.
if (span.isNoop()) {
return delegate().serve(ctx, req);
}
final String method = ctx.method().name();
span.kind(Kind.SERVER).name(method);
ctx.log().addListener(log -> SpanContextUtil.startSpan(span, log),
RequestLogAvailability.REQUEST_START);
// Ensure the trace context propagates to children
ctx.onChild(RequestContextCurrentTraceContext::copy);
ctx.log().addListener(log -> {
SpanTags.logWireReceive(span, log.requestFirstBytesTransferredTimeNanos(), log);
SpanTags.logWireSend(span, log.responseFirstBytesTransferredTimeNanos(), log);
SpanContextUtil.closeSpan(span, log);
}, RequestLogAvailability.COMPLETE);
try (SpanInScope ignored = tracer.withSpanInScope(span)) {
return delegate().serve(ctx, req);
}
}
}
代码示例来源:origin: openzipkin/brave
TraceContextOrSamplingFlags extracted = extractor.extract(invocation.getAttachments());
span = extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
代码示例来源:origin: io.zipkin.brave/brave-core
@Override Span joinSpan(SpanId spanId) {
TraceContext context = toTraceContext(spanId);
return Brave.toSpan(toSpanId(tracer.joinSpan(context).context()));
}
}
代码示例来源:origin: openzipkin-contrib/brave-opentracing
span = server ? braveTracer.joinSpan(context) : braveTracer.newChild(context);
} else {
span = braveTracer.nextSpan(((BraveSpanContext.Incomplete) reference).extractionResult());
代码示例来源:origin: jaegertracing/spark-dependencies
@Override
public void createChildSpan(TracingWrapper<ZipkinWrapper> parent) {
operationName = UUID.randomUUID().toString().replace("-","");
if (parent == null) {
// root node we start a new trace
span = tracing.tracer().newTrace().name(operationName + "-root")
.start();
} else {
brave.Span parentClient = parent.get().tracing.tracer().newChild(parent.get().span.context())
.kind(Kind.CLIENT)
.name(operationName + "-client")
.start();
// TODO if I finish this later the span is cached
// and joined with server span and reported as a single span.
// to properly solve this we have to look into the tags.
// However there is another problem jaeger adds only one span.kind
// (even if span contains cs,cr,sr,ss)
// And it filters out core annotations, so there is no way how to find out
// that there is a dependency link in this span.
// https://github.com/jaegertracing/jaeger/issues/451
parentClient.finish();
span = tracing.tracer().joinSpan(parentClient.context())
.name(operationName + "-server")
.kind(Kind.SERVER)
.start();
}
}
代码示例来源:origin: apache/cxf
protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder, final int responseStatus) {
if (holder == null) {
return;
}
final TraceScope scope = holder.getScope();
if (scope != null) {
try {
// If the client invocation was asynchronous , the trace span has been created
// in another thread and should be re-attached to the current one.
if (holder.isDetached()) {
brave.tracing().tracer().joinSpan(scope.getSpan().context());
}
final Response response = HttpAdapterFactory.response(responseStatus);
final HttpClientAdapter<?, Response> adapter = HttpClientAdapterFactory.create(response);
final HttpClientHandler<?, Response> handler = HttpClientHandler.create(brave, adapter);
handler.handleReceive(response, null, scope.getSpan());
} finally {
scope.close();
}
}
}
}
代码示例来源:origin: org.apache.cxf/cxf-integration-tracing-brave
protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder, final int responseStatus) {
if (holder == null) {
return;
}
final TraceScope scope = holder.getScope();
if (scope != null) {
try {
// If the client invocation was asynchronous , the trace span has been created
// in another thread and should be re-attached to the current one.
if (holder.isDetached()) {
brave.tracing().tracer().joinSpan(scope.getSpan().context());
}
final Response response = HttpAdapterFactory.response(responseStatus);
final HttpClientAdapter<?, Response> adapter = HttpClientAdapterFactory.create(response);
final HttpClientHandler<?, Response> handler = HttpClientHandler.create(brave, adapter);
handler.handleReceive(response, null, scope.getSpan());
} finally {
scope.close();
}
}
}
}
代码示例来源:origin: ZhuBaker/Tracing
} else {
TraceContextOrSamplingFlags extracted = extractor.extract(invocation.getAttachments());
span = extracted.context() != null ? tracer.joinSpan(extracted.context()) : tracer.nextSpan(extracted);
代码示例来源:origin: org.apache.cxf/cxf-integration-tracing-brave
span = brave.tracing().tracer().joinSpan(scope.getSpan().context());
代码示例来源:origin: apache/cxf
span = brave.tracing().tracer().joinSpan(scope.getSpan().context());
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-grpc
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call,
final Metadata headers, final ServerCallHandler<ReqT, RespT> next) {
TraceContextOrSamplingFlags extracted = extractor.extract(headers);
Span span = extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
// If grpc propagation is enabled, make sure we refresh the server method
if (grpcPropagationFormatEnabled) {
Tags tags = span.context().findExtra(Tags.class);
if (tags != null) tags.put(RPC_METHOD, call.getMethodDescriptor().getFullMethodName());
}
span.kind(Span.Kind.SERVER);
parser.onStart(call, headers, span.customizer());
// startCall invokes user interceptors, so we place the span in scope here
ServerCall.Listener<ReqT> result;
SpanInScope scope = tracer.withSpanInScope(span);
try { // retrolambda can't resolve this try/finally
result = next.startCall(new TracingServerCall<>(span, call, parser), headers);
} catch (RuntimeException | Error e) {
span.error(e);
span.finish();
throw e;
} finally {
scope.close();
}
// This ensures the server implementation can see the span in scope
return new ScopingServerCallListener<>(tracer, span, result, parser);
}
内容来源于网络,如有侵权,请联系作者删除!