Skip to content

Commit

Permalink
Fixed TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
whiskeysierra committed Nov 27, 2019
1 parent 2e2ea91 commit d13de35
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static org.apiguardian.api.API.Status.EXPERIMENTAL;

// TODO doesn't work for tagging of builders...
@API(status = EXPERIMENTAL)
@AllArgsConstructor
public final class AutoBaggage implements TagListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
import lombok.AllArgsConstructor;
import org.apiguardian.api.API;

import java.util.Map;
import java.util.Optional;

import static java.util.Collections.singletonMap;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;

@API(status = EXPERIMENTAL)
@AllArgsConstructor
public final class AutoTagging implements SpanListener, BaggageListener {

private final String baggageKey;
private final String tagKey;
private final Map<String, String> mapping;

public AutoTagging(final String key) {
this(key, key);
}

public AutoTagging(final String baggageKey, final String tagKey) {
this(singletonMap(baggageKey, tagKey));
}

@Override
public void onStarted(final Span span) {
Optional.ofNullable(span.getBaggageItem(baggageKey))
.ifPresent(value -> tag(span, value));
mapping.forEach((baggageKey, tagKey) ->
Optional.ofNullable(span.getBaggageItem(baggageKey))
.ifPresent(value -> span.setTag(tagKey, value)));
}

@Override
Expand All @@ -31,13 +37,8 @@ public void onBaggage(
final String key,
final String value) {

if (baggageKey.equals(key)) {
tag(span, value);
}
}

private void tag(final Span span, final String baggageItem) {
span.setTag(tagKey, baggageItem);
Optional.ofNullable(mapping.get(key))
.ifPresent(tagKey -> span.setTag(tagKey, value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand All @@ -25,11 +26,10 @@
@AllArgsConstructor
public final class TagPropagation implements SpanBuilderInterceptor {

// TODO Set!
private final Collection<String> keys;
private final Set<String> keys;

public TagPropagation(final String... keys) {
this(Arrays.asList(keys));
this(new HashSet<>(Arrays.asList(keys)));
}

@Override
Expand Down Expand Up @@ -64,7 +64,7 @@ private <T> void with(final Tag<T> tag, final T value) {

@Override
public SpanBuilder asChildOf(@Nullable final Span parent) {
runIfPropagating(parent, span ->
ifPropagating(parent, span ->
span.propagateTo(this));

return super.asChildOf(parent);
Expand Down Expand Up @@ -92,13 +92,13 @@ public Span start() {
return span;
}

runIfPropagating(unwrap(active), parent ->
ifPropagating(unwrap(active), parent ->
parent.propagateTo(span));

return span;
}

private void runIfPropagating(
private void ifPropagating(
@Nullable final Span span,
final Consumer<PropagatingSpan> action) {
Optional.ofNullable(span)
Expand Down

0 comments on commit d13de35

Please sign in to comment.