Tabnine Logo
Span$Builder.withParentSpanId
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void propagateTracingHeaders_only_sends_parent_span_id_header_if_parent_span_id_exists(
  boolean parentSpanIdExists
) {
  // given
  String parentSpanId = (parentSpanIdExists) ? UUID.randomUUID().toString() : null;
  Span span = Span.newBuilder("foo", SpanPurpose.CLIENT)
          .withParentSpanId(parentSpanId)
          .build();
  // when
  WingtipsSpringUtil.propagateTracingHeaders(httpMessageMock, span);
  // then
  if (parentSpanIdExists) {
    verify(headersMock).set(PARENT_SPAN_ID, parentSpanId);
  }
  else {
    verify(headersMock, never()).set(eq(PARENT_SPAN_ID), anyString());
  }
}
origin: Nike-Inc/wingtips

.withTraceId(badTraceId)
.withSpanId(badSpanId)
.withParentSpanId(badParentSpanId)
.withSpanStartTimeEpochMicros(Math.abs(random.nextLong()))
.withDurationNanos(Math.abs(random.nextLong()))
origin: Nike-Inc/wingtips

? null
: Span.newBuilder(UUID.randomUUID().toString(), SpanPurpose.CLIENT)
   .withParentSpanId(UUID.randomUUID().toString())
   .build();
origin: Nike-Inc/wingtips

.withTraceId(traceId)
.withSpanId(spanId)
.withParentSpanId(parentSpanId)
.withSpanName(spanName)
.withSampleable(sampleableForFullyCompleteSpan)
origin: Nike-Inc/wingtips

.newBuilder(newSpanName, spanPurpose)
.withTraceId(traceId)
.withParentSpanId(parentSpanId)
.withSampleable(sampleable)
.withUserId(userId)
origin: Nike-Inc/wingtips

? null
: spy(Span.newBuilder(UUID.randomUUID().toString(), Span.SpanPurpose.CLIENT)
     .withParentSpanId(UUID.randomUUID().toString())
     .build());
origin: Nike-Inc/wingtips

.withParentSpanId(getSpanIdFromRequest(request, TraceHeaders.PARENT_SPAN_ID, false))
.withSpanId(getSpanIdFromRequest(request, TraceHeaders.SPAN_ID, true))
.withSampleable(getSpanSampleableFlag(request))
origin: Nike-Inc/wingtips

@Test
public void convertSpanToKeyValueFormat_and_fromKeyValueString_should_escape_and_unescape_expected_non_tag_or_annotation_values() {
  // The TAGS_AND_ANNOTATIONS_WITH_SPECIAL_CHARS case already verified tags and annotations. Now we need to
  //      verify that non-tag values are escaped. Also note that other tests have verified that escapeJson()
  //      and unescapeJson() work properly.
  // given
  String complexSpanName = "span-name-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexTraceId = "trace-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexParentId = "parent-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexSpanId = "span-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexUserId = "user-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  Span span = Span.newBuilder(complexSpanName, SpanPurpose.CLIENT)
          .withTraceId(complexTraceId)
          .withParentSpanId(complexParentId)
          .withSpanId(complexSpanId)
          .withUserId(complexUserId)
          .build();
  // when
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(span);
  // then
  assertThat(keyValueStr).contains("traceId=\"trace-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(keyValueStr).contains("parentSpanId=\"parent-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(keyValueStr).contains("spanId=\"span-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(keyValueStr).contains("userId=\"user-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(keyValueStr).contains("spanName=\"span-name-" + ESCAPED_JSON_CHARS + "\"");
  // and when
  Span deserialized = SpanParser.fromKeyValueString(keyValueStr);
  // then
  verifySpanDeepEquals(deserialized, span, true);
}
origin: Nike-Inc/wingtips

.withParentSpanId(TraceAndSpanIdGenerator.generateId())
.withSampleable(false)
.withUserId("someUser")
origin: Nike-Inc/wingtips

@Test
public void convertSpanToJSON_and_fromJSON_should_escape_and_unescape_expected_non_tag_or_annotation_values() {
  // The TAGS_AND_ANNOTATIONS_WITH_SPECIAL_CHARS case already verified tags and annotations. Now we need to
  //      verify that non-tag values are escaped. Also note that other tests have verified that escapeJson()
  //      and unescapeJson() work properly.
  // given
  String complexSpanName = "span-name-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexTraceId = "trace-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexParentId = "parent-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexSpanId = "span-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  String complexUserId = "user-id-" + ALL_JSON_CHARS_THAT_NEED_ESCAPING;
  Span span = Span.newBuilder(complexSpanName, SpanPurpose.CLIENT)
          .withTraceId(complexTraceId)
          .withParentSpanId(complexParentId)
          .withSpanId(complexSpanId)
          .withUserId(complexUserId)
          .build();
  // when
  String json = SpanParser.convertSpanToJSON(span);
  // then
  assertThat(json).contains("\"traceId\":\"trace-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(json).contains("\"parentSpanId\":\"parent-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(json).contains("\"spanId\":\"span-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(json).contains("\"userId\":\"user-id-" + ESCAPED_JSON_CHARS + "\"");
  assertThat(json).contains("\"spanName\":\"span-name-" + ESCAPED_JSON_CHARS + "\"");
  // and when
  Span deserialized = SpanParser.fromJSON(json);
  // then
  verifySpanDeepEquals(deserialized, span, true);
}
origin: Nike-Inc/wingtips

? null
: spy(Span.newBuilder(UUID.randomUUID().toString(), SpanPurpose.CLIENT)
     .withParentSpanId(UUID.randomUUID().toString())
     .build());
origin: Nike-Inc/wingtips

@Test
public void doFilterInternal_should_use_user_id_from_parent_span_info_if_present_in_request_headers(
) throws ServletException, IOException {
  // given: filter and request that has parent span info
  RequestTracingFilter spyFilter = spy(getBasicFilter());
  given(requestMock.getHeader(ALT_USER_ID_HEADER_KEY)).willReturn("testUserId");
  Span parentSpan = Span.newBuilder("someParentSpan", null)
             .withParentSpanId(TraceAndSpanIdGenerator.generateId())
             .withSampleable(false)
             .withUserId("someUser")
             .build();
  given(requestMock.getHeader(TraceHeaders.TRACE_ID)).willReturn(parentSpan.getTraceId());
  given(requestMock.getHeader(TraceHeaders.SPAN_ID)).willReturn(parentSpan.getSpanId());
  given(requestMock.getHeader(TraceHeaders.PARENT_SPAN_ID)).willReturn(parentSpan.getParentSpanId());
  given(requestMock.getHeader(TraceHeaders.SPAN_NAME)).willReturn(parentSpan.getSpanName());
  given(requestMock.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(String.valueOf(parentSpan.isSampleable()));
  given(requestMock.getServletPath()).willReturn("/some/path");
  given(requestMock.getMethod()).willReturn("GET");
  // when: doFilterInternal is called
  spyFilter.doFilterInternal(requestMock, responseMock, spanCapturingFilterChain);
  // then: the span that is created should use the parent span info as its parent
  assertThat(spanCapturingFilterChain.capturedSpan).isNotNull();
  Span newSpan = spanCapturingFilterChain.capturedSpan;
  assertThat(newSpan.getUserId()).isEqualTo("testUserId");
}
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void propagateTracingHeaders_only_sends_parent_span_id_header_if_parent_span_id_exists(
  boolean parentSpanIdExists
) {
  // given
  String parentSpanId = (parentSpanIdExists) ? UUID.randomUUID().toString() : null;
  Span span = Span.newBuilder("foo", Span.SpanPurpose.CLIENT)
          .withParentSpanId(parentSpanId)
          .build();
  // when
  WingtipsApacheHttpClientUtil.propagateTracingHeaders(requestMock, span);
  // then
  if (parentSpanIdExists) {
    verify(requestMock).setHeader(PARENT_SPAN_ID, parentSpanId);
  }
  else {
    verify(requestMock, never()).setHeader(eq(PARENT_SPAN_ID), anyString());
  }
}
origin: Nike-Inc/wingtips

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void propagateTracingHeaders_only_sends_parent_span_id_header_if_parent_span_id_exists(
  boolean parentSpanIdExists
) {
  // given
  String parentSpanId = (parentSpanIdExists) ? UUID.randomUUID().toString() : null;
  Span span = Span.newBuilder("foo", SpanPurpose.CLIENT)
          .withParentSpanId(parentSpanId)
          .build();
  // when
  HttpRequestTracingUtils.propagateTracingHeaders(httpObjectForPropagationMock, span);
  // then
  if (parentSpanIdExists) {
    verify(httpObjectForPropagationMock).setHeader(PARENT_SPAN_ID, parentSpanId);
  }
  else {
    verify(httpObjectForPropagationMock, never()).setHeader(eq(PARENT_SPAN_ID), anyString());
  }
}
origin: Nike-Inc/wingtips

@UseDataProvider("idSanitizationScenarios")
@Test
public void convertWingtipsSpanToZipkinSpan_sanitizes_parentSpanId_as_expected_when_sanitization_is_enabled(
  IdSanitizationScenario scenario
) {
  // given
  impl = new WingtipsToZipkinSpanConverterDefaultImpl(true);
  final Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build();
  final Span wingtipsSpan = Span.newBuilder("foo", SpanPurpose.CLIENT)
                 .withParentSpanId(scenario.originalId)
                 .withSpanStartTimeEpochMicros(Math.abs(random.nextLong()))
                 .withDurationNanos(Math.abs(random.nextLong()))
                 .build();
  // when
  zipkin2.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint);
  // then
  assertThat(zipkinSpan.parentId()).isEqualTo(scenario.expectedSanitizedResultForSpanIdOrParentSpanId);
  assertThat(zipkinSpan.tags().get("invalid.parent_id")).isEqualTo(scenario.originalId);
}
origin: Nike-Inc/wingtips

/**
 * @param spanName The {@link Span#getSpanName()} to use for the new child sub-span.
 * @param spanPurpose The {@link SpanPurpose} for the new child span. 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 new uncompleted span representing a child of this instance. The returned instance's {@link #getParentSpanId()} will be this instance's
 *          {@link #getSpanId()}, its {@link #getSpanName()} will be the given value, its {@link #getSpanId()} will be randomly generated, and its
 *          {@link #getSpanStartTimeEpochMicros()} and {@link #getSpanStartTimeNanos()} values will be set to the appropriate values based on when this
 *          method is called. It will share this instance's {@link #getTraceId()}, {@link #isSampleable()}, and {@link #getUserId()} values.
 */
public Span generateChildSpan(String spanName, SpanPurpose spanPurpose) {
  return Span.newBuilder(spanName, spanPurpose)
        .withTraceId(this.getTraceId())
        .withSampleable(this.isSampleable())
        .withUserId(this.getUserId())
        .withParentSpanId(this.getSpanId())
        .withSpanId(TraceAndSpanIdGenerator.generateId())
        .withSpanStartTimeEpochMicros(TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()))
        .withSpanStartTimeNanos(System.nanoTime())
        .withDurationNanos(null)
        .build();
}
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 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);
}
com.nike.wingtipsSpan$BuilderwithParentSpanId

Javadoc

Sets the ID of the span that spawned this span instance (the logical "parent" of this span), or pass in null if no such parent exists. If you pass in null then this instance will be a root span for the distributed trace - the ultimate ancestor of all other spans in the trace tree.

Popular methods of Span$Builder

  • build
    Returns a Span built from the parameters set via the various with*(...) methods on this builder inst
  • 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

  • Reading from database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • getApplicationContext (Context)
  • getSharedPreferences (Context)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • JOptionPane (javax.swing)
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • CodeWhisperer alternatives
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