Tabnine Logo
Tracer.registerWithThread
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: Nike-Inc/wingtips

/**
 * Calls {@link Tracer#unregisterFromThread()} and {@link MDC#clear()} to reset this thread's tracing and
 * MDC state to be completely clean, then (optionally) resets the span stack and MDC info to the arguments
 * provided. If the span stack argument is null then the span stack will *not* be reset, and similarly if the MDC
 * info is null then the MDC info will *not* be reset. So if both are null then when this method finishes the trace
 * stack and MDC will be left in a blank state.
 *
 * @deprecated Please move to the Java 8 version of this class and method ({@code AsyncWingtipsHelper} or the static
 * {@code AsyncWingtipsHelperStatic}) whenever possible.
 */
@Deprecated
public static void unlinkTracingFromCurrentThread(Deque<Span> spanStackToResetFor,
                         Map<String, String> mdcContextMapToResetFor) {
  Tracer.getInstance().unregisterFromThread();
  MDC.clear();
  if (mdcContextMapToResetFor != null)
    MDC.setContextMap(mdcContextMapToResetFor);
  if (spanStackToResetFor != null)
    Tracer.getInstance().registerWithThread(spanStackToResetFor);
}
origin: com.nike.riposte/riposte-core

/**
 * Calls {@link Tracer#unregisterFromThread()} and {@link org.slf4j.MDC#clear()} to reset this thread's tracing and
 * MDC state to be completely clean, then (optionally) resets the trace stack and MDC info to the arguments
 * provided. If the trace stack argument is null then the trace stack will *not* be reset, and similarly if the MDC
 * info is null then the MDC info will *not* be reset. So if both are null then when this method finishes the trace
 * stack and MDC will be left in a blank state.
 */
public static void unlinkTracingAndMdcFromCurrentThread(Deque<Span> distributedTraceStackToResetFor,
                            Map<String, String> mdcContextMapToResetFor) {
  Tracer.getInstance().unregisterFromThread();
  MDC.clear();
  if (mdcContextMapToResetFor != null)
    MDC.setContextMap(mdcContextMapToResetFor);
  if (distributedTraceStackToResetFor != null)
    Tracer.getInstance().registerWithThread(distributedTraceStackToResetFor);
}
origin: Nike-Inc/riposte

/**
 * Calls {@link Tracer#unregisterFromThread()} and {@link org.slf4j.MDC#clear()} to reset this thread's tracing and
 * MDC state to be completely clean, then (optionally) resets the trace stack and MDC info to the arguments
 * provided. If the trace stack argument is null then the trace stack will *not* be reset, and similarly if the MDC
 * info is null then the MDC info will *not* be reset. So if both are null then when this method finishes the trace
 * stack and MDC will be left in a blank state.
 */
public static void unlinkTracingAndMdcFromCurrentThread(Deque<Span> distributedTraceStackToResetFor,
                            Map<String, String> mdcContextMapToResetFor) {
  Tracer.getInstance().unregisterFromThread();
  MDC.clear();
  if (mdcContextMapToResetFor != null)
    MDC.setContextMap(mdcContextMapToResetFor);
  if (distributedTraceStackToResetFor != null)
    Tracer.getInstance().registerWithThread(distributedTraceStackToResetFor);
}
origin: Nike-Inc/riposte

@Test
public void doChannelRead_does_not_propagate_errors_if_unexpected_exceptions_occur_during_endpoint_timing_annotations() {
  // given
  Span spanMock = mock(Span.class);
  Tracer.getInstance().registerWithThread(new ArrayDeque<>(Collections.singleton(spanMock)));
  assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanMock);
  TracingState tracingStateForTest = TracingState.getCurrentThreadTracingState();
  doReturn(tracingStateForTest.getLeft()).when(stateMock).getDistributedTraceStack();
  doReturn(tracingStateForTest.getRight()).when(stateMock).getLoggerMdcContextMap();
  doReturn(true).when(taggingStrategySpy).shouldAddEndpointStartAnnotation();
  doThrow(new RuntimeException("intentional exception")).when(taggingStrategySpy).endpointStartAnnotationName();
  doReturn(true).when(taggingStrategySpy).shouldAddEndpointFinishAnnotation();
  doThrow(new RuntimeException("intentional exception")).when(taggingStrategySpy).endpointFinishAnnotationName();
  ResponseInfo<?> responseInfoMock = mock(ResponseInfo.class);
  // when
  handlerSpy.doChannelRead(ctxMock, msg);
  futureThatWillBeAttachedToSpy.complete(responseInfoMock);
  Object result = futureThatWillBeAttachedToSpy.join();
  // then
  verify(taggingStrategySpy).endpointStartAnnotationName();
  verify(taggingStrategySpy).endpointFinishAnnotationName();
  assertThat(result).isSameAs(responseInfoMock);
  // We verified that the methods were called that would have thrown exceptions, and nothing propagated. So
  //      we're good.
}
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_do_nothing_if_copy_of_same_stack_is_passed_in() {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("foo");
  Span subspan = tracer.startSubSpan("bar", SpanPurpose.LOCAL_ONLY);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  // when
  Deque<Span> spanStack = getSpanStackThreadLocal().get();
  tracer.registerWithThread(new LinkedList<>(spanStack));
  // then
  assertThat(getSpanStackThreadLocal().get()).isEqualTo(spanStack);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
}
origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_try_to_recomplete_span_if_already_completed() throws Exception {
  // given
  Span span = setupTracingForChannelInactive(false);
  Deque<Span> deque = new LinkedList<>();
  deque.add(span);
  Tracer.getInstance().registerWithThread(deque);
  Tracer.getInstance().completeRequestSpan();
  Assertions.assertThat(span.isCompleted()).isTrue();
  long durationNanosBefore = span.getDurationNanos();
  // when
  PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
  // then
  Assertions.assertThat(span.isCompleted()).isTrue(); // no change
  Assertions.assertThat(span.getDurationNanos()).isEqualTo(durationNanosBefore);
  verify(requestInfoMock).releaseAllResources();
  verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_do_nothing_if_same_stack_is_passed_in() {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("foo");
  Span subspan = tracer.startSubSpan("bar", SpanPurpose.LOCAL_ONLY);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  // when
  Deque<Span> spanStack = getSpanStackThreadLocal().get();
  tracer.registerWithThread(spanStack);
  // then
  assertThat(getSpanStackThreadLocal().get()).isEqualTo(spanStack);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
}
origin: Nike-Inc/wingtips

  MDC.setContextMap(mdcContextMapToLink);
Tracer.getInstance().registerWithThread(spanStackToLink);
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_reset_everything_if_passed_empty_instance() {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("foo");
  Span subspan = tracer.startSubSpan("bar", SpanPurpose.LOCAL_ONLY);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  // when
  Deque<Span> emptyStack = new LinkedList<>();
  tracer.registerWithThread(emptyStack);
  // then
  assertThat(getSpanStackThreadLocal().get()).isEqualTo(emptyStack);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
}
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_reset_everything_if_passed_null() {
  // given
  Tracer tracer = Tracer.getInstance();
  tracer.startRequestWithRootSpan("foo");
  Span subspan = tracer.startSubSpan("bar", SpanPurpose.LOCAL_ONLY);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  // when
  tracer.registerWithThread(null);
  // then
  assertThat(getSpanStackThreadLocal().get()).isNull();
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
}
origin: Nike-Inc/wingtips

tracer.registerWithThread(new LinkedList<Span>());
  mock(Span.class), mock(Span.class), mock(Span.class)
));
tracer.registerWithThread(nonEmptyStack);
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_override_existing_stuff() {
  // given
  Tracer tracer = Tracer.getInstance();
  Span existingSpan = tracer.startRequestWithRootSpan("old");
  Deque<Span> newSpanStack = new LinkedList<>();
  Span parentSpan = Span.newBuilder("foo", SpanPurpose.LOCAL_ONLY).build();
  Span subspan = Span.newBuilder("bar", SpanPurpose.LOCAL_ONLY).build();
  newSpanStack.push(parentSpan);
  newSpanStack.push(subspan);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(existingSpan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(existingSpan.toJSON());
  // when
  tracer.registerWithThread(newSpanStack);
  // then
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  Deque<Span> spanStack = getSpanStackThreadLocal().get();
  assertThat(spanStack).isEqualTo(newSpanStack);
}
origin: Nike-Inc/riposte

Tracer.getInstance().registerWithThread(new ArrayDeque<>(Collections.singleton(spanMock)));
assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanMock);
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_work_as_advertised_if_existing_stack_is_empty() {
  // given
  getSpanStackThreadLocal().set(new LinkedList<Span>());
  Tracer tracer = Tracer.getInstance();
  Deque<Span> newSpanStack = new LinkedList<>();
  Span parentSpan = Span.newBuilder("foo", SpanPurpose.LOCAL_ONLY).build();
  Span subspan = Span.newBuilder("bar", SpanPurpose.LOCAL_ONLY).build();
  newSpanStack.push(parentSpan);
  newSpanStack.push(subspan);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
  // when
  tracer.registerWithThread(newSpanStack);
  // then
  // our stack was registered, so subspan should be current
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  assertThat(tracer.getCurrentSpan()).isEqualTo(subspan);
  // a *copy* of the stack we passed in should have been registered, and modifying the original stack should not affect Tracer's stack
  Deque<Span> spanStack = getSpanStackThreadLocal().get();
  assertThat(Tracer.getInstance().containsSameSpansInSameOrder(spanStack, newSpanStack)).isTrue();
  assertThat(spanStack).isNotSameAs(newSpanStack);
  newSpanStack.push(subspan.generateChildSpan("subsub", SpanPurpose.LOCAL_ONLY));
  assertThat(newSpanStack).hasSize(3);
  assertThat(spanStack).hasSize(2);
}
origin: Nike-Inc/wingtips

@Test
public void registerWithThread_should_work_as_advertised() {
  // given
  Tracer tracer = Tracer.getInstance();
  Deque<Span> newSpanStack = new LinkedList<>();
  Span parentSpan = Span.newBuilder("foo", SpanPurpose.LOCAL_ONLY).build();
  Span subspan = Span.newBuilder("bar", SpanPurpose.LOCAL_ONLY).build();
  newSpanStack.push(parentSpan);
  newSpanStack.push(subspan);
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
  // when
  tracer.registerWithThread(newSpanStack);
  // then
  // our stack was registered, so subspan should be current
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isEqualTo(subspan.getTraceId());
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(subspan.toJSON());
  assertThat(tracer.getCurrentSpan()).isEqualTo(subspan);
  // a *copy* of the stack we passed in should have been registered, and modifying the original stack should not affect Tracer's stack
  Deque<Span> spanStack = getSpanStackThreadLocal().get();
  assertThat(Tracer.getInstance().containsSameSpansInSameOrder(spanStack, newSpanStack)).isTrue();
  assertThat(spanStack).isNotSameAs(newSpanStack);
  newSpanStack.push(subspan.generateChildSpan("subsub", SpanPurpose.LOCAL_ONLY));
  assertThat(newSpanStack).hasSize(3);
  assertThat(spanStack).hasSize(2);
}
origin: com.nike.riposte/riposte-core

  MDC.setContextMap(mdcContextMapToLink);
Tracer.getInstance().registerWithThread(distributedTraceStackToLink);
origin: Nike-Inc/riposte

  MDC.setContextMap(mdcContextMapToLink);
Tracer.getInstance().registerWithThread(distributedTraceStackToLink);
origin: Nike-Inc/riposte

  MDC.setContextMap(mdcContextMap);
Tracer.getInstance().registerWithThread(distributedTraceStack);
origin: Nike-Inc/wingtips

tracer.registerWithThread(reqAStack);
tracer.registerWithThread(reqBStack);
com.nike.wingtipsTracerregisterWithThread

Javadoc

"Registers" a *COPY* of the given span stack with this thread (sets up the ThreadLocal span stack with a copy of the given argument) and sets up the MDC appropriately based on what you pass in. This is used in asynchronous projects/frameworks where multiple in-progress requests might be handled by the same thread before any of the requests can finish (e.g. Netty, where the worker I/O threads might process a portion of request A, flip over to request B to do some work, then go back to request A, etc). When the worker thread was about to stop working on the original request and move to a new one you would call #unregisterFromThread()and store the result with some kind of context state that follows the original request, and when processing switches back to the original request you would call this method to set the thread's span stack and MDC info back to the way it was so you could continue where you left off.

In a properly functioning project/framework this thread would not have any span information in its stack when this method was called, so if there are any spans already on this thread then this method will mark them as invalid, complete them, and log an appropriate error message before registering the stack passed into this method.

NOTE: A *copy* of the given stack is registered so that changes to the stack you pass in don't affect the stack stored here. This prevents a host of subtle annoying bugs.

WARNING: This method should NOT be called if you're in an environment where a single thread is guaranteed to process a request from start to finish without jumping to a different request in the middle. In that case just use the normal start and complete span methods and ignore this method.

Popular methods of Tracer

  • getInstance
  • getCurrentSpan
  • 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
  • startSubSpan
  • completeSubSpan
  • startSubSpan,
  • completeSubSpan,
  • startRequestWithChildSpan,
  • setSpanLoggingRepresentation,
  • configureMDC,
  • containsSameSpansInSameOrder,
  • getCurrentManagedStatusForSpan,
  • getCurrentSpanStackSize,
  • getCurrentTracingStateCopy

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • setScale (BigDecimal)
  • compareTo (BigDecimal)
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Reference (javax.naming)
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JTable (javax.swing)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top Vim 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