Skip to content

Commit

Permalink
Rever to using non-defaulted key for TracingContextUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosalberto committed Mar 20, 2020
1 parent 7a3cbeb commit 88fdcbb
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions api/src/main/java/io/opentelemetry/trace/TracingContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@
@Immutable
public final class TracingContextUtils {
private static final Context.Key<Span> CONTEXT_SPAN_KEY =
Context.<Span>keyWithDefault("opentelemetry-trace-span-key", DefaultSpan.getInvalid());

/**
* Returns the {@link Span} from the current {@code Context}, falling back to a default, no-op
* {@link Span}.
*
* @return the {@link Span} from the current {@code Context}.
* @since 0.3.0
*/
public static Span getCurrentSpan() {
return getSpan(Context.current());
}
Context.<Span>key("opentelemetry-trace-span-key");

/**
* Creates a new {@code Context} with the given {@link Span} set.
Expand All @@ -55,6 +44,17 @@ public static Context withSpan(Span span, Context context) {
return context.withValue(CONTEXT_SPAN_KEY, span);
}

/**
* Returns the {@link Span} from the current {@code Context}, falling back to a default, no-op
* {@link Span}.
*
* @return the {@link Span} from the current {@code Context}.
* @since 0.3.0
*/
public static Span getCurrentSpan() {
return getSpan(Context.current());
}

/**
* Returns the {@link Span} from the specified {@code Context}, falling back to a default, no-op
* {@link Span}.
Expand All @@ -64,7 +64,8 @@ public static Context withSpan(Span span, Context context) {
* @since 0.3.0
*/
public static Span getSpan(Context context) {
return CONTEXT_SPAN_KEY.get(context);
Span span = CONTEXT_SPAN_KEY.get(context);
return span == null ? DefaultSpan.getInvalid() : span;
}

/**
Expand All @@ -77,8 +78,7 @@ public static Span getSpan(Context context) {
*/
@Nullable
public static Span getSpanWithoutDefault(Context context) {
Span span = CONTEXT_SPAN_KEY.get(context);
return DefaultSpan.getInvalid().equals(span) ? null : span;
return CONTEXT_SPAN_KEY.get(context);
}

/**
Expand Down

0 comments on commit 88fdcbb

Please sign in to comment.