本文整理了Java中brave.Tracing
类的一些代码示例,展示了Tracing
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracing
类的具体详情如下:
包路径:brave.Tracing
类名称:Tracing
[英]This provides utilities needed for trace instrumentation. For example, a Tracer.
Instances built via #newBuilder() are registered automatically such that statically configured instrumentation like JDBC drivers can use #current().
This type can be extended so that the object graph can be built differently or overridden, for example via spring or when mocking.
[中]这提供了跟踪检测所需的实用程序。例如,一个追踪器。
通过#newBuilder()构建的实例会自动注册,这样静态配置的工具(如JDBC驱动程序)就可以使用#current()。
可以扩展此类型,以便以不同的方式构建或覆盖对象图,例如通过spring或模拟时。
代码示例来源:origin: openzipkin/brave
@Inject TracingClientFilter(HttpTracing httpTracing) {
if (httpTracing == null) throw new NullPointerException("HttpTracing == null");
tracer = httpTracing.tracing().tracer();
handler = HttpClientHandler.create(httpTracing, new HttpAdapter());
injector = httpTracing.tracing().propagation().injector(SETTER);
}
代码示例来源:origin: openzipkin/brave
TracingProducer(P delegate, JmsTracing jmsTracing) {
this.delegate = delegate;
this.jmsTracing = jmsTracing;
this.tracer = jmsTracing.tracing.tracer();
this.current = jmsTracing.tracing.currentTraceContext();
this.remoteServiceName = jmsTracing.remoteServiceName;
}
代码示例来源:origin: openzipkin/brave
/**
* This closes the current instance of tracing, to prevent it from being accidentally visible to
* other test classes which call {@link Tracing#current()}.
*/
@After public void close() throws Exception {
Tracing current = Tracing.current();
if (current != null) current.close();
}
代码示例来源:origin: openzipkin/brave
/**
* {@link ExtensionLoader} supplies the tracing implementation which must be named "tracing". For
* example, if using the {@link SpringExtensionFactory}, only a bean named "tracing" will be
* injected.
*/
public void setTracing(Tracing tracing) {
tracer = tracing.tracer();
extractor = tracing.propagation().extractor(GETTER);
injector = tracing.propagation().injector(SETTER);
}
代码示例来源:origin: spring-cloud/spring-cloud-sleuth
/**
* This starts a consumer span as a child of the incoming message or the current trace
* context, placing it in scope until the receive completes.
*/
@Override
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
if (emptyMessage(message)) {
return message;
}
MessageHeaderAccessor headers = mutableHeaderAccessor(message);
TraceContextOrSamplingFlags extracted = this.extractor.extract(headers);
Span span = this.threadLocalSpan.next(extracted);
MessageHeaderPropagation.removeAnyTraceHeaders(headers,
this.tracing.propagation().keys());
this.injector.inject(span.context(), headers);
if (!span.isNoop()) {
span.kind(Span.Kind.CONSUMER).name("receive").start();
span.remoteServiceName(REMOTE_SERVICE_NAME);
addTags(message, span, channel);
}
if (log.isDebugEnabled()) {
log.debug("Created a new span in post receive " + span);
}
headers.setImmutable();
return new GenericMessage<>(message.getPayload(), headers.getMessageHeaders());
}
代码示例来源:origin: apache/cxf
@WebMethod
public Collection< Book > getBooks() {
final Span span = brave.tracer().nextSpan().name("Get Books").start();
try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
return Arrays.asList(
new Book("Apache CXF in Action", UUID.randomUUID().toString()),
new Book("Mastering Apache CXF", UUID.randomUUID().toString())
);
} finally {
span.finish();
}
}
代码示例来源:origin: apache/cxf
@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
final Tracing brave = Tracing.newBuilder()
.localServiceName("book-store")
.spanReporter(new TestSpanReporter())
.build();
final Span span = brave.tracer().nextSpan().name("test span").start();
try {
try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
assertThat(service.getBooks().size(), equalTo(2));
assertThat(brave.tracer().currentSpan(), not(nullValue()));
span.finish();
代码示例来源:origin: apache/cxf
@Test
public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
final Span span = brave.tracer().nextSpan().name("test span").start();
try {
try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
final Future<Response> f = client.async().get();
final Response r = f.get(1, TimeUnit.SECONDS);
assertEquals(Status.OK.getStatusCode(), r.getStatus());
assertThat(brave.tracer().currentSpan().context().spanId(), equalTo(span.context().spanId()));
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
assertThatTraceHeadersArePresent(r, true);
}
} finally {
span.finish();
}
// Await till flush happens, usually a second is enough
await().atMost(Duration.ONE_SECOND).until(()-> TestSpanReporter.getAllSpans().size() == 4);
assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}
代码示例来源: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: openzipkin/brave
if (records.isEmpty() || tracing.isNoop()) return records;
long timestamp = 0L;
Map<String, Span> consumerSpansForTopic = new LinkedHashMap<>();
Span span = consumerSpansForTopic.get(topic);
if (span == null) {
span = tracing.tracer().nextSpan(extracted);
if (!span.isNoop()) {
setConsumerSpan(topic, span);
timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
span.start(timestamp);
injector.inject(span.context(), record.headers());
} else { // we extracted request-scoped data, so cannot share a consumer span.
Span span = tracing.tracer().nextSpan(extracted);
if (!span.isNoop()) {
setConsumerSpan(topic, span);
timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
span.start(timestamp).finish(timestamp); // span won't be shared by other records
代码示例来源:origin: spring-cloud/spring-cloud-sleuth
SpanSubscriber(Subscriber<? super T> subscriber, Context ctx, Tracing tracing,
String name) {
this.subscriber = subscriber;
this.tracer = tracing.tracer();
Span root = ctx.getOrDefault(Span.class, this.tracer.currentSpan());
if (log.isTraceEnabled()) {
log.trace("Span from context [{}]", root);
}
this.rootSpan = root;
if (log.isTraceEnabled()) {
log.trace("Stored context root span [{}]", this.rootSpan);
}
this.span = root != null ? this.tracer
.nextSpan(TraceContextOrSamplingFlags.create(root.context())).name(name)
: this.tracer.nextSpan().name(name);
if (log.isTraceEnabled()) {
log.trace("Created span [{}], with name [{}]", this.span, name);
}
this.context = ctx.put(Span.class, this.span);
}
代码示例来源:origin: openzipkin/brave
Span nextSpan(ProcessorContext context) {
TraceContextOrSamplingFlags extracted = extractor.extract(context.headers());
Span result = tracing.tracer().nextSpan(extracted);
if (!result.isNoop()) {
addTags(context, result);
}
return result;
}
代码示例来源:origin: openzipkin/brave
SparkTracing(HttpTracing httpTracing) { // intentionally hidden constructor
tracer = httpTracing.tracing().tracer();
handler = HttpServerHandler.create(httpTracing, ADAPTER);
extractor = httpTracing.tracing().propagation().extractor(Request::headers);
}
代码示例来源:origin: openzipkin/brave
TracingFilter(HttpTracing httpTracing) {
tracer = httpTracing.tracing().tracer();
currentTraceContext = httpTracing.tracing().currentTraceContext();
handler = HttpServerHandler.create(httpTracing, ADAPTER);
extractor = httpTracing.tracing().propagation().extractor(GETTER);
}
代码示例来源:origin: openzipkin/brave
@Override public Set<Object> getSingletons() {
return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create(
HttpTracing.create(Tracing.newBuilder().spanReporter(Reporter.NOOP).build())
)));
}
}
代码示例来源:origin: apache/cxf
.propagation()
.keys()
.forEach(key -> transferRequestHeader(requestHeaders, responseHeaders, key));
span = brave.tracing().tracer().joinSpan(scope.getSpan().context());
span.abandon();
代码示例来源: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: lettuce-io/lettuce-core
@Override
public Span nextSpan() {
return postProcessSpan(tracing.tracer().nextSpan());
}
代码示例来源:origin: line/armeria
/**
* Creates a new instance.
*/
public HttpTracingService(Service<HttpRequest, HttpResponse> delegate, Tracing tracing) {
super(delegate);
tracer = tracing.tracer();
extractor = tracing.propagationFactory().create(AsciiStringKeyFactory.INSTANCE)
.extractor(HttpHeaders::get);
}
代码示例来源:origin: openzipkin/brave
TracingServerInterceptor(GrpcTracing grpcTracing) {
tracer = grpcTracing.tracing.tracer();
extractor = grpcTracing.propagation.extractor(GETTER);
parser = grpcTracing.serverParser;
grpcPropagationFormatEnabled = grpcTracing.grpcPropagationFormatEnabled;
}
内容来源于网络,如有侵权,请联系作者删除!