Skip to content

Commit

Permalink
Small reduction in context lookups (#4006)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Aug 30, 2021
1 parent dc4e239 commit c91eda5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ public static void onEnter(
.get((Filter) servletOrFilter);
}

Context currentContext = Java8BytecodeBridge.currentContext();
Context attachedContext = tracer().getServerContext(httpServletRequest);
if (attachedContext != null && tracer().needsRescoping(attachedContext)) {
if (attachedContext != null && tracer().needsRescoping(currentContext, attachedContext)) {
attachedContext =
tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet);
scope = attachedContext.makeCurrent();
// We are inside nested servlet/filter/app-server span, don't create new span
return;
}

Context currentContext = Java8BytecodeBridge.currentContext();
if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) {
// Update context with info from current request to ensure that server span gets the best
// possible name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ public static void onEnter(
.get((Filter) servletOrFilter);
}

Context currentContext = Java8BytecodeBridge.currentContext();
Context attachedContext = tracer().getServerContext(httpServletRequest);
if (attachedContext != null && tracer().needsRescoping(attachedContext)) {
if (attachedContext != null && tracer().needsRescoping(currentContext, attachedContext)) {
attachedContext =
tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet);
scope = attachedContext.makeCurrent();
// We are inside nested servlet/filter/app-server span, don't create new span
return;
}

Context currentContext = Java8BytecodeBridge.currentContext();
if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) {
// Update context with info from current request to ensure that server span gets the best
// possible name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ public void onTimeout(Context context, long timeout) {
In this case we have to put the span from the request into current context before continuing.
*/
public boolean needsRescoping(Context attachedContext) {
return !sameTrace(Span.fromContext(Context.current()), Span.fromContext(attachedContext));
public boolean needsRescoping(Context currentContext, Context attachedContext) {
return !sameTrace(Span.fromContext(currentContext), Span.fromContext(attachedContext));
}

private static boolean sameTrace(Span oneSpan, Span otherSpan) {
Expand Down

0 comments on commit c91eda5

Please sign in to comment.