本文整理了Java中com.nike.wingtips.Span.isSampleable()
方法的一些代码示例,展示了Span.isSampleable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.isSampleable()
方法的具体详情如下:
包路径:com.nike.wingtips.Span
类名称:Span
方法名:isSampleable
暂无
代码示例来源:origin: Nike-Inc/wingtips
/**
* Notifies all listeners that the given span was sampled using {@link SpanLifecycleListener#spanSampled(Span)}, <b>but only if the span's {@link Span#isSampleable()}
* method returns true!</b> If the span is not sampleable then this method does nothing.
*/
protected void notifyIfSpanSampled(Span span) {
if (span.isSampleable()) {
for (SpanLifecycleListener tll : spanLifecycleListeners) {
tll.spanSampled(span);
}
}
}
代码示例来源:origin: Nike-Inc/wingtips
/**
* Helper method for adding tracing-related request attributes to the given request based on the given span.
*
* @param span The span for the overall request.
* @param request The request object to add tracing-related request attributes to.
*/
protected void addTracingInfoToRequestAttributes(Span span, HttpServletRequest request) {
request.setAttribute(TraceHeaders.TRACE_SAMPLED, span.isSampleable());
request.setAttribute(TraceHeaders.TRACE_ID, span.getTraceId());
request.setAttribute(TraceHeaders.SPAN_ID, span.getSpanId());
request.setAttribute(TraceHeaders.PARENT_SPAN_ID, span.getParentSpanId());
request.setAttribute(TraceHeaders.SPAN_NAME, span.getSpanName());
request.setAttribute(Span.class.getName(), span);
}
代码示例来源:origin: Nike-Inc/wingtips
public EndpointSpanInfoDto(HttpServletRequest request, Span endpoint_execution_span, List<String> userIdHeaderKeys) {
this.parent_span_info = new SpanInfoDto(
request.getHeader(TraceHeaders.TRACE_ID),
request.getHeader(TraceHeaders.SPAN_ID),
request.getHeader(TraceHeaders.PARENT_SPAN_ID),
request.getHeader(TraceHeaders.TRACE_SAMPLED),
HttpSpanFactory.getUserIdFromHttpServletRequest(request, userIdHeaderKeys)
);
this.endpoint_execution_span_info = new SpanInfoDto(
endpoint_execution_span.getTraceId(),
endpoint_execution_span.getSpanId(),
endpoint_execution_span.getParentSpanId(),
String.valueOf(endpoint_execution_span.isSampleable()),
endpoint_execution_span.getUserId()
);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromKeyValueString_returns_null_if_sampleable_field_is_missing() {
// given
Span validSpan = createFilledOutSpan(true);
String validKeyValStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
String invalidKeyValStr = validKeyValStr.replace(
String.format(",%s=\"%s\"",
SpanParser.SAMPLEABLE_FIELD,
String.valueOf(validSpan.isSampleable())
),
""
);
// when
Span result = SpanParser.fromKeyValueString(invalidKeyValStr);
// then
assertThat(result).isNull();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromHttpServletRequest_sets_span_sampleable_to_false_if_trace_sampled_header_is_empty_but_attribute_returns_false() {
// given: request where the header for TRACE_SAMPLED returns null but the attribute returns false
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(" ");
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(false);
// when: creating span from request
Span newSpan = HttpSpanFactory.fromHttpServletRequest(request, USER_ID_HEADER_KEYS);
// then: new span should be disabled
assertThat(newSpan.isSampleable()).isFalse();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromHttpServletRequest_sets_span_sampleable_to_false_if_trace_sampled_header_is_null_but_attribute_returns_false() {
// given: request where the header for TRACE_SAMPLED returns null but the attribute returns false
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(null);
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(false);
// when: creating span from request
Span newSpan = HttpSpanFactory.fromHttpServletRequest(request, USER_ID_HEADER_KEYS);
// then: new span should be disabled
assertThat(newSpan.isSampleable()).isFalse();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromHttpServletRequest_defaults_span_sampleable_value_to_true_if_request_header_and_attribute_is_null() {
// given: request where the request header and attribute for TRACE_SAMPLED returns null
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(null);
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(null);
// when: creating span from request
Span newSpan = HttpSpanFactory.fromHttpServletRequest(request, USER_ID_HEADER_KEYS);
// then: new span should be sampleable
assertThat(newSpan.isSampleable()).isTrue();
}
代码示例来源:origin: Nike-Inc/wingtips
private SpanInfoDto spanInfoDtoFromSpan(Span span) {
return new SpanInfoDto(
span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()),
span.getUserId()
);
}
代码示例来源:origin: Nike-Inc/wingtips
private SpanInfoDto spanInfoDtoFromSpan(Span span) {
return new SpanInfoDto(
span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()),
span.getUserId()
);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void equals_returns_false_and_hashCode_different_if_sampleable_is_different() {
// given
Span fullSpan1 = createFilledOutSpan(true);
Span fullSpan2 = createFilledOutSpan(true);
Whitebox.setInternalState(fullSpan2, "sampleable", !fullSpan1.isSampleable());
// expect
assertThat(fullSpan1.equals(fullSpan2)).isFalse();
assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode());
}
代码示例来源:origin: Nike-Inc/riposte
private void verifyExpectedTracingHeadersReceivedDownstream(
ExtractableResponse response, Span expectedSpan
) {
verifyExpectedTracingHeadersReceivedDownstream(
response, expectedSpan.getTraceId(), expectedSpan.getSpanId(), expectedSpan.getParentSpanId(),
convertSampleableBooleanToExpectedB3Value(expectedSpan.isSampleable())
);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromRequestWithHeaders_sets_sampleable_to_attribute_value_if_sampled_header_is_missing_but_attribute_exists() {
// given: request where the header for TRACE_SAMPLED returns null but the attribute returns false
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(null);
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(false);
// when: creating span from request
Span newSpan = HttpRequestTracingUtils.fromRequestWithHeaders(request, USER_ID_HEADER_KEYS);
// then: new span should be disabled
assertThat(newSpan.isSampleable()).isFalse();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void fromRequestWithHeaders_sets_sampleable_to_attribute_value_if_sampled_header_is_empty_but_attribute_exists() {
// given: request where the header for TRACE_SAMPLED returns null but the attribute returns false
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(" ");
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(false);
// when: creating span from request
Span newSpan = HttpRequestTracingUtils.fromRequestWithHeaders(request, USER_ID_HEADER_KEYS);
// then: new span should be disabled
assertThat(newSpan.isSampleable()).isFalse();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
@UseDataProvider("nullAndEmptyStrings")
public void fromRequestWithHeaders_sets_sampleable_to_true_if_sampled_header_is_null_or_missing_from_both_headers_and_attributes(String nullOrEmptySampledString) {
// given: request where the request header and attribute for TRACE_SAMPLED returns null or empty string
given(request.getHeader(TraceHeaders.TRACE_ID)).willReturn(sampleTraceID);
given(request.getHeader(TraceHeaders.TRACE_SAMPLED)).willReturn(nullOrEmptySampledString);
given(request.getAttribute(TraceHeaders.TRACE_SAMPLED)).willReturn(nullOrEmptySampledString);
// when: creating span from request
Span newSpan = HttpRequestTracingUtils.fromRequestWithHeaders(request, USER_ID_HEADER_KEYS);
// then: new span should be sampleable
assertThat(newSpan.isSampleable()).isTrue();
}
代码示例来源: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(boolean includeUserId) {
Span.Builder spanBuilder = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT);
if (includeUserId) {
spanBuilder.withUserId("user-" + UUID.randomUUID().toString());
}
Span span = spanBuilder.build();
MapBuilder<String, String> headersBuilder = 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()));
if (span.getUserId() != null) {
headersBuilder.put(USER_ID_HEADER_KEY, span.getUserId());
}
return Pair.of(span, headersBuilder.build());
}
代码示例来源: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(boolean includeUserId) {
Span.Builder spanBuilder = Span.newBuilder("upstreamSpan", Span.SpanPurpose.CLIENT);
if (includeUserId) {
spanBuilder.withUserId("user-" + UUID.randomUUID().toString());
}
Span span = spanBuilder.build();
MapBuilder<String, String> headersBuilder = 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()));
if (span.getUserId() != null) {
headersBuilder.put(USER_ID_HEADER_KEY, span.getUserId());
}
return Pair.of(span, headersBuilder.build());
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!