congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Span$Builder.build
Code IndexAdd Tabnine to your IDE (free)

How to use
build
method
in
com.nike.wingtips.Span$Builder

Best Java code snippets using com.nike.wingtips.Span$Builder.build (Showing top 20 results out of 315)

origin: Nike-Inc/wingtips

@DataProvider
public static Object[][] spanStackDataProvider() {
  Span rootSpan = Span.generateRootSpanForNewTrace("rootspan", SpanPurpose.SERVER).build();
  Span childSpan = rootSpan.generateChildSpan("childSpan", SpanPurpose.CLIENT);
  return new Object[][] {
      { null },
      { new LinkedList<>() },
      { new LinkedList<>(Collections.singleton(rootSpan)) },
      { new LinkedList<>(Arrays.asList(rootSpan, childSpan)) }
  };
}
origin: Nike-Inc/wingtips

@Test
public void toJson_should_use_cached_json() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedJsonRepresentation", uuidString);
  // when
  String toJsonResult = validSpan.toJSON();
  // then
  assertThat(toJsonResult).isEqualTo(uuidString);
}
origin: Nike-Inc/wingtips

@Test
public void toKeyValueString_should_use_cached_key_value_string() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedKeyValueRepresentation", uuidString);
  // when
  String toKeyValueStringResult = validSpan.toKeyValueString();
  // then
  assertThat(toKeyValueStringResult).isEqualTo(uuidString);
}
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

  @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 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 getDuration_should_be_null_until_span_is_completed() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  assertThat(validSpan.getDurationNanos()).isNull();
  // when
  validSpan.complete();
  // then
  assertThat(validSpan.getDurationNanos()).isNotNull();
}
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 convertSpanToKeyValueFormat_should_function_properly_for_non_completed_spans() {
  // given: valid span and key/value string from SpanParser.convertSpanToKeyValueFormat()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  assertThat(validSpan.isCompleted()).isFalse();
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: the string is deserialized into a map
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(keyValueStr);
  // then: the original span and deserialized map values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}
origin: Nike-Inc/wingtips

@Test
public void convertSpanToKeyValueFormat_should_function_properly_for_completed_spans() {
  // given: valid span and completed, and key/value string from SpanParser.convertSpanToKeyValueFormat()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: the string is deserialized into a map
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(keyValueStr);
  // then: the original span and deserialized map values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}
origin: Nike-Inc/wingtips

@Test
public void fromJson_should_function_properly_for_completed_spans() {
  // given: valid span that has been completed, and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  String json = SpanParser.convertSpanToJSON(validSpan);
  // when: fromJson is called
  Span spanFromJson = SpanParser.fromJSON(json);
  // then: the original span and the fromJson() span values should be exactly the same
  verifySpanDeepEquals(spanFromJson, validSpan, true);
}
origin: Nike-Inc/wingtips

@Test
public void fromJson_should_function_properly_for_non_completed_spans() {
  // given: valid, non-completed span and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String json = SpanParser.convertSpanToJSON(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  // when: fromJson is called
  Span spanFromJson = SpanParser.fromJSON(json);
  // then: the original span and the fromJson() span values should be exactly the same
  verifySpanDeepEquals(spanFromJson, validSpan, true);
}
origin: Nike-Inc/wingtips

@Test
public void convertSpanToJSON_should_function_properly_for_non_completed_spans() throws IOException {
  // given: valid span and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String json = SpanParser.convertSpanToJSON(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  assertThat(validSpan.getDurationNanos()).isNull();
  // when: jackson is used to deserialize that JSON
  Map<String, Object> spanValuesFromJackson = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
  // then: the original span and jackson's span values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, spanValuesFromJackson);
}
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

@Test
public void fromKeyValueString_should_function_properly_for_non_completed_spans() {
  // given: valid, non-completed span and key/value string from Span.fromKeyValueString()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String keyValStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  // when: fromKeyValueString is called
  Span spanFromKeyValStr = SpanParser.fromKeyValueString(keyValStr);
  // then: the original span and the fromKeyValueString() span values should be exactly the same
  verifySpanDeepEquals(spanFromKeyValStr, validSpan, true);
}
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

@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

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

@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

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);
}
com.nike.wingtipsSpan$Builderbuild

Javadoc

Returns a Span built from the parameters set via the various with*(...) methods on this builder instance.

IMPORTANT NOTE: Span objects are not allowed to have null Span#getTraceId(), Span#getSpanId(), or Span#getSpanStartTimeEpochMicros(), and there are sensible defaults we can set for those values when creating a new span, so if any of them are null when this method is called it is assumed you are creating a new span and they will be set to the following:

  • traceId is defaulted to TraceAndSpanIdGenerator#generateId().
  • spanId is defaulted to TraceAndSpanIdGenerator#generateId().
  • spanStartTimeEpochMicros is defaulted to System#currentTimeMillis() converted to microseconds.
    • Side note - spanStartTimeNanos is calculated based on the rules described in #withSpanStartTimeNanos(Long).

Span name is also not allowed to be null, but since there is no sensible default for that value an IllegalArgumentException will be thrown if span name is null when this method is called.

Popular methods of Span$Builder

  • withParentSpanId
    Sets the ID of the span that spawned this span instance (the logical "parent" of this span), or pass
  • withSampleable
    Set this to true if this span is sampleable and should be output to the logging/span collection syst
  • withUserId
    Sets the ID of the user logically associated with this span, or pass in null if no such user ID exis
  • withTraceId
    Sets the The ID associated with the overall distributed trace - a.k.a. the trace tree ID. All spans
  • withDurationNanos
    Sets the duration of the span in nanoseconds, or null if this Span should not be considered Span#is
  • withSpanId
    Sets the ID for this span of work in the distributed trace. Don't confuse this with #withTraceId(Str
  • withSpanStartTimeEpochMicros
    Sets the start timestamp in microseconds since the epoch for this span (*not* milliseconds), or pas
  • withSpanStartTimeNanos
    TLDR; Passing in null (or not calling this method at all) is always a safe option - when in doubt le
  • <init>
  • withSpanName
    Sets the human-readable name for this span. This should never be null - if you set this to null and
  • withSpanPurpose
    Sets the SpanPurpose for this span. See the javadocs on that class for details on what each enum opt
  • withTag
    Sets the value of a tag for the respective key. This will replace an existing tag value for the resp
  • withSpanPurpose,
  • withTag,
  • withTags,
  • withTimestampedAnnotation,
  • withTimestampedAnnotations

Popular in Java

  • Reactive rest calls using spring rest template
  • getSystemService (Context)
  • getSupportFragmentManager (FragmentActivity)
  • compareTo (BigDecimal)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Permission (java.security)
    Legacy security code; do not use.
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • JOptionPane (javax.swing)
  • Top PhpStorm 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