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

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

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

Span.newBuilder介绍

暂无

代码示例

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

/**
 * @param spanName The {@link Span#getSpanName()} to initialize the builder with.
 * @param spanPurpose The {@link SpanPurpose} to initialize the builder with. See the javadocs for {@link SpanPurpose} for full details on what each enum option
 *                    means. If you pass in null for this then {@link SpanPurpose#UNKNOWN} will be used.
 * @return A builder setup to generate an uncompleted root span for a new trace. Since it is a root span it will have a null {@link #getParentSpanId()}.
 *          If no further changes are made to the returned builder then when {@link Builder#build()} is called the resulting span's {@link #getTraceId()}
 *          and {@link #getSpanId()} will be randomly generated, and {@link #getSpanStartTimeEpochMicros()} and {@link #getSpanStartTimeNanos()} will be set to
 *          the appropriate values based on when {@link Builder#build()} is called. If further tweaks to the span are necessary you can adjust the builder
 *          before calling {@link Builder#build()} (e.g. setting a user ID via {@link Builder#withUserId(String)}.
 */
public static Builder generateRootSpanForNewTrace(String spanName, SpanPurpose spanPurpose) {
  return Span.newBuilder(spanName, spanPurpose);
}

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

private Span setupTracingForChannelInactive(boolean traceCompletedOrScheduled) {
  state.setTraceCompletedOrScheduled(traceCompletedOrScheduled);
  Span span = Span.newBuilder("fooSpan", Span.SpanPurpose.SERVER).build();
  Assertions.assertThat(span.isCompleted()).isFalse();
  Deque<Span> spanStack = new LinkedList<>();
  spanStack.add(span);
  state.setDistributedTraceStack(spanStack);
  return span;
}

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

@Test
public void setSpanName_throws_IllegalArgumentException_if_passed_null() {
  // given
  Span span = Span.newBuilder("origSpanName", SpanPurpose.SERVER).build();
  // when
  Throwable ex = catchThrowable(() -> span.setSpanName(null));
  // then
  assertThat(ex).isInstanceOf(IllegalArgumentException.class);
}

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

@Test
public void changeSpanName_works_as_expected() {
  // given
  Span span = Span.newBuilder("origSpanName", Span.SpanPurpose.SERVER).build();
  String newSpanName = UUID.randomUUID().toString();
  assertThat(span.getSpanName()).isNotEqualTo(newSpanName);
  // when
  SpanMutator.changeSpanName(span, newSpanName);
  // then
  assertThat(span.getSpanName()).isEqualTo(newSpanName);
}

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

@Test
public void setSpanName_works_as_expected() {
  // given
  Span span = Span.newBuilder("origSpanName", SpanPurpose.SERVER).build();
  String newSpanName = UUID.randomUUID().toString();
  assertThat(span.getSpanName()).isNotEqualTo(newSpanName);
  // when
  span.setSpanName(newSpanName);
  // then
  assertThat(span.getSpanName()).isEqualTo(newSpanName);
}

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

@Test
public void doDetermineAndSetFinalSpanName_delegates_to_adapter_getFinalSpanName_and_changes_span_name_if_result_is_not_blank() {
  // given
  String adapterSpanNameResult = UUID.randomUUID().toString();
  doReturn(adapterSpanNameResult).when(adapterMock).getFinalSpanName(anyObject(), anyObject());
  Span span = Span.newBuilder("originalSpanName", SpanPurpose.SERVER).build();
  assertThat(span.getSpanName()).isNotEqualTo(adapterSpanNameResult);
  // when
  implSpy.doDetermineAndSetFinalSpanName(span, requestObjectMock, responseObjectMock, errorMock, adapterMock);
  // then
  assertThat(span.getSpanName()).isEqualTo(adapterSpanNameResult);
  verify(adapterMock).getFinalSpanName(requestObjectMock, responseObjectMock);
}

代码示例来源: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 builder_withTimestampedAnnotations_does_nothing_if_passed_null() {
  // given
  Span.Builder builder = Span.newBuilder("foo", SpanPurpose.UNKNOWN);
  List<TimestampedAnnotation> annotationsListSpy = spy(new ArrayList<>());
  Whitebox.setInternalState(builder, "annotations", annotationsListSpy);
  // when
  Span.Builder resultingBuilder = builder.withTimestampedAnnotations(null);
  // then
  assertThat(resultingBuilder).isSameAs(builder);
  verifyZeroInteractions(annotationsListSpy);
  // and when
  Span resultingSpan = resultingBuilder.build();
  // then
  assertThat(resultingSpan.getTimestampedAnnotations()).isEmpty();
}

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

@Test
public void fromJSON_delegates_to_span_parser() {
  // given
  Span span = Span.newBuilder("foo", SpanPurpose.CLIENT)
          .withTag("blahtag", UUID.randomUUID().toString())
          .build();
  String json = span.toJSON();
  // when
  Span result = span.fromJSON(json);
  // then
  verifySpanDeepEquals(result, span, true);
}

代码示例来源: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 configureMDC_should_set_span_values_on_MDC() throws Exception {
  // given
  Span span = Span.newBuilder("test-span", SpanPurpose.LOCAL_ONLY).withParentSpanId("3").build();
  String expected = span.toJSON();
  // when
  Tracer.configureMDC(span);
  // then
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isEqualTo(expected);
}

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

@Test
public void addTimestampedAnnotation_works_as_expected() {
  // given
  Span span = Span.newBuilder("foo", SpanPurpose.CLIENT).build();
  TimestampedAnnotation annotationMock = mock(TimestampedAnnotation.class);
  
  // when
  span.addTimestampedAnnotation(annotationMock);
  // then
  assertThat(span.getTimestampedAnnotations())
    .hasSize(1)
    .containsExactly(annotationMock);
}

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

@Test
public void fromKeyValueString_delegates_to_span_parser() {
  // given
  Span span = Span.newBuilder("foo", SpanPurpose.CLIENT)
          .withTag("blahtag", UUID.randomUUID().toString())
          .build();
  String keyValueStr = span.toKeyValueString();
  // when
  Span result = span.fromKeyValueString(keyValueStr);
  // then
  verifySpanDeepEquals(result, span, true);
}

代码示例来源: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 unconfigureMDC_should_unset_span_values_on_MDC() throws Exception {
  // given
  Span span = Span.newBuilder("test-span", SpanPurpose.LOCAL_ONLY).withParentSpanId("3").build();
  Tracer.configureMDC(span);
  // when
  Tracer.unconfigureMDC();
  // then
  assertThat(MDC.get(Tracer.SPAN_JSON_MDC_KEY)).isNull();
}

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

@UseDataProvider("badKeyValueScenarioDataProvider")
@Test
public void fromKeyValueString_should_return_null_for_garbage_input(BadKeyValueScenario scenario) {
  // given: garbage input
  String garbageInput = scenario.generateBadKeyValueStr(
    Span.newBuilder("foo", SpanPurpose.CLIENT)
      .withTag("footag", "bar")
      .build()
  );
  // when: fromKeyValueString is called
  Span spanFromKeyValStr = SpanParser.fromKeyValueString(garbageInput);
  // then: the return value should be null
  assertThat(spanFromKeyValStr).isNull();
}

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

private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders() {
  Span span = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT).build();
  Map<String, String> headers = MapBuilder
    .builder(TraceHeaders.TRACE_ID, span.getTraceId())
    .put(TraceHeaders.SPAN_ID, span.getSpanId())
    .put(TraceHeaders.SPAN_NAME, span.getSpanName())
    .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()))
    .build();
  return Pair.of(span, headers);
}

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

private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders() {
  Span span = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT).build();
  Map<String, String> headers = MapBuilder
    .builder(TraceHeaders.TRACE_ID, span.getTraceId())
    .put(TraceHeaders.SPAN_ID, span.getSpanId())
    .put(TraceHeaders.SPAN_NAME, span.getSpanName())
    .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()))
    .build();
  return Pair.of(span, headers);
}

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

private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders() {
  Span span = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT).build();
  Map<String, String> headers = MapBuilder
    .builder(TraceHeaders.TRACE_ID, span.getTraceId())
    .put(TraceHeaders.SPAN_ID, span.getSpanId())
    .put(TraceHeaders.SPAN_NAME, span.getSpanName())
    .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()))
    .build();
  return Pair.of(span, headers);
}

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

private Pair<Span, Map<String, String>> generateUpstreamSpanHeaders() {
  Span span = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT).build();
  Map<String, String> headers = MapBuilder
    .builder(TraceHeaders.TRACE_ID, span.getTraceId())
    .put(TraceHeaders.SPAN_ID, span.getSpanId())
    .put(TraceHeaders.SPAN_NAME, span.getSpanName())
    .put(TraceHeaders.TRACE_SAMPLED, String.valueOf(span.isSampleable()))
    .build();
  return Pair.of(span, headers);
}

相关文章