congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Tracer.getCurrentSpan
Code IndexAdd Tabnine to your IDE (free)

How to use
getCurrentSpan
method
in
com.nike.wingtips.Tracer

Best Java code snippets using com.nike.wingtips.Tracer.getCurrentSpan (Showing top 20 results out of 315)

origin: Nike-Inc/wingtips

private HttpEntity getHttpEntityWithUserIdHeader() {
  HttpHeaders headers = new HttpHeaders();
  String userId = Tracer.getInstance().getCurrentSpan().getUserId();
  if (userIdHeaderKeys == null || userIdHeaderKeys.isEmpty() || userId == null) {
    return new HttpEntity(headers);
  }
  headers.set(userIdHeaderKeys.get(0), userId);
  return new HttpEntity(headers);
}
origin: Nike-Inc/riposte

@Test
public void linkTracingAndMdcToCurrentThread_should_clear_mdc_if_state_is_available_but_state_mdc_info_is_null() {
  // given
  MDC.put("foo", "bar");
  Tracer.getInstance().startRequestWithRootSpan("blahtrace");
  assertThat(MDC.getCopyOfContextMap().isEmpty(), is(false));
  assertThat(Tracer.getInstance().getCurrentSpan(), notNullValue());
  // when
  handler.linkTracingAndMdcToCurrentThread(ctxMock);
  // then
  assertThat(MDC.getCopyOfContextMap().isEmpty(), is(true));
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy(), nullValue());
}
origin: Nike-Inc/wingtips

private HttpEntity getHttpEntityWithUserIdHeader() {
  HttpHeaders headers = new HttpHeaders();
  String userId = Tracer.getInstance().getCurrentSpan().getUserId();
  if (userIdHeaderKeys.isEmpty() || userId == null) {
    return new HttpEntity(headers);
  }
  headers.set(userIdHeaderKeys.get(0), userId);
  return new HttpEntity(headers);
}
origin: Nike-Inc/riposte

public static ChannelHandlerContextMocks mockChannelHandlerContextWithTraceInfo(String userId) {
  if (Tracer.getInstance().getCurrentSpan() == null) {
    Tracer.getInstance().startRequestWithRootSpan("mockChannelHandlerContext", userId);
  }
  ChannelHandlerContextMocks channelHandlerMocks = mockChannelHandlerContext();
  when(channelHandlerMocks.mockHttpProcessingState.getLoggerMdcContextMap()).thenReturn(MDC.getCopyOfContextMap());
  when(channelHandlerMocks.mockHttpProcessingState.getDistributedTraceStack()).thenReturn(Tracer.getInstance().getCurrentSpanStackCopy());
  return channelHandlerMocks;
}
origin: Nike-Inc/wingtips

@GetMapping(path = SPAN_INFO_CALL_PATH)
@SuppressWarnings("unused")
public EndpointSpanInfoDto getSpanInfoCall(HttpServletRequest request) {
  logger.info("Span info endpoint hit. Sleeping...");
  sleepThread(SLEEP_TIME_MILLIS);
  return new EndpointSpanInfoDto(request, Tracer.getInstance().getCurrentSpan(), userIdHeaderKeys);
}
origin: Nike-Inc/wingtips

@GetMapping(path = SPAN_INFO_CALL_PATH)
@SuppressWarnings("unused")
public EndpointSpanInfoDto getSpanInfoCall(HttpServletRequest request) {
  logger.info("Span info endpoint hit. Sleeping...");
  sleepThread(SLEEP_TIME_MILLIS);
  return new EndpointSpanInfoDto(request, Tracer.getInstance().getCurrentSpan(), userIdHeaderKeys);
}
origin: com.nike.riposte/riposte-core

protected String extractDistributedTraceId(RequestInfo requestInfo, ChannelHandlerContext ctx) {
  String traceId = (requestInfo == null) ? null : requestInfo.getHeaders().get(TraceHeaders.TRACE_ID);
  if (traceId == null) {
    traceId = supplierWithTracingAndMdc(
      () -> {
        Span currentSpanFromTracer = Tracer.getInstance().getCurrentSpan();
        if (currentSpanFromTracer != null)
          return currentSpanFromTracer.getTraceId();
        return null;
      },
      ctx
    ).get();
  }
  return traceId;
}
origin: Nike-Inc/riposte

protected String extractDistributedTraceId(RequestInfo requestInfo, ChannelHandlerContext ctx) {
  String traceId = (requestInfo == null) ? null : requestInfo.getHeaders().get(TraceHeaders.TRACE_ID);
  if (traceId == null) {
    traceId = supplierWithTracingAndMdc(
      () -> {
        Span currentSpanFromTracer = Tracer.getInstance().getCurrentSpan();
        if (currentSpanFromTracer != null)
          return currentSpanFromTracer.getTraceId();
        return null;
      },
      ctx
    ).get();
  }
  return traceId;
}
origin: Nike-Inc/wingtips

  protected CloseableHttpResponse propagateHeadersAndExecute(
    HttpRoute route,
    HttpRequestWrapper request,
    HttpClientContext clientContext,
    HttpExecutionAware execAware
  ) throws IOException, HttpException {
    propagateTracingHeaders(request, Tracer.getInstance().getCurrentSpan());
    return protocolExec.execute(route, request, clientContext, execAware);
  }
};
origin: Nike-Inc/wingtips

  @Override
  public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request,
                     HttpClientContext clientContext,
                     HttpExecutionAware execAware) throws IOException, HttpException {
    capturedSpan = Tracer.getInstance().getCurrentSpan();
    
    doReturn(statusLineMock).when(response).getStatusLine();
    
    if (exceptionToThrow != null) {
      throw exceptionToThrow;
    }
    // Return a graceful 500 from the response
    doReturn(500).when(statusLineMock).getStatusCode();
    return response;
  }
}
origin: Nike-Inc/wingtips

/**
 * Calls {@link WingtipsSpringUtil#propagateTracingHeaders(HttpMessage, Span)} to propagate the current span's
 * tracing state on the given request's headers, then returns
 * {@link ClientHttpRequestExecution#execute(HttpRequest, byte[])} to execute the request.
 *
 * @return The result of calling {@link ClientHttpRequestExecution#execute(HttpRequest, byte[])}.
 */
protected ClientHttpResponse propagateTracingHeadersAndExecuteRequest(
  HttpRequestWrapperWithModifiableHeaders wrapperRequest, byte[] body, ClientHttpRequestExecution execution
) throws IOException {
  propagateTracingHeaders(wrapperRequest, Tracer.getInstance().getCurrentSpan());
  
  // Execute the request/interceptor chain.
  return execution.execute(wrapperRequest, body);
}
origin: Nike-Inc/wingtips

/**
 * Calls {@link WingtipsSpringUtil#propagateTracingHeaders(HttpMessage, Span)} to propagate the current span's
 * tracing state on the given request's headers, then returns
 * {@link AsyncClientHttpRequestExecution#executeAsync(HttpRequest, byte[])} to execute the request.
 *
 * @return The result of calling {@link AsyncClientHttpRequestExecution#executeAsync(HttpRequest, byte[])}.
 */
protected ListenableFuture<ClientHttpResponse> propagateTracingHeadersAndExecute(
  HttpRequestWrapperWithModifiableHeaders wrapperRequest, byte[] body, AsyncClientHttpRequestExecution execution
) throws IOException {
  propagateTracingHeaders(wrapperRequest, Tracer.getInstance().getCurrentSpan());
  // Execute the request/interceptor chain.
  return execution.executeAsync(wrapperRequest, body);
}
origin: Nike-Inc/wingtips

@Test
public void getCurrentSpan_should_return_current_span() throws Exception {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("test-span");
  // when
  Span span = tracer.getCurrentSpan();
  // then
  assertThat(span).isNotNull();
  assertThat(span.getSpanName()).isEqualTo("test-span");
}
origin: Nike-Inc/wingtips

@Test
public void close_completes_the_span_as_expected_overall_request_span() {
  // given
  Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
  assertThat(overallSpan.isCompleted()).isFalse();
  // when
  overallSpan.close();
  // then
  assertThat(overallSpan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}
origin: Nike-Inc/wingtips

@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_overall_request_span() {
  // given
  Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
  assertThat(overallSpan.isCompleted()).isFalse();
  // when
  Tracer.getInstance().handleSpanCloseMethod(overallSpan);
  // then
  assertThat(overallSpan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}
origin: Nike-Inc/wingtips

@Test
public void completeSubSpan_should_do_nothing_if_the_span_stack_is_null() {
  // given: a null span stack
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
  assertThat(getSpanStackSize()).isEqualTo(0);
  assertThat(getSpanStackFromTracer()).isNull();
  // when: completeSubSpan() is called
  Tracer.getInstance().completeSubSpan();
  // then: nothing should be done because the stack is null
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
  assertThat(getSpanStackSize()).isEqualTo(0);
  assertThat(getSpanStackFromTracer()).isNull();
}
origin: Nike-Inc/wingtips

  @Override
  public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
    capturedSpan = Tracer.getInstance().getCurrentSpan();
    captureSpanCopyAtTimeOfDoFilter = Span.newBuilder(capturedSpan).build();
  }
}
origin: Nike-Inc/wingtips

@Test
public void close_completes_the_span_as_expected_subspan() {
  // given
  Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
  assertThat(subspan.isCompleted()).isFalse();
  // when
  subspan.close();
  // then
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}
origin: Nike-Inc/wingtips

@Test
public void startRequestWithRootSpan_wipes_out_any_existing_spans_on_the_stack() {
  // given: Tracer already has some Spans on the stack
  Tracer.getInstance().startRequestWithRootSpan("span1");
  Tracer.getInstance().startSubSpan("span2", SpanPurpose.LOCAL_ONLY);
  assertThat(getSpanStackSize()).isEqualTo(2);
  // when: Tracer.startRequestWithRootSpan(String) is called to start a span without a parent
  Tracer.getInstance().startRequestWithRootSpan("noparent");
  // then: a new span is started for it, and the other spans on the stack are removed
  assertThat(getSpanStackSize()).isEqualTo(1);
  Span span = Tracer.getInstance().getCurrentSpan();
  assertThat(span).isNotNull();
  assertThat(span.getSpanName()).isEqualTo("noparent");
}
origin: Nike-Inc/wingtips

@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_subspan() {
  // given
  Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
  assertThat(subspan.isCompleted()).isFalse();
  // when
  Tracer.getInstance().handleSpanCloseMethod(subspan);
  // then
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}
com.nike.wingtipsTracergetCurrentSpan

Javadoc

The Span set as the "current" one for this thread.

NOTE: If #currentSpanStackThreadLocal is null or empty for this thread it will try to reconstitute the Span from the logging org.slf4j.MDC. This is useful in some situations, for example async request processing where the thread changes but the MDC is smart enough to transfer the span anyway. In any case as a caller you don't have to care - you'll just get the Span appropriate for the caller, or null if one hasn't been set up yet.

Popular methods of Tracer

  • getInstance
  • addSpanLifecycleListener
    Adds the given listener to the #spanLifecycleListeners list using java.util.List#add(Object). This m
  • getSpanLifecycleListeners
  • removeSpanLifecycleListener
    Returns the value of calling java.util.List#remove(Object) on #spanLifecycleListeners.
  • getCurrentSpanStackCopy
  • startRequestWithRootSpan
  • unregisterFromThread
  • completeRequestSpan
  • startSpanInCurrentContext
  • registerWithThread
  • startSubSpan
  • completeSubSpan
  • startSubSpan,
  • completeSubSpan,
  • startRequestWithChildSpan,
  • setSpanLoggingRepresentation,
  • configureMDC,
  • containsSameSpansInSameOrder,
  • getCurrentManagedStatusForSpan,
  • getCurrentSpanStackSize,
  • getCurrentTracingStateCopy

Popular in Java

  • Creating JSON documents from java classes using gson
  • startActivity (Activity)
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Kernel (java.awt.image)
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JCheckBox (javax.swing)
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now