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 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

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;
}
Expand Down
20 changes: 20 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,20 @@
/*
* 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
}
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,8 @@ 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) {
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
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