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

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

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

Span.putTag介绍

[英]Tags are expressed as key/value pairs. A call to this method will add the key/value pair if it exists or replaces the current value if one exists for the respective key.

NOTE: If you're integrating with a system that understands Zipkin tags, see com.nike.wingtips.tags.KnownZipkinTags for common tag key/value pairs that have special meaning that you might want to take advantage of. Similarly, if you're integrating with a system that understands OpenTracing tags, see com.nike.wingtips.tags.KnownOpenTracingTags.
[中]标记表示为键/值对。对该方法的调用将添加键/值对(如果存在),或替换当前值(如果存在)。
注意:如果您正在与一个理解Zipkin标签的系统集成,请参阅com。耐克。翼尖。标签。KnownZipkinTags用于常见的标记键/值对,这些标记具有您可能想要利用的特殊含义。类似地,如果要与理解OpenTracing标记的系统集成,请参阅com。耐克。翼尖。标签。不知道诱捕。

代码示例

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

/**
 * A helper method that can be used by subclasses for putting a tag value on the given span (via {@link
 * Span#putTag(String, String)}) if and only if the tag value is not null and its {@link Object#toString()} is not
 * blank (according to {@link StringUtils#isBlank(CharSequence)}).
 *
 * @param span The span to tag - should never be null.
 * @param tagKey The key to use when calling {@link Span#putTag(String, String)} - should never be null.
 * @param tagValue The tag value to use if and only if it is not null and its {@link Object#toString()} is not
 * blank.
 */
protected void putTagIfValueIsNotBlank(
  @NotNull Span span,
  @NotNull String tagKey,
  @Nullable Object tagValue
) {
  //noinspection ConstantConditions
  if (tagValue == null || span == null || tagKey == null) {
    return;
  }
  // tagValue is not null. Convert to string and check for blank.
  String tagValueString = tagValue.toString();
  if (StringUtils.isBlank(tagValueString)) {
    return;
  }
  // tagValue is not blank. Add it to the given span.
  span.putTag(tagKey, tagValueString);
}

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

@Override
  protected void doHandleResponseAndErrorTagging(
    @NotNull Span span,
    @Nullable REQ request,
    @Nullable RES response,
    @Nullable Throwable error,
    @NotNull HttpTagAndSpanNamingAdapter<REQ, RES> adapter
  ) {
    putTagIfValueIsNotBlank(span, KnownOpenTracingTags.HTTP_STATUS, adapter.getResponseHttpStatus(response));

    if (error != null || StringUtils.isNotBlank(adapter.getErrorResponseTagValue(response))) {
      // OpenTracing doesn't expect you to pass messages with the error tag, just error=true.
      //      So we don't need to do anything with the given error Throwable or returned
      //      getErrorResponseTagValue(), other than have them trigger adding the error=true tag.
      span.putTag(KnownOpenTracingTags.ERROR, "true");
    }
  }
}

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

@Test
public void putTagIfValueIsNotBlank_calls_span_putTag_as_expected_for_tagValue_toString_when_result_is_not_blank() {
  // given
  Object tagValueMock = mock(Object.class);
  String tagValueToStringResult = "tag_value-" + UUID.randomUUID().toString();
  doReturn(tagValueToStringResult).when(tagValueMock).toString();
  String tagKey = "tag_key-" + UUID.randomUUID().toString();
  // when
  implSpy.putTagIfValueIsNotBlank(spanMock, tagKey, tagValueMock);
  // then
  verify(spanMock).putTag(tagKey, tagValueToStringResult);
}

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

@DataProvider(value = {
  "null",
  "",
  "[whitespace]"
}, splitBy = "\\|")
@Test
public void putTagIfValueIsNotBlank_does_nothing_when_tagValue_toString_IS_blank(
  String blankTagValueToStringResult
) {
  // given
  if ("[whitespace]".equals(blankTagValueToStringResult)) {
    blankTagValueToStringResult = "   \n\r\t   ";
  }
  Object tagValueMock = mock(Object.class);
  doReturn(blankTagValueToStringResult).when(tagValueMock).toString();
  String tagKey = "tag_key-" + UUID.randomUUID().toString();
  // when
  implSpy.putTagIfValueIsNotBlank(spanMock, tagKey, tagValueMock);
  // then
  verify(spanMock, never()).putTag(anyString(), anyString());
}

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

@DataProvider(value = {
  "true   |   false   |   false",
  "false  |   true    |   false",
  "false  |   false   |   true"
}, splitBy = "\\|")
@Test
public void putTagIfValueIsNotBlank_does_nothing_when_any_arg_is_null(
  boolean spanIsNull, boolean tagKeyIsNull, boolean tagValueIsNull
) {
  // given
  Span span = (spanIsNull) ? null : spanMock;
  String tagKey = (tagKeyIsNull) ? null : UUID.randomUUID().toString();
  String tagValue = (tagValueIsNull) ? null : UUID.randomUUID().toString();
  // when
  implSpy.putTagIfValueIsNotBlank(span, tagKey, tagValue);
  // then
  verify(spanMock, never()).putTag(anyString(), anyString());
}

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

@Test
public void doExtraWingtipsTagging_adds_SPAN_HANDLER_tag_if_adapter_getSpanHandlerTagValue_is_not_blank() {
  // given
  String adapterSpanHandlerTagValue = UUID.randomUUID().toString();
  doReturn(adapterSpanHandlerTagValue).when(adapterMock).getSpanHandlerTagValue(anyObject(), anyObject());
  // when
  implSpy.doExtraWingtipsTagging(spanMock, requestObjectMock, responseObjectMock, errorMock, adapterMock);
  // then
  verify(implSpy).putTagIfValueIsNotBlank(spanMock, WingtipsTags.SPAN_HANDLER, adapterSpanHandlerTagValue);
  verify(spanMock).putTag(WingtipsTags.SPAN_HANDLER, adapterSpanHandlerTagValue);
  verifyNoMoreInteractions(spanMock);
}

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

@Test
public void equals_returns_false_and_hashCode_different_if_tags_are_different() {
  // given
  Span fullSpan1 = createFilledOutSpan(true);
  Span fullSpan2 = createFilledOutSpan(true);
  fullSpan1.putTag("key-" + UUID.randomUUID().toString(), UUID.randomUUID().toString());
  // expect
  assertThat(fullSpan1.equals(fullSpan2)).isFalse();
  assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode());
}

代码示例来源: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

verify(spanMock).putTag(KnownOpenTracingTags.ERROR, "true");

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

subspan.putTag(KnownZipkinTags.HTTP_HOST, downstreamHost + ":" + downstreamPort);

代码示例来源:origin: com.nike.riposte/riposte-core

subspan.putTag(KnownZipkinTags.HTTP_HOST, downstreamHost + ":" + downstreamPort);

相关文章