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

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

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

Span.getTags介绍

暂无

代码示例

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

  1. private Span findSubspan() {
  2. return spanRecorder.completedSpans.stream().filter(
  3. s -> "riposte.ningasynchttpclienthelper".equals(s.getTags().get(WingtipsTags.SPAN_HANDLER))
  4. ).findFirst().orElse(null);
  5. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedSpanHandlerTagValue
  10. ) {
  11. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  12. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  17. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  18. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  19. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedSpanHandlerTagValue
  10. ) {
  11. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  12. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  17. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  18. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  19. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedErrorTagValue,
  10. String expectedSpanHandlerTagValue
  11. ) {
  12. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  17. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  18. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  19. assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
  20. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  21. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedErrorTagValue,
  10. String expectedSpanHandlerTagValue
  11. ) {
  12. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  17. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  18. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  19. assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
  20. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  21. }

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

  1. private void verifySubspanTags(
  2. Span subspan, String expectedFullUrl, String expectedHttpStatusCode, boolean expectError
  3. ) {
  4. assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo("GET");
  5. assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(TestEndpoint.MATCHING_PATH);
  6. assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedFullUrl);
  7. assertThat(subspan.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE)).isEqualTo(expectedHttpStatusCode);
  8. assertThat(subspan.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo("riposte.ningasynchttpclienthelper");
  9. if (expectError) {
  10. assertThat(subspan.getTags().get(KnownZipkinTags.ERROR)).isNotNull();
  11. }
  12. else {
  13. assertThat(subspan.getTags().get(KnownZipkinTags.ERROR)).isNull();
  14. }
  15. // Either there's a status code tag but no error tag, or an error tag but no status code tag. In either
  16. // case we expect 5 tags.
  17. assertThat(subspan.getTags()).hasSize(5);
  18. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedErrorTagValue,
  10. String expectedSpanHandlerTagValue
  11. ) {
  12. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  17. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  18. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  19. assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
  20. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  21. }

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

  1. private void verifySpanNameAndTags(
  2. Span span,
  3. String expectedSpanName,
  4. String expectedHttpMethodTagValue,
  5. String expectedPathTagValue,
  6. String expectedUrlTagValue,
  7. String expectedHttpRouteTagValue,
  8. int expectedStatusCodeTagValue,
  9. String expectedErrorTagValue,
  10. String expectedSpanHandlerTagValue
  11. ) {
  12. assertThat(span.getSpanName()).isEqualTo(expectedSpanName);
  13. assertThat(span.getTags().get(KnownZipkinTags.HTTP_METHOD)).isEqualTo(expectedHttpMethodTagValue);
  14. assertThat(span.getTags().get(KnownZipkinTags.HTTP_PATH)).isEqualTo(expectedPathTagValue);
  15. assertThat(span.getTags().get(KnownZipkinTags.HTTP_URL)).isEqualTo(expectedUrlTagValue);
  16. assertThat(span.getTags().get(KnownZipkinTags.HTTP_ROUTE)).isEqualTo(expectedHttpRouteTagValue);
  17. assertThat(span.getTags().get(KnownZipkinTags.HTTP_STATUS_CODE))
  18. .isEqualTo(String.valueOf(expectedStatusCodeTagValue));
  19. assertThat(span.getTags().get(KnownZipkinTags.ERROR)).isEqualTo(expectedErrorTagValue);
  20. assertThat(span.getTags().get(WingtipsTags.SPAN_HANDLER)).isEqualTo(expectedSpanHandlerTagValue);
  21. }

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

  1. private Span findApacheHttpClientSpanFromCompletedSpans() {
  2. List<Span> httpClientSpans = spanRecorder.completedSpans
  3. .stream()
  4. .filter(s -> "apache.httpclient".equals(s.getTags().get(WingtipsTags.SPAN_HANDLER)))
  5. .collect(Collectors.toList());
  6. assertThat(httpClientSpans)
  7. .withFailMessage(
  8. "Expected to find exactly one Span that came from Apache HttpClient - instead found: "
  9. + httpClientSpans.size()
  10. )
  11. .hasSize(1);
  12. return httpClientSpans.get(0);
  13. }

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

  1. private Span findCompletedSpan(String expectedSpanName, String expectedSpanHandler) {
  2. return spanRecorder.completedSpans
  3. .stream()
  4. .filter(
  5. s -> s.getSpanName().equals(expectedSpanName)
  6. && expectedSpanHandler.equals(s.getTags().get(WingtipsTags.SPAN_HANDLER))
  7. )
  8. .findFirst()
  9. .orElseThrow(
  10. () -> new RuntimeException(
  11. "Unable to find span with expected span name: " + expectedSpanName + " and span handler: "
  12. + expectedSpanHandler
  13. )
  14. );
  15. }

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

  1. private Span findSpringRestTemplateSpanFromCompletedSpans(boolean expectAsync) {
  2. String expectedSpanHandler = (expectAsync) ? "spring.asyncresttemplate" : "spring.resttemplate";
  3. List<Span> restTemplateSpans = spanRecorder.completedSpans
  4. .stream()
  5. .filter(s -> expectedSpanHandler.equals(s.getTags().get(WingtipsTags.SPAN_HANDLER)))
  6. .collect(Collectors.toList());
  7. assertThat(restTemplateSpans)
  8. .withFailMessage(
  9. "Expected to find exactly one Span that came from Spring RestTemplate - instead found: "
  10. + restTemplateSpans.size()
  11. )
  12. .hasSize(1);
  13. return restTemplateSpans.get(0);
  14. }

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

  1. @Test
  2. public void putTag_works_as_expected() {
  3. // given
  4. Span span = Span.newBuilder("foo", SpanPurpose.CLIENT).build();
  5. assertThat(span.getTags()).isEmpty();
  6. String tagKey = "key-" + UUID.randomUUID().toString();
  7. String tagValue = "value-" + UUID.randomUUID().toString();
  8. String otherValue = "othervalue-" + UUID.randomUUID().toString();
  9. // when
  10. span.putTag(tagKey, tagValue);
  11. // then
  12. assertThat(span.getTags()).hasSize(1);
  13. assertThat(span.getTags().get(tagKey)).isEqualTo(tagValue);
  14. // and when
  15. span.putTag(tagKey, otherValue);
  16. // then
  17. assertThat(span.getTags()).hasSize(1);
  18. assertThat(span.getTags().get(tagKey)).isEqualTo(otherValue);
  19. }

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

  1. @Test
  2. public void public_constructor_uses_empty_tags_map_when_tags_argument_is_null() {
  3. // when
  4. Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null);
  5. // then
  6. assertThat(span.getTags())
  7. .isNotNull()
  8. .isEmpty();
  9. }

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

  1. @Test
  2. public void public_constructor_works_as_expected_for_incomplete_span() {
  3. // when
  4. Span span = new Span(
  5. traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
  6. spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
  7. startTimeNanosForFullyCompleteSpan, null, tags, annotations
  8. );
  9. // then
  10. assertThat(span.getTraceId()).isEqualTo(traceId);
  11. assertThat(span.getParentSpanId()).isEqualTo(parentSpanId);
  12. assertThat(span.getSpanId()).isEqualTo(spanId);
  13. assertThat(span.getSpanName()).isEqualTo(spanName);
  14. assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan);
  15. assertThat(span.getUserId()).isEqualTo(userId);
  16. assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan);
  17. assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan);
  18. assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan);
  19. assertThat(span.isCompleted()).isFalse();
  20. assertThat(span.getDurationNanos()).isNull();
  21. assertThat(span.getTags()).isEqualTo(tags);
  22. assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations);
  23. }

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

  1. @Test
  2. public void builder_withTags_does_nothing_if_passed_null() {
  3. // given
  4. Span.Builder builder = Span.newBuilder("foo", SpanPurpose.UNKNOWN);
  5. Map<String, String> tagsMapSpy = spy(new LinkedHashMap<>());
  6. Whitebox.setInternalState(builder, "tags", tagsMapSpy);
  7. // when
  8. Span.Builder resultingBuilder = builder.withTags(null);
  9. // then
  10. assertThat(resultingBuilder).isSameAs(builder);
  11. verifyZeroInteractions(tagsMapSpy);
  12. // and when
  13. Span resultingSpan = resultingBuilder.build();
  14. // then
  15. assertThat(resultingSpan.getTags()).isEmpty();
  16. }

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

  1. @UseDataProvider("escapedAndUnescapedQuotesBeforeKeyOrValueEndScenarioDataProvider")
  2. @Test
  3. public void fromKeyValueString_properly_handles_escaped_quotes_and_unescaped_quotes_preceded_by_backslashes(
  4. EscapedAndUnescapedQuotesBeforeKeyOrValueEndScenario scenario
  5. ) {
  6. // given
  7. Span span = Span.newBuilder("someSpan", SpanPurpose.CLIENT)
  8. .withTag(scenario.unescapedKey, scenario.unescapedValue)
  9. .build();
  10. String keyValueStr = SpanParser.convertSpanToKeyValueFormat(span);
  11. // when
  12. Span result = SpanParser.fromKeyValueString(keyValueStr);
  13. // then
  14. assertThat(result.getTags().get(scenario.unescapedKey)).isEqualTo(scenario.unescapedValue);
  15. }

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

  1. @UseDataProvider("escapedAndUnescapedQuotesBeforeKeyOrValueEndScenarioDataProvider")
  2. @Test
  3. public void fromJSON_properly_handles_escaped_quotes_and_unescaped_quotes_preceded_by_backslashes(
  4. EscapedAndUnescapedQuotesBeforeKeyOrValueEndScenario scenario
  5. ) {
  6. // given
  7. Span span = Span.newBuilder("someSpan", SpanPurpose.CLIENT)
  8. .withTag(scenario.unescapedKey, scenario.unescapedValue)
  9. .withTimestampedAnnotation(
  10. TimestampedAnnotation.forEpochMicros(1234, scenario.unescapedValue)
  11. )
  12. .build();
  13. String json = SpanParser.convertSpanToJSON(span);
  14. // when
  15. Span result = SpanParser.fromJSON(json);
  16. // then
  17. assertThat(result.getTags().get(scenario.unescapedKey)).isEqualTo(scenario.unescapedValue);
  18. assertThat(result.getTimestampedAnnotations().get(0).getValue()).isEqualTo(scenario.unescapedValue);
  19. }

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

  1. @UseDataProvider("tagAndAnnotationScenarioDataProvider")
  2. @Test
  3. public void fromJson_should_function_properly_when_there_are_no_null_values(TagAndAnnotationScenario scenario) {
  4. // given: valid span without any null values, completed (so that end time is not null) and JSON string
  5. // from SpanParser.convertSpanToJSON()
  6. Span validSpan = createFilledOutSpan(true, scenario.tags, scenario.annotations);
  7. assertThat(validSpan).isNotNull();
  8. assertThat(validSpan.getTraceId()).isNotNull();
  9. assertThat(validSpan.getUserId()).isNotNull();
  10. assertThat(validSpan.getParentSpanId()).isNotNull();
  11. assertThat(validSpan.getSpanName()).isNotNull();
  12. assertThat(validSpan.getSpanId()).isNotNull();
  13. assertThat(validSpan.getDurationNanos()).isNotNull();
  14. assertThat(validSpan.isCompleted()).isTrue();
  15. assertThat(validSpan.getSpanPurpose()).isNotNull();
  16. assertThat(validSpan.getTags()).isEqualTo(scenario.tags);
  17. assertThat(validSpan.getTimestampedAnnotations()).isEqualTo(scenario.annotations);
  18. String json = SpanParser.convertSpanToJSON(validSpan);
  19. // when: fromJson is called
  20. Span spanFromJson = SpanParser.fromJSON(json);
  21. // then: the original span and the fromJson() span values should be exactly the same
  22. verifySpanDeepEquals(spanFromJson, validSpan, true);
  23. }

代码示例来源:origin: com.nike.wingtips/wingtips-zipkin

  1. @Override
  2. public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) {
  3. String traceId = wingtipsSpan.getTraceId();
  4. long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros();
  5. long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos());
  6. zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace)
  7. .id(nullSafeLong(wingtipsSpan.getSpanId()))
  8. .name(wingtipsSpan.getSpanName())
  9. .parentId(nullSafeLong(wingtipsSpan.getParentSpanId()))
  10. .timestamp(startEpochMicros)
  11. .traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0)
  12. .traceId(nullSafeLong(traceId))
  13. .duration(durationMicros);
  14. addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint);
  15. addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint);
  16. return builder.build();
  17. }

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

  1. @Override
  2. public zipkin.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint, String localComponentNamespace) {
  3. String traceId = wingtipsSpan.getTraceId();
  4. long startEpochMicros = wingtipsSpan.getSpanStartTimeEpochMicros();
  5. long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos());
  6. zipkin.Span.Builder builder = createNewZipkinSpanBuilderWithSpanPurposeAnnotations(wingtipsSpan, startEpochMicros, durationMicros, zipkinEndpoint, localComponentNamespace)
  7. .id(nullSafeLong(wingtipsSpan.getSpanId()))
  8. .name(wingtipsSpan.getSpanName())
  9. .parentId(nullSafeLong(wingtipsSpan.getParentSpanId()))
  10. .timestamp(startEpochMicros)
  11. .traceIdHigh(traceId.length() == 32 ? nullSafeLong(traceId, 0) : 0)
  12. .traceId(nullSafeLong(traceId))
  13. .duration(durationMicros);
  14. addAllTagsToBuilderAsBinaryAnnotations(builder, wingtipsSpan.getTags(), zipkinEndpoint);
  15. addAllAnnotationsToBuilder(builder, wingtipsSpan.getTimestampedAnnotations(), zipkinEndpoint);
  16. return builder.build();
  17. }

相关文章