Skip to content

Commit e1a9676

Browse files
author
Adrian Cole
committed
unhacks and adds note about thing to do
1 parent 1a6f57e commit e1a9676

File tree

2 files changed

+11
-76
lines changed

2 files changed

+11
-76
lines changed

src/main/java/brave/opentracing/BraveSpanBuilder.java

Lines changed: 10 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,16 @@ public final class BraveSpanBuilder implements Tracer.SpanBuilder {
9090
}
9191

9292
@Override public <T> BraveSpanBuilder withTag(Tag<T> tag, T value) {
93-
new TagSetterHack<>(this, tag, value);
94-
return this;
93+
if (tag == null) throw new NullPointerException("tag == null");
94+
if (value == null) throw new NullPointerException("value == null");
95+
if (value instanceof String) {
96+
return withTag(tag.getKey(), (String) value);
97+
} else if (value instanceof Number) {
98+
return withTag(tag.getKey(), (Number) value);
99+
} else if (value instanceof Boolean) {
100+
return withTag(tag.getKey(), (Boolean) value);
101+
}
102+
throw new IllegalArgumentException("value must be a string, number or boolean");
95103
}
96104

97105
@Override public BraveSpanBuilder withStartTimestamp(long microseconds) {
@@ -173,78 +181,4 @@ public final class BraveSpanBuilder implements Tracer.SpanBuilder {
173181

174182
return result;
175183
}
176-
177-
static class TagSetterHack<T> implements Span {
178-
static final String ERROR_FORMAT = "%s.set(span, %s) should only call Span.setTag";
179-
180-
final Tracer.SpanBuilder delegate;
181-
final Tag<T> tag;
182-
final T value;
183-
184-
TagSetterHack(Tracer.SpanBuilder delegate, Tag<T> tag, T value) {
185-
this.delegate = delegate;
186-
this.tag = tag;
187-
this.value = value;
188-
}
189-
190-
@Override public SpanContext context() {
191-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
192-
}
193-
194-
@Override public Span setTag(String key, String value) {
195-
delegate.withTag(key, value);
196-
return this;
197-
}
198-
199-
@Override public Span setTag(String key, boolean value) {
200-
delegate.withTag(key, value);
201-
return this;
202-
}
203-
204-
@Override public Span setTag(String key, Number value) {
205-
delegate.withTag(key, value);
206-
return this;
207-
}
208-
209-
@Override public <T2> Span setTag(Tag<T2> tag, T2 value) {
210-
delegate.withTag(tag, value);
211-
return this;
212-
}
213-
214-
@Override public Span log(Map<String, ?> fields) {
215-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
216-
}
217-
218-
@Override public Span log(long timestampMicroseconds, Map<String, ?> fields) {
219-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
220-
}
221-
222-
@Override public Span log(String event) {
223-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
224-
}
225-
226-
@Override public Span log(long timestampMicroseconds, String event) {
227-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
228-
}
229-
230-
@Override public Span setBaggageItem(String key, String value) {
231-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
232-
}
233-
234-
@Override public String getBaggageItem(String key) {
235-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
236-
}
237-
238-
@Override public Span setOperationName(String operationName) {
239-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
240-
}
241-
242-
@Override public void finish() {
243-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
244-
}
245-
246-
@Override public void finish(long finishMicros) {
247-
throw new IllegalArgumentException(String.format(ERROR_FORMAT, tag, value));
248-
}
249-
}
250184
}

src/main/java/brave/opentracing/BraveTracer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public static final class Builder {
9292
if (tracing == null) throw new NullPointerException("brave tracing component == null");
9393
this.tracing = tracing;
9494
formatToPropagation.put(Format.Builtin.HTTP_HEADERS, tracing.propagation());
95+
// TODO: TEXT_MAP_INJECT and TEXT_MAP_EXTRACT (not excited about this)
9596
formatToPropagation.put(Format.Builtin.TEXT_MAP, tracing.propagation());
9697
}
9798

0 commit comments

Comments
 (0)