本文整理了Java中com.nike.wingtips.Span.getTags()
方法的一些代码示例,展示了Span.getTags()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.getTags()
方法的具体详情如下:
包路径:com.nike.wingtips.Span
类名称:Span
方法名:getTags
暂无
代码示例来源:origin: Nike-Inc/riposte
private Span findSubspan() {
return spanRecorder.completedSpans.stream().filter(
s -> "riposte.ningasynchttpclienthelper".equals(s.getTags().get(WingtipsTags.SPAN_HANDLER))
).findFirst().orElse(null);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedErrorTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedErrorTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/riposte
private void verifySubspanTags(
Span subspan, String expectedFullUrl, String expectedHttpStatusCode, boolean expectError
) {
assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo("GET");
assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(TestEndpoint.MATCHING_PATH);
assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedFullUrl);
assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE)).isEqualTo(expectedHttpStatusCode);
assertThat(subspan.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo("riposte.ningasynchttpclienthelper");
if (expectError) {
assertThat(subspan.getTags().get(KnownZipkinTags.ERROR)).isNotNull();
}
else {
assertThat(subspan.getTags().get(KnownZipkinTags.ERROR)).isNull();
}
// Either there's a status code tag but no error tag, or an error tag but no status code tag. In either
// case we expect 5 tags.
assertThat(subspan.getTags()).hasSize(5);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedErrorTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanNameAndTags(
Span span,
String expectedSpanName,
String expectedHttpMethodTagValue,
String expectedPathTagValue,
String expectedUrlTagValue,
String expectedHttpRouteTagValue,
int expectedStatusCodeTagValue,
String expectedErrorTagValue,
String expectedSpanHandlerTagValue
) {
assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
.isEqualTo(String.valueOf(expectedStatusCodeTagValue));
assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
}
代码示例来源:origin: Nike-Inc/wingtips
private Span findApacheHttpClientSpanFromCompletedSpans() {
List<Span> httpClientSpans = spanRecorder.completedSpans
.stream()
.filter(s -> "apache.httpclient".equals(s.getTags().get(WingtipsTags.SPAN_HANDLER)))
.collect(Collectors.toList());
assertThat(httpClientSpans)
.withFailMessage(
"Expected to find exactly one Span that came from Apache HttpClient - instead found: "
+ httpClientSpans.size()
)
.hasSize(1);
return httpClientSpans.get(0);
}
代码示例来源:origin: Nike-Inc/riposte
private Span findCompletedSpan(String expectedSpanName, String expectedSpanHandler) {
return spanRecorder.completedSpans
.stream()
.filter(
s -> s.getSpanName().equals(expectedSpanName)
&& expectedSpanHandler.equals(s.getTags().get(WingtipsTags.SPAN_HANDLER))
)
.findFirst()
.orElseThrow(
() -> new RuntimeException(
"Unable to find span with expected span name: " + expectedSpanName + " and span handler: "
+ expectedSpanHandler
)
);
}
代码示例来源:origin: Nike-Inc/wingtips
private Span findSpringRestTemplateSpanFromCompletedSpans(boolean expectAsync) {
String expectedSpanHandler = (expectAsync) ? "spring.asyncresttemplate" : "spring.resttemplate";
List<Span> restTemplateSpans = spanRecorder.completedSpans
.stream()
.filter(s -> expectedSpanHandler.equals(s.getTags().get(WingtipsTags.SPAN_HANDLER)))
.collect(Collectors.toList());
assertThat(restTemplateSpans)
.withFailMessage(
"Expected to find exactly one Span that came from Spring RestTemplate - instead found: "
+ restTemplateSpans.size()
)
.hasSize(1);
return restTemplateSpans.get(0);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void putTag_works_as_expected() {
// given
Span span = Span.newBuilder("foo", SpanPurpose.CLIENT).build();
assertThat(span.getTags()).isEmpty();
String tagKey = "key-" + UUID.randomUUID().toString();
String tagValue = "value-" + UUID.randomUUID().toString();
String otherValue = "othervalue-" + UUID.randomUUID().toString();
// when
span.putTag(tagKey, tagValue);
// then
assertThat(span.getTags()).hasSize(1);
assertThat(span.getTags().get(tagKey)).isEqualTo(tagValue);
// and when
span.putTag(tagKey, otherValue);
// then
assertThat(span.getTags()).hasSize(1);
assertThat(span.getTags().get(tagKey)).isEqualTo(otherValue);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_uses_empty_tags_map_when_tags_argument_is_null() {
// when
Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null);
// then
assertThat(span.getTags())
.isNotNull()
.isEmpty();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_works_as_expected_for_incomplete_span() {
// when
Span span = new Span(
traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
startTimeNanosForFullyCompleteSpan, null, tags, annotations
);
// then
assertThat(span.getTraceId()).isEqualTo(traceId);
assertThat(span.getParentSpanId()).isEqualTo(parentSpanId);
assertThat(span.getSpanId()).isEqualTo(spanId);
assertThat(span.getSpanName()).isEqualTo(spanName);
assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan);
assertThat(span.getUserId()).isEqualTo(userId);
assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan);
assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan);
assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan);
assertThat(span.isCompleted()).isFalse();
assertThat(span.getDurationNanos()).isNull();
assertThat(span.getTags()).isEqualTo(tags);
assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void builder_withTags_does_nothing_if_passed_null() {
// given
Span.Builder builder = Span.newBuilder("foo", SpanPurpose.UNKNOWN);
Map<String, String> tagsMapSpy = spy(new LinkedHashMap<>());
Whitebox.setInternalState(builder, "tags", tagsMapSpy);
// when
Span.Builder resultingBuilder = builder.withTags(null);
// then
assertThat(resultingBuilder).isSameAs(builder);
verifyZeroInteractions(tagsMapSpy);
// and when
Span resultingSpan = resultingBuilder.build();
// then
assertThat(resultingSpan.getTags()).isEmpty();
}
代码示例来源:origin: Nike-Inc/wingtips
@UseDataProvider("escapedAndUnescapedQuotesBeforeKeyOrValueEndScenarioDataProvider")
@Test
public void fromKeyValueString_properly_handles_escaped_quotes_and_unescaped_quotes_preceded_by_backslashes(
EscapedAndUnescapedQuotesBeforeKeyOrValueEndScenario scenario
) {
// given
Span span = Span.newBuilder("someSpan", SpanPurpose.CLIENT)
.withTag(scenario.unescapedKey, scenario.unescapedValue)
.build();
String keyValueStr = SpanParser.convertSpanToKeyValueFormat(span);
// when
Span result = SpanParser.fromKeyValueString(keyValueStr);
// then
assertThat(result.getTags().get(scenario.unescapedKey)).isEqualTo(scenario.unescapedValue);
}
代码示例来源:origin: Nike-Inc/wingtips
@UseDataProvider("escapedAndUnescapedQuotesBeforeKeyOrValueEndScenarioDataProvider")
@Test
public void fromJSON_properly_handles_escaped_quotes_and_unescaped_quotes_preceded_by_backslashes(
EscapedAndUnescapedQuotesBeforeKeyOrValueEndScenario scenario
) {
// given
Span span = Span.newBuilder("someSpan", SpanPurpose.CLIENT)
.withTag(scenario.unescapedKey, scenario.unescapedValue)
.withTimestampedAnnotation(
TimestampedAnnotation.forEpochMicros(1234, scenario.unescapedValue)
)
.build();
String json = SpanParser.convertSpanToJSON(span);
// when
Span result = SpanParser.fromJSON(json);
// then
assertThat(result.getTags().get(scenario.unescapedKey)).isEqualTo(scenario.unescapedValue);
assertThat(result.getTimestampedAnnotations().get(0).getValue()).isEqualTo(scenario.unescapedValue);
}
代码示例来源:origin: Nike-Inc/wingtips
@UseDataProvider("tagAndAnnotationScenarioDataProvider")
@Test
public void fromJson_should_function_properly_when_there_are_no_null_values(TagAndAnnotationScenario scenario) {
// given: valid span without any null values, completed (so that end time is not null) and JSON string
// from SpanParser.convertSpanToJSON()
Span validSpan = createFilledOutSpan(true, scenario.tags, scenario.annotations);
assertThat(validSpan).isNotNull();
assertThat(validSpan.getTraceId()).isNotNull();
assertThat(validSpan.getUserId()).isNotNull();
assertThat(validSpan.getParentSpanId()).isNotNull();
assertThat(validSpan.getSpanName()).isNotNull();
assertThat(validSpan.getSpanId()).isNotNull();
assertThat(validSpan.getDurationNanos()).isNotNull();
assertThat(validSpan.isCompleted()).isTrue();
assertThat(validSpan.getSpanPurpose()).isNotNull();
assertThat(validSpan.getTags()).isEqualTo(scenario.tags);
assertThat(validSpan.getTimestampedAnnotations()).isEqualTo(scenario.annotations);
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: com.nike.wingtips/wingtips-zipkin
@Override
public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) {
String traceId = wingtipsSpan.getTraceId();
long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros();
long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos());
zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace)
.id(nullSafeLong(wingtipsSpan.getSpanId()))
.name(wingtipsSpan.getSpanName())
.parentId(nullSafeLong(wingtipsSpan.getParentSpanId()))
.timestamp(startEpochMicros)
.traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0)
.traceId(nullSafeLong(traceId))
.duration(durationMicros);
addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint);
addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint);
return builder.build();
}
代码示例来源:origin: Nike-Inc/wingtips
@Override
public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) {
String traceId = wingtipsSpan.getTraceId();
long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros();
long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos());
zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace)
.id(nullSafeLong(wingtipsSpan.getSpanId()))
.name(wingtipsSpan.getSpanName())
.parentId(nullSafeLong(wingtipsSpan.getParentSpanId()))
.timestamp(startEpochMicros)
.traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0)
.traceId(nullSafeLong(traceId))
.duration(durationMicros);
addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint);
addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint);
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!