io.opentracing.tag.Tag Java Examples

The following examples show how to use io.opentracing.tag.Tag. 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 File: PeerSpanDecorator.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
private void tagIfMatch(
        final Span span,
        final Class<? extends InetAddress> type, final Tag<String> tag,
        final InetAddress address) {

    if (type.isInstance(address)) {
        span.setTag(tag, address.getHostAddress());
    }
}
 
Example #2
Source File: SpanBuilderShim.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Override
public <T> SpanBuilder withTag(Tag<T> tag, T value) {
  if (value instanceof String) {
    this.withTag(tag.getKey(), (String) value);
  } else if (value instanceof Boolean) {
    this.withTag(tag.getKey(), (Boolean) value);
  } else if (value instanceof Number) {
    this.withTag(tag.getKey(), (Number) value);
  } else {
    this.withTag(tag.getKey(), value.toString());
  }

  return this;
}
 
Example #3
Source File: HonoClientUnitTestHelper.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a mocked OpenTracing SpanBuilder for creating a given Span.
 * <p>
 * All invocations on the mock are stubbed to return the builder by default.
 *
 * @param spanToCreate The object that the <em>start</em> method of the
 *                     returned builder should produce.
 * @return The builder.
 */
@SuppressWarnings("unchecked")
public static SpanBuilder mockSpanBuilder(final Span spanToCreate) {
    final SpanBuilder spanBuilder = mock(SpanBuilder.class, Mockito.RETURNS_SMART_NULLS);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), anyBoolean())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), (String) any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), (Number) any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(any(Tag.class), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(spanToCreate);
    return spanBuilder;
}
 
Example #4
Source File: CacheBasedDeviceConnectionInfoTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets up the fixture.
 */
@SuppressWarnings("unchecked")
@BeforeEach
void setUp(final Vertx vertx, final VertxTestContext testContext) {

    final var cacheManager = new DefaultCacheManager(false);
    cacheManager.defineConfiguration("cache-name", new ConfigurationBuilder()
            .build());
    cache = new EmbeddedCache<>(vertx, cacheManager, "cache-name", "foo", "bar");
    cache.connect().onComplete(testContext.completing());

    final SpanContext spanContext = mock(SpanContext.class);
    span = mock(Span.class);
    when(span.context()).thenReturn(spanContext);
    final Tracer.SpanBuilder spanBuilder = mock(Tracer.SpanBuilder.class, Mockito.RETURNS_SMART_NULLS);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), anyBoolean())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), (String) any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(anyString(), (Number) any())).thenReturn(spanBuilder);
    when(spanBuilder.withTag(any(Tag.class), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    tracer = mock(Tracer.class);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);

    info = new CacheBasedDeviceConnectionInfo(cache, tracer);
}
 
Example #5
Source File: ProxySpanBuilder.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
    final TagInterceptor interceptor = plugins.interceptors().tags();
    final TagListener listener = plugins.listeners().tags();

    interceptor.intercept(tag, value).forEach(pair -> {
        pair.tag(delegate);
        pair.notify(listener, this);
    });

    return this;
}
 
Example #6
Source File: ProxySpan.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> Span setTag(final Tag<T> tag, final T value) {
    final TagInterceptor interceptor = plugins.interceptors().tags();
    final TagListener listener = plugins.listeners().tags();

    interceptor.intercept(tag, value).forEach(pair -> {
        pair.tag(delegate);
        pair.notify(listener, this);
    });

    return this;
}
 
Example #7
Source File: CompositeTagInterceptor.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> Collection<TagPair> intercept(
        final Tag<T> tag, final T value) {

    return interceptors.stream()
            .map(interceptor -> interceptor.intercept(tag, value))
            .flatMap(Collection::stream)
            .collect(toList());
}
 
Example #8
Source File: AutoBaggage.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> void onTag(final Span span, final Tag<T> tag, final T value) {
    if (baggageExists(span)) {
        return;
    }

    if (tagKey.equals(tag.getKey())) {
        span.setBaggageItem(baggageKey, String.valueOf(value));
    }
}
 
Example #9
Source File: HttpSpanTagger.java    From riptide with MIT License 5 votes vote down vote up
static HttpSpanTagger tagging(
        final Tag<String> tag,
        final String name,
        final String... names) {

    return tagging(ImmutableMap.of(tag, Lists.asList(name, names)));
}
 
Example #10
Source File: TagListener.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
default <T> void onTag(
        final Span span,
        final Tag<T> tag,
        final T value) {

    // nothing to do
}
 
Example #11
Source File: TagListener.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
default <T> void onTag(
        final SpanBuilder builder,
        final Tag<T> tag,
        final T value) {

    // nothing to do
}
 
Example #12
Source File: BraveSpanBuilder.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
@Override public <T> BraveSpanBuilder withTag(Tag<T> tag, T value) {
  if (tag == null) throw new NullPointerException("tag == null");
  if (value == null) throw new NullPointerException("value == null");
  if (value instanceof String) return withTag(tag.getKey(), (String) value);
  if (value instanceof Number) return withTag(tag.getKey(), (Number) value);
  if (value instanceof Boolean) return withTag(tag.getKey(), (Boolean) value);
  throw new IllegalArgumentException("tag value not a string, number or boolean: " + value);
}
 
Example #13
Source File: CompositeTagListener.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> void onTag(
        final SpanBuilder builder,
        final Tag<T> tag,
        final T value) {

    listeners.forEach(listener ->
            listener.onTag(builder, tag, value));
}
 
Example #14
Source File: TagPropagation.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> void propagate(
        final Map<Tag<?>, Object> tags,
        final BiConsumer<Tag<T>, T> consumer) {

    tags.forEach((raw, value) -> {
        final Tag<T> tag = (Tag<T>) raw;
        consumer.accept(tag, (T) value);
    });
}
 
Example #15
Source File: TagPropagation.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
    with(tag, value);
    return ForwardingSpanBuilder.super.withTag(tag, value);
}
 
Example #16
Source File: NoopSpan.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
@Override
public <T> NoopSpan setTag(Tag<T> tag, T value) { return this; }
 
Example #17
Source File: ForwardingSpanBuilder.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
default <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
    delegate().withTag(tag, value);
    return this;
}
 
Example #18
Source File: ForwardingSpan.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
default  <T> Span setTag(final Tag<T> tag, final T value) {
    delegate().setTag(tag, value);
    return this;
}
 
Example #19
Source File: Tracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
/** Same as {@link AbstractTag#set(Span, T)}, but for the span being built. */
<T> SpanBuilder withTag(Tag<T> tag, T value);
 
Example #20
Source File: TagPropagation.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
private <T> void with(final Tag<T> tag, final T value) {
    if (keys.contains(tag.getKey())) {
        tags.put(tag, value);
    }
}
 
Example #21
Source File: TagPropagation.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public <T> Span setTag(final Tag<T> tag, final T value) {
    set(tag, value);
    return delegate.setTag(tag, value);
}
 
Example #22
Source File: TagPropagation.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
private <T> void set(final Tag<T> tag, final T value) {
    if (keys.contains(tag.getKey())) {
        tags.put(tag, value);
    }
}
 
Example #23
Source File: CompositeTagListener.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public <T> void onTag(final Span span, final Tag<T> tag, final T value) {
    listeners.forEach(listener ->
            listener.onTag(span, tag, value));
}
 
Example #24
Source File: TagInterceptor.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
static <T> TagPair of(final Tag<T> tag, final T value) {
    return new DefaultTagPair<>(tag, value);
}
 
Example #25
Source File: TagInterceptor.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@CheckReturnValue
default <T> Collection<TagPair> intercept(
        final Tag<T> tag, final T value) {

    return singleton(TagPair.of(tag, value));
}
 
Example #26
Source File: TagListenerTest.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
private static <T> Tag<T> tag(final String key) {
    return argThat(tag -> key.equals(tag.getKey()));
}
 
Example #27
Source File: TagInterceptorTest.java    From opentracing-toolbox with 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"));
}
 
Example #28
Source File: TagInterceptorTest.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public <T> Collection<TagPair> intercept(final Tag<T> tag, final T value) {
    return singletonList(TagPair.of(new IntTag("v"), 1));
}
 
Example #29
Source File: BraveSpan.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public <T> Span setTag(Tag<T> tag, T t) {
  if (t instanceof String) return setTag(tag.getKey(), (String) t);
  if (t instanceof Number) return setTag(tag.getKey(), (Number) t);
  if (t instanceof Boolean) return setTag(tag.getKey(), (Boolean) t);
  throw new IllegalArgumentException("tag value not a string, number or boolean: " + tag);
}
 
Example #30
Source File: BraveSpanBuilder.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public <T> BraveSpanBuilder withTag(Tag<T> tag, T t) {
  if (t instanceof String) return withTag(tag.getKey(), (String) t);
  if (t instanceof Number) return withTag(tag.getKey(), (Number) t);
  if (t instanceof Boolean) return withTag(tag.getKey(), (Boolean) t);
  throw new IllegalArgumentException("tag value not a string, number or boolean: " + tag);
}