/** * Conditionally joins a span, or starts a new trace, depending on if a trace context was * extracted from the request. Tags are added before the span is started. * * <p>This is typically called before the request is processed by the actual library. */ public Span handleReceive(TraceContext.Extractor<Req> extractor, Req request) { return handleReceive(extractor, request, request); }
public Filter before() { return (request, response) -> { Span span = handler.handleReceive(extractor, request, request.raw()); request.attribute(Tracer.SpanInScope.class.getName(), tracer.withSpanInScope(span)); }; }
@Override public RequestEventListener onRequest(RequestEvent requestEvent) { if (requestEvent.getType() == RequestEvent.Type.START) { Span span = serverHandler.handleReceive(extractor, requestEvent.getContainerRequest()); return new TracingRequestEventListener(span, tracer.withSpanInScope(span)); } return null; }
private Span findOrCreateSpan(Context c) { Span span; if (c.hasKey(Span.class)) { Span parent = c.get(Span.class); span = this.tracer .nextSpan(TraceContextOrSamplingFlags.create(parent.context())) .start(); if (log.isDebugEnabled()) { log.debug("Found span in reactor context" + span); } } else { if (this.attrSpan != null) { span = this.attrSpan; if (log.isDebugEnabled()) { log.debug("Found span in attribute " + span); } } else { span = this.handler.handleReceive(this.extractor, this.exchange.getRequest().getHeaders(), this.exchange.getRequest()); if (log.isDebugEnabled()) { log.debug("Handled receive of span " + span); } } this.exchange.getAttributes().put(TRACE_REQUEST_ATTR, span); } return span; }
Span span = handler.handleReceive(extractor, httpRequest);
@Override public void handle(RoutingContext context) { TracingHandler tracingHandler = context.get(TracingHandler.class.getName()); if (tracingHandler != null) { // then we already have a span if (!context.failed()) { // re-routed, so re-attach the end handler context.addHeadersEndHandler(tracingHandler); } context.next(); return; } Span span = serverHandler.handleReceive(extractor, context.request()); TracingHandler handler = new TracingHandler(context, span); context.put(TracingHandler.class.getName(), handler); context.addHeadersEndHandler(handler); try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { context.next(); } }
@Override public Span createSpan(Invocation invocation) { return handler.handleReceive(extractor, invocation); }
@Override public Span createSpan(Invocation invocation) { return handler.handleReceive(extractor, invocation); }
@Override public Span createSpan(Invocation invocation) { return handler.handleReceive(extractor, invocation); }
public Filter before() { return (request, response) -> { Span span = handler.handleReceive(extractor, request, request.raw()); request.attribute(Tracer.SpanInScope.class.getName(), tracer.withSpanInScope(span)); }; }
private Span findOrCreateSpan(Context c) { Span span; if (c.hasKey(Span.class)) { Span parent = c.get(Span.class); span = this.tracer .nextSpan(TraceContextOrSamplingFlags.create(parent.context())) .start(); if (log.isDebugEnabled()) { log.debug("Found span in reactor context" + span); } } else { if (this.attrSpan != null) { span = this.attrSpan; if (log.isDebugEnabled()) { log.debug("Found span in attribute " + span); } } else { span = this.handler.handleReceive(this.extractor, this.exchange.getRequest().getHeaders(), this.exchange.getRequest()); if (log.isDebugEnabled()) { log.debug("Handled receive of span " + span); } } this.exchange.getAttributes().put(TRACE_REQUEST_ATTR, span); } return span; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (!exchange.isComplete()) { Span span = serverHandler.handleReceive(extractor, exchange.getRequestHeaders(), exchange); exchange.addExchangeCompleteListener((exch, nextListener) -> { try { nextListener.proceed(); } finally { serverHandler.handleSend(exch, exch.getAttachment(ExceptionHandler.THROWABLE), span); } }); try (Scope scope = currentTraceContext.newScope(span.context())) { next.handleRequest(exchange); } catch (Exception | Error e) { // move the error to where the complete listener can see it exchange.putAttachment(ExceptionHandler.THROWABLE, e); throw e; } } else { next.handleRequest(exchange); } } }
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) { final Request request = HttpAdapterFactory.request(requestHeaders, uri, method); final HttpServerAdapter<Request, ?> adapter = HttpServerAdapterFactory.create(request); final HttpServerHandler<Request, ?> handler = HttpServerHandler.create(brave, adapter); Span span = handler.handleReceive( brave .tracing() .propagation() .extractor(adapter::requestHeader), request); // If the service resource is using asynchronous processing mode, the trace // scope will be closed in another thread and as such should be detached. SpanInScope scope = null; if (isAsyncResponse() && span != null) { // Do not modify the current context span propagateContinuationSpan(span); } else if (span != null) { scope = brave.tracing().tracer().withSpanInScope(span); } return new TraceScopeHolder<TraceScope>(new TraceScope(span, scope), scope == null /* detached */); }
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) { final Request request = HttpAdapterFactory.request(requestHeaders, uri, method); final HttpServerAdapter<Request, ?> adapter = HttpServerAdapterFactory.create(request); final HttpServerHandler<Request, ?> handler = HttpServerHandler.create(brave, adapter); Span span = handler.handleReceive( brave .tracing() .propagation() .extractor(adapter::requestHeader), request); // If the service resource is using asynchronous processing mode, the trace // scope will be closed in another thread and as such should be detached. SpanInScope scope = null; if (isAsyncResponse() && span != null) { // Do not modify the current context span propagateContinuationSpan(span); } else if (span != null) { scope = brave.tracing().tracer().withSpanInScope(span); } return new TraceScopeHolder<TraceScope>(new TraceScope(span, scope), scope == null /* detached */); }