Refine search
@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); }
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; }
/** * {@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); }
/** * 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()); }
@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(); } }
@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();
@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")); }
@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(); } }
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
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); }
SparkTracing(HttpTracing httpTracing) { // intentionally hidden constructor tracer = httpTracing.tracing().tracer(); handler = HttpServerHandler.create(httpTracing, ADAPTER); extractor = httpTracing.tracing().propagation().extractor(Request::headers); }
TracingFilter(HttpTracing httpTracing) { tracer = httpTracing.tracing().tracer(); currentTraceContext = httpTracing.tracing().currentTraceContext(); handler = HttpServerHandler.create(httpTracing, ADAPTER); extractor = httpTracing.tracing().propagation().extractor(GETTER); }
@Override public Set<Object> getSingletons() { return new LinkedHashSet<>(asList(new Resource(), TracingApplicationEventListener.create( HttpTracing.create(Tracing.newBuilder().spanReporter(Reporter.NOOP).build()) ))); } }
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(); } } } }
/** * 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); }