com.nike.wingtips.Tracer.completeRequestSpan()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中com.nike.wingtips.Tracer.completeRequestSpan()方法的一些代码示例,展示了Tracer.completeRequestSpan()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.completeRequestSpan()方法的具体详情如下:
包路径:com.nike.wingtips.Tracer
类名称:Tracer
方法名:completeRequestSpan

Tracer.completeRequestSpan介绍

[英]Completes the current span by calling #completeAndLogSpan(Span,boolean) on it, empties the MDC by calling #unconfigureMDC(), and clears out the #currentSpanStackThreadLocal stack.

This should be called by the overall request when the request is done. At the point this method is called there should just be one span left on the #currentSpanStackThreadLocal stack - the overall request span. If there is more than 1 then that indicates a bug with the usage of this class where a child span is created but not completed. If this error case is detected then and all spans will be logged/popped and an error message will be logged with details on what went wrong.
[中]通过调用#completeAndLogSpan(span,布尔值)来完成当前span,通过调用#unconfigureMDC()清空MDC,并清除#currentSpanStackThreadLocal堆栈。
当请求完成时,应该由整体请求调用。在调用此方法时,#currentSpanStackThreadLocal堆栈上应该只剩下一个跨度,即整个请求跨度。如果超过1,则表示该类的使用存在错误,其中创建了一个子跨度,但尚未完成。如果检测到此错误情况,则会记录/弹出所有跨度,并记录错误消息,详细说明出错原因。

代码示例

代码示例来源:origin: com.nike.riposte/riposte-core

protected void completeCurrentSpan() {
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/riposte

protected void completeCurrentSpan() {
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/wingtips

@Override
  public void run() {
    Span span = Tracer.getInstance().getCurrentSpan();
    try {
      // Handle response/error tagging and final span name.
      tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName(
        span, httpRequest, httpResponse, error, tagAndNamingAdapter
      );
    }
    finally {
      // Complete the overall request span.
      Tracer.getInstance().completeRequestSpan();
    }
  }
},

代码示例来源:origin: Nike-Inc/riposte

private void resetTracingAndMdc() {
  MDC.clear();
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/riposte

private void resetTracingAndMdc() {
  MDC.clear();
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/riposte

private void resetTracingAndMdc() {
  MDC.clear();
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/riposte

private void resetTracingAndMdc() {
  MDC.clear();
  Tracer.getInstance().completeRequestSpan();
}

代码示例来源:origin: Nike-Inc/riposte

Tracer.getInstance().completeRequestSpan();

代码示例来源: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 spanLifecycleListener_spanCompleted_is_not_called_when_request_span_was_completed_already() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  Span span = tracer.startRequestWithRootSpan("newspan");
  span.complete();
  verify(listener1).spanStarted(span);
  verify(listener1, times(0)).spanCompleted(span);
  verify(listener2).spanStarted(span);
  verify(listener2, times(0)).spanCompleted(span);
  // when
  tracer.completeRequestSpan();
  // then
  verify(listener1, never()).spanCompleted(span);
  verify(listener2, never()).spanCompleted(span);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void spanLifecycleListener_spanCompleted_is_called_when_request_span_is_completed() {
  // given
  SpanLifecycleListener listener1 = mock(SpanLifecycleListener.class);
  SpanLifecycleListener listener2 = mock(SpanLifecycleListener.class);
  Tracer tracer = Tracer.getInstance();
  tracer.addSpanLifecycleListener(listener1);
  tracer.addSpanLifecycleListener(listener2);
  Span span = tracer.startRequestWithRootSpan("newspan");
  verify(listener1).spanStarted(span);
  verify(listener1, times(0)).spanCompleted(span);
  verify(listener2).spanStarted(span);
  verify(listener2, times(0)).spanCompleted(span);
  // when
  tracer.completeRequestSpan();
  // then
  verify(listener1).spanCompleted(span);
  verify(listener2).spanCompleted(span);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void getCurrentTracerManagedSpanStatus_works_as_expected_for_unmanaged() {
  // given
  Span manuallyCreatedSpan = Span.newBuilder("manuallyCreatedSpan", SpanPurpose.LOCAL_ONLY).build();
  Span completedSpan = Tracer.getInstance().startRequestWithRootSpan("completedSpan");
  Tracer.getInstance().completeRequestSpan();
  // when
  TracerManagedSpanStatus tmssManual = manuallyCreatedSpan.getCurrentTracerManagedSpanStatus();
  TracerManagedSpanStatus tmssCompleted = completedSpan.getCurrentTracerManagedSpanStatus();
  // then
  assertThat(tmssManual).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
  assertThat(tmssCompleted).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void completeRequestSpan_should_complete_the_span() {
  // given: an already-started span
  Tracer.getInstance().startRequestWithRootSpan("somespan");
  Span span = Tracer.getInstance().getCurrentSpan();
  assertThat(span.getSpanName()).isEqualTo("somespan");
  assertThat(getSpanStackSize()).isEqualTo(1);
  assertThat(span.isCompleted()).isFalse();
  // when: completeRequestSpan() is called
  long beforeNanoTime = System.nanoTime();
  Tracer.getInstance().completeRequestSpan();
  long afterNanoTime = System.nanoTime();
  // then: the span should be completed, the stack emptied, and the MDC unconfigured
  assertThat(span.isCompleted()).isTrue();
  verifyDurationBetweenLowerAndUpperBounds(span, beforeNanoTime, afterNanoTime);
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
  assertThat(getSpanStackSize()).isEqualTo(0);
  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 starting_request_span_should_configure_MDC_and_completing_it_should_unset_MDC() throws Exception {
  // given
  Tracer tracer = Tracer.getInstance();
  // when
  tracer.startRequestWithRootSpan("test-span");
  // then
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNotNull();
  // and when
  tracer.completeRequestSpan();
  // then
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void getCurrentManagedStatusForSpan_works_as_expected_for_unmanaged() {
  // given
  Span manuallyCreatedSpan = Span.newBuilder("manuallyCreatedSpan", SpanPurpose.LOCAL_ONLY).build();
  Span completedSpan = Tracer.getInstance().startRequestWithRootSpan("completedSpan");
  Tracer.getInstance().completeRequestSpan();
  // when
  TracerManagedSpanStatus tmssManual = Tracer.getInstance().getCurrentManagedStatusForSpan(manuallyCreatedSpan);
  TracerManagedSpanStatus tmssCompleted = Tracer.getInstance().getCurrentManagedStatusForSpan(completedSpan);
  // then
  assertThat(tmssManual).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
  assertThat(tmssCompleted).isEqualTo(TracerManagedSpanStatus.UNMANAGED_SPAN);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void completeRequestSpan_should_do_nothing_if_there_is_no_span_to_complete() {
  // given: no span started
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
  assertThat(getSpanStackSize()).isEqualTo(0);
  // when: completeRequestSpan() is called
  Tracer.getInstance().completeRequestSpan();
  // then: nothing should be done
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
  assertThat(MDC.get(Tracer.TRACE_ID_MDC_KEY)).isNull();
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
  assertThat(getSpanStackSize()).isEqualTo(0);
}

代码示例来源:origin: Nike-Inc/wingtips

Tracer.getInstance().completeRequestSpan();
long afterNanoTime = System.nanoTime();

代码示例来源:origin: Nike-Inc/wingtips

Tracer.getInstance().completeRequestSpan();

代码示例来源:origin: Nike-Inc/wingtips

private void resetTracer() {
  Tracer.getInstance().completeRequestSpan();
  Tracer.getInstance().setRootSpanSamplingStrategy(new SampleAllTheThingsStrategy());
  for (SpanLifecycleListener listener : new ArrayList<>(Tracer.getInstance().getSpanLifecycleListeners())) {
    Tracer.getInstance().removeSpanLifecycleListener(listener);
  }
  Tracer.getInstance().setSpanLoggingRepresentation(Tracer.SpanLoggingRepresentation.JSON);
}

代码示例来源:origin: Nike-Inc/wingtips

Tracer.getInstance().completeRequestSpan();

相关文章