Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Do not use AbstractTag<T> for Span.setTag(), but the actual impls. #317

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions opentracing-api/src/main/java/io/opentracing/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*/
package io.opentracing;

import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.BooleanTag;
import io.opentracing.tag.IntTag;
import io.opentracing.tag.StringTag;
import java.util.Map;

/**
Expand Down Expand Up @@ -45,8 +47,14 @@ public interface Span {
/** Same as {@link #setTag(String, String)}, but for numeric values. */
Span setTag(String key, Number value);

/** Same as {@link #setTag(String, String)}, but with typed value. */
<T> Span setTag(AbstractTag<T> key, T value);
/** Same as {@link #setTag(String, String)}, but using BooleanTag.*/
Span setTag(BooleanTag tag, Boolean value);

/** Same as {@link #setTag(String, String)}, but using IntTag. */
Span setTag(IntTag tag, Integer value);

/** Same as {@link #setTag(String, String)}, but using StringTag. */
Span setTag(StringTag tag, String value);

/**
* Log key:value pairs to the Span with the current walltime timestamp.
Expand Down
18 changes: 15 additions & 3 deletions opentracing-mock/src/main/java/io/opentracing/mock/MockSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import io.opentracing.References;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.BooleanTag;
import io.opentracing.tag.IntTag;
import io.opentracing.tag.StringTag;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -137,8 +139,18 @@ public MockSpan setTag(String key, Number value) {
}

@Override
public <T> Span setTag(AbstractTag<T> key, T value) {
return setObjectTag(key.getKey(), value);
public Span setTag(BooleanTag tag, Boolean value) {
return setObjectTag(tag.getKey(), value);
}

@Override
public Span setTag(IntTag tag, Integer value) {
return setObjectTag(tag.getKey(), value);
}

@Override
public Span setTag(StringTag tag, String value) {
return setObjectTag(tag.getKey(), value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add setValue to the interface you won't need to use object.

}

private synchronized MockSpan setObjectTag(String key, Object value) {
Expand Down
14 changes: 10 additions & 4 deletions opentracing-noop/src/main/java/io/opentracing/noop/NoopSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.BooleanTag;
import io.opentracing.tag.IntTag;
import io.opentracing.tag.StringTag;

import java.util.Map;

Expand Down Expand Up @@ -44,9 +46,13 @@ public void finish(long finishMicros) {}
public NoopSpan setTag(String key, Number value) { return this; }

@Override
public <T> Span setTag(AbstractTag<T> key, T value) {
return this;
}
public Span setTag(BooleanTag tag, Boolean value) { return this; }

@Override
public Span setTag(IntTag tag, Integer value) { return this; }

@Override
public Span setTag(StringTag tag, String value) { return this; }

@Override
public NoopSpan log(Map<String, ?> fields) { return this; }
Expand Down