Java Code Examples for io.opentracing.tag.StringTag

The following examples show how to use io.opentracing.tag.StringTag. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sofa-tracer   Source File: SofaTracerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Method: withTag(String key, String value)
 */
@Test
public void testWithTagForKeyValue() {
    //create
    SofaTracerSpan spanParent = (SofaTracerSpan) this.sofaTracer
        .buildSpan("testWithTagForKeyValue")
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start();
    //tags
    StringTag stringTag = new StringTag("tagkey");
    stringTag.set(spanParent, "tagvalue");
    //tags
    spanParent.setTag("tag1", "value");

    Map<String, String> tagsStr = spanParent.getTagsWithStr();
    //string
    assertTrue("tagsStr : " + tagsStr, tagsStr.keySet().contains("tagkey")
                                       && tagsStr.values().contains("tagvalue"));
    assertTrue(tagsStr.keySet().contains("tag1") && tagsStr.values().contains("value"));
    //bool
    spanParent.setTag("bool", Boolean.TRUE);
    spanParent.setTag("bool1", Boolean.FALSE);
    assertTrue(spanParent.getTagsWithBool().get("bool").equals(Boolean.TRUE));
    assertTrue(spanParent.getTagsWithBool().get("bool1").equals(Boolean.FALSE));
    //number
    spanParent.setTag("num1", new Integer(10));
    spanParent.setTag("num2", 20);
    spanParent.setTag("num3", 2.22);
    assertTrue(spanParent.getTagsWithNumber().get("num1").equals(10));
    assertTrue(spanParent.getTagsWithNumber().get("num2").equals(20));
    assertTrue(spanParent.getTagsWithNumber().get("num3").equals(2.22));
}
 
Example 2
Source Project: opentracing-toolbox   Source File: TagListenerTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldDelegateSpanBuilderTag() {
    final Tracer.SpanBuilder builder = unit.buildSpan("test")
            .withTag(new StringTag("k4"), "v");

    verify(listener).onTag(eq(builder), tag("k4"), eq("v"));
}
 
Example 3
private StringTag buildTag(String tag) {
    if (prefix == null) {
        return new StringTag(tag);
    }
    return new StringTag(prefix + tag);
}
 
Example 4
private StringTag buildTag(String tag) {
    if (prefix == null) {
        return new StringTag(tag);
    }
    return new StringTag(prefix + tag);
}
 
Example 5
Source Project: opentracing-toolbox   Source File: NormalizingSpan.java    License: MIT License 4 votes vote down vote up
@Override
default Span setTag(final String key, final String value) {
    return setTag(new StringTag(key), value);
}
 
Example 6
Source Project: opentracing-toolbox   Source File: NormalizingSpanBuilder.java    License: MIT License 4 votes vote down vote up
@Override
default SpanBuilder withTag(final String key, final String value) {
    return withTag(new StringTag(key), value);
}
 
Example 7
Source Project: opentracing-toolbox   Source File: TagInterceptorTest.java    License: MIT License 4 votes vote down vote up
@Override
public <T> Collection<TagPair> intercept(final Tag<T> tag, final T value) {
    return singleton(TagPair.of(new StringTag("type"), "test"));
}