Small reduction in context lookups (#4006)

This commit is contained in:
Trask Stalnaker 2021-08-30 09:02:52 -07:00 committed by GitHub
parent dc4e239722
commit c91eda59b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -58,8 +58,9 @@ public class Servlet3Advice {
.get((Filter) servletOrFilter); .get((Filter) servletOrFilter);
} }
Context currentContext = Java8BytecodeBridge.currentContext();
Context attachedContext = tracer().getServerContext(httpServletRequest); Context attachedContext = tracer().getServerContext(httpServletRequest);
if (attachedContext != null && tracer().needsRescoping(attachedContext)) { if (attachedContext != null && tracer().needsRescoping(currentContext, attachedContext)) {
attachedContext = attachedContext =
tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet); tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet);
scope = attachedContext.makeCurrent(); scope = attachedContext.makeCurrent();
@ -67,7 +68,6 @@ public class Servlet3Advice {
return; return;
} }
Context currentContext = Java8BytecodeBridge.currentContext();
if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) { if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) {
// Update context with info from current request to ensure that server span gets the best // Update context with info from current request to ensure that server span gets the best
// possible name. // possible name.

View File

@ -58,8 +58,9 @@ public class JakartaServletServiceAdvice {
.get((Filter) servletOrFilter); .get((Filter) servletOrFilter);
} }
Context currentContext = Java8BytecodeBridge.currentContext();
Context attachedContext = tracer().getServerContext(httpServletRequest); Context attachedContext = tracer().getServerContext(httpServletRequest);
if (attachedContext != null && tracer().needsRescoping(attachedContext)) { if (attachedContext != null && tracer().needsRescoping(currentContext, attachedContext)) {
attachedContext = attachedContext =
tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet); tracer().updateContext(attachedContext, httpServletRequest, mappingResolver, servlet);
scope = attachedContext.makeCurrent(); scope = attachedContext.makeCurrent();
@ -67,7 +68,6 @@ public class JakartaServletServiceAdvice {
return; return;
} }
Context currentContext = Java8BytecodeBridge.currentContext();
if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) { if (attachedContext != null || ServerSpan.fromContextOrNull(currentContext) != null) {
// Update context with info from current request to ensure that server span gets the best // Update context with info from current request to ensure that server span gets the best
// possible name. // possible name.

View File

@ -266,8 +266,8 @@ public abstract class ServletHttpServerTracer<REQUEST, RESPONSE>
In this case we have to put the span from the request into current context before continuing. In this case we have to put the span from the request into current context before continuing.
*/ */
public boolean needsRescoping(Context attachedContext) { public boolean needsRescoping(Context currentContext, Context attachedContext) {
return !sameTrace(Span.fromContext(Context.current()), Span.fromContext(attachedContext)); return !sameTrace(Span.fromContext(currentContext), Span.fromContext(attachedContext));
} }
private static boolean sameTrace(Span oneSpan, Span otherSpan) { private static boolean sameTrace(Span oneSpan, Span otherSpan) {