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 all commits
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
6 changes: 3 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,7 @@
*/
package io.opentracing;

import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;
import java.util.Map;

/**
Expand Down Expand Up @@ -45,8 +45,8 @@ 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 with using Tag<T>. */
<T> Span setTag(Tag<T> tag, T value);

/**
* Log key:value pairs to the Span with the current walltime timestamp.
Expand Down
4 changes: 2 additions & 2 deletions opentracing-api/src/main/java/io/opentracing/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.opentracing;

import io.opentracing.propagation.Format;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;

/**
* Tracer is a simple, thin interface for Span creation and propagation across arbitrary transports.
Expand Down Expand Up @@ -175,7 +175,7 @@ interface SpanBuilder {
SpanBuilder withTag(String key, Number value);

/** Same as {@link AbstractTag#set(Span, T)}, but for the span being built. */
<T> SpanBuilder withTag(AbstractTag<T> tag, T value);
<T> SpanBuilder withTag(Tag<T> tag, T value);

/** Specify a timestamp of when the Span was started, represented in microseconds since epoch. */
SpanBuilder withStartTimestamp(long microseconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

import io.opentracing.Span;

public abstract class AbstractTag<T> {
public abstract class AbstractTag<T> implements Tag<T> {
protected final String key;

public AbstractTag(String tagKey) {
this.key = tagKey;
}

@Override
public String getKey() {
return key;
}

protected abstract void set(Span span, T tagValue);
@Override
public abstract void set(Span span, T tagValue);
}
21 changes: 21 additions & 0 deletions opentracing-api/src/main/java/io/opentracing/tag/Tag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2016-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.opentracing.tag;

import io.opentracing.Span;

public interface Tag<T> {
String getKey();
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
void set(Span span, T value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.opentracing.References;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -137,8 +137,9 @@ public MockSpan setTag(String key, Number value) {
}

@Override
public <T> Span setTag(AbstractTag<T> key, T value) {
return setObjectTag(key.getKey(), value);
public <T> MockSpan setTag(Tag<T> tag, T value) {
tag.set(this, value);
return this;
}

private synchronized MockSpan setObjectTag(String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.opentracing.propagation.Binary;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;
import io.opentracing.util.ThreadLocalScopeManager;

/**
Expand Down Expand Up @@ -348,7 +348,7 @@ public SpanBuilder withTag(String key, Number value) {
}

@Override
public <T> Tracer.SpanBuilder withTag(AbstractTag<T> tag, T value) {
public <T> Tracer.SpanBuilder withTag(Tag<T> tag, T value) {
this.initialTags.put(tag.getKey(), value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;

import java.util.Map;

Expand Down Expand Up @@ -44,9 +44,7 @@ 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 <T> NoopSpan setTag(Tag<T> tag, T value) { return this; }

@Override
public NoopSpan log(Map<String, ?> fields) { return this; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.tag.AbstractTag;
import io.opentracing.tag.Tag;

public interface NoopSpanBuilder extends Tracer.SpanBuilder {
NoopSpanBuilder INSTANCE = new NoopSpanBuilderImpl();
Expand Down Expand Up @@ -59,7 +59,7 @@ public Tracer.SpanBuilder withTag(String key, Number value) {
}

@Override
public <T> Tracer.SpanBuilder withTag(AbstractTag<T> key, T value) {
public <T> Tracer.SpanBuilder withTag(Tag<T> key, T value) {
return this;
}

Expand Down