protected TraceCommand(Tracer tracer, Setter setter) { super(setter); this.tracer = tracer; this.span = new AtomicReference<>(this.tracer.nextSpan()); }
private Span findOrCreateSpan(ClientRequest.Builder builder) { if (log.isDebugEnabled()) { log.debug("Instrumenting WebClient call"); } Span clientSpan = this.handler.handleSend(this.injector, builder, this.request, this.tracer.nextSpan()); if (log.isDebugEnabled()) { log.debug("Handled send of " + clientSpan); } return clientSpan; }
@RequestMapping("/traced") public String traced() throws InterruptedException { log.info("traced"); Span span = this.tracer.nextSpan().name("http:customTraceEndpoint"); int millis = this.random.nextInt(1000); log.info(String.format("Sleeping for [%d] millis", millis)); Thread.sleep(millis); this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis)); String s = this.restTemplate .getForObject("http://localhost:" + this.port + "/call", String.class); span.finish(); return "traced/" + s; }
@Override public Span nextSpan() { return postProcessSpan(tracing.tracer().nextSpan()); }
@RequestMapping("/traced") public String traced() throws InterruptedException { Span span = this.tracer.nextSpan().name("http:customTraceEndpoint").start(); int millis = this.random.nextInt(1000); log.info(String.format("Sleeping for [%d] millis", millis)); Thread.sleep(millis); this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis)); String s = this.restTemplate .getForObject("http://localhost:" + this.port + "/call", String.class); span.finish(); return "traced/" + s; }
/** * 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(); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { tracer.nextSpan().name("child").start().finish(); resp.setStatus(200); } }
private Span startOrContinueRenamedSpan(String spanName) { Span currentSpan = this.tracer.currentSpan(); if (currentSpan != null) { return currentSpan.name(spanName); } return this.tracer.nextSpan().name(spanName); }
@Override public Span nextSpan(TraceContext traceContext) { if (!(traceContext instanceof BraveTraceContext)) { return nextSpan(); } BraveTraceContext braveTraceContext = BraveTraceContext.class.cast(traceContext); if (braveTraceContext.traceContext == null) { return nextSpan(); } return postProcessSpan(tracing.tracer() .nextSpan(TraceContextOrSamplingFlags.create(braveTraceContext.traceContext))); }
/** 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); }
/** 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); }
/** * Returns the {@link Tracer#nextSpan(TraceContextOrSamplingFlags)} or null if {@link * #CURRENT_TRACER} and tracing isn't available. */ @Nullable public Span next(TraceContextOrSamplingFlags extracted) { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(extracted); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }
Span nextSpan(ProcessorContext context) { TraceContextOrSamplingFlags extracted = extractor.extract(context.headers()); Span result = tracing.tracer().nextSpan(extracted); if (!result.isNoop()) { addTags(context, result); } return result; }
/** * Returns the {@link Tracer#nextSpan()} or null if {@link #CURRENT_TRACER} and tracing isn't * available. */ @Nullable public Span next() { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }
void nextWithSpanInScope(Tracer tracer, TraceContextOrSamplingFlags extracted) { Span span = tracer.nextSpan(extracted).name("encode").start(); try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) { span.tag("foo", "bar"); span.tag("baz", "qux"); } finally { span.finish(); } }
/** * Use this to create a span for processing the given record. Note: the result has no name and is * not started. * * <p>This creates a child from identifiers extracted from the record headers, or a new span if * one couldn't be extracted. */ public Span nextSpan(ConsumerRecord<?, ?> record) { TraceContextOrSamplingFlags extracted = extractAndClearHeaders(record.headers()); Span result = tracing.tracer().nextSpan(extracted); if (extracted.context() == null && !result.isNoop()) { addTags(record, result); } return result; }
@Override public void subscribe(CoreSubscriber<? super Object> actual) { Span span; Tracer tracer = this.processor.tracer(); if (this.span == null) { span = tracer.nextSpan(); this.processor.newSpanParser().parse(this.invocation, this.newSpan, span); span.start(); } else { span = this.span; } try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { this.source.subscribe(new SpanSubscriber(actual, this.processor, this.invocation, this.span == null, span, this.log, this.hasLog)); } }
@Override public void subscribe(CoreSubscriber<? super Object> actual) { Span span; Tracer tracer = this.processor.tracer(); if (this.span == null) { span = tracer.nextSpan(); this.processor.newSpanParser().parse(this.invocation, this.newSpan, span); span.start(); } else { span = this.span; } try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { this.source.subscribe(new SpanSubscriber(actual, this.processor, this.invocation, this.span == null, span, this.log, this.hasLog)); } }
void handleReceive(Message message) { if (message == null || tracing.isNoop()) return; // remove prior propagation headers from the message TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message); Span span = tracer.nextSpan(extracted); if (!span.isNoop()) { span.name("receive").kind(Span.Kind.CONSUMER); Destination destination = destination(message); if (destination != null) jmsTracing.tagQueueOrTopic(destination, span); if (remoteServiceName != null) span.remoteServiceName(remoteServiceName); // incur timestamp overhead only once long timestamp = tracing.clock(span.context()).currentTimeMicroseconds(); span.start(timestamp).finish(timestamp); } jmsTracing.setNextParent(message, span.context()); }
Span startMessageListenerSpan(Message message) { if (!addConsumerSpan) return jmsTracing.nextSpan(message).name("on-message").start(); TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message); // JMS has no visibility of the incoming message, which incidentally could be local! Span consumerSpan = tracer.nextSpan(extracted).kind(CONSUMER).name("receive"); Span listenerSpan = tracer.newChild(consumerSpan.context()); if (!consumerSpan.isNoop()) { long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds(); consumerSpan.start(timestamp); if (remoteServiceName != null) consumerSpan.remoteServiceName(remoteServiceName); jmsTracing.tagQueueOrTopic(message, consumerSpan); long consumerFinish = timestamp + 1L; // save a clock reading consumerSpan.finish(consumerFinish); // not using scoped span as we want to start late listenerSpan.name("on-message").start(consumerFinish); } return listenerSpan; } }