-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Boot WebFlux + open-telemetry java agent, use Baggage and makeCurrent() in Filter, traceId is duplicated for many times. #12085
Comments
I was able to reproduce the issue - it was not introduced by #12003 |
@giantoneday After starting the application do only one request. Now if you examine the log file you'll notice that
before request is logged on thread
after request is logged on a different thread
@zeitlinger since the original report mentions that it already does not work in 2.4.0 I find it hard to believe that the PR you singled out could be the culprit as it was merged only in 2.7.0 |
I said it did not introduce it. Looking at the user code, I can't see what's wrong with it. private static class RequestLoggingFilter extends AbstractRequestLoggingFilter {
public RequestLoggingFilter() {
setAfterMessagePrefix("REQUEST: [");
}
@Override
protected void beforeRequest(HttpServletRequest request, String message) {
Baggage baggage = Baggage.builder()
.put(BAGGAGE_USER_ID, String.valueOf(System.currentTimeMillis()))
.build();
Scope scope = baggage.storeInContext(Context.current()).makeCurrent();
request.setAttribute(SCOPE, scope);
print("ReqLogConfig.beforeRequest", true);
}
@Override
protected void afterRequest(HttpServletRequest request, String message) {
//print("ReqLogConfig.afterRequest", false);
log.info("afterRequest: message:[{}] traceId: {}", message, getTraceId(false));
Scope scope = (Scope) request.getAttribute(SCOPE);
if (scope != null) {
log.info("close scope: {} {}", scope.getClass(), scope);
scope.close();
}
print("afterRequest finish", false);
//Span.current().end();
}
} |
Have a look at how if (shouldLog && isFirstRequest) {
this.beforeRequest((HttpServletRequest)requestToUse, this.getBeforeMessage((HttpServletRequest)requestToUse));
}
try {
filterChain.doFilter((ServletRequest)requestToUse, response);
} finally {
if (shouldLog && !this.isAsyncStarted((HttpServletRequest)requestToUse)) {
this.afterRequest((HttpServletRequest)requestToUse, this.getAfterMessage((HttpServletRequest)requestToUse));
}
} The try (Scope ignore = baggage.makeCurrent()) {
filterChain.doFilter(request, response);
} |
@laurit @zeitlinger tks for your reply. I use a plain filter(tomcat level's filter) to fix this problem, tks. |
Describe the bug
Hi,
I use Spring Boot WebFlux + open-telemetry java agent, and add Baggage to the Context, but I found that if I add baggage.storeInContext(Context.current()).makeCurrent() on Filter,
My test project is here: flux-open-telemetry.zip
Uploading flux-open-telemetry.zip…
And please read the README to reproduce my issue. Both opentelemetry-javaagent 2.7.0 or 2.4.0 have the same issues.
Could you please show me how to fix this problem? Because it's important for me.
some similar issues reported by others:
Thanks.
Steps to reproduce
My test project is attached, and please read the README to reproduce my issue.
Could you please show me how to fix this problem? Because it's important for me.
Expected behavior
traceId is not duplicated
Actual behavior
traceId is duplicated
Javaagent or library instrumentation version
2.4.0 or 2.7.0
Environment
JDK: 17
OS: mac/linux
Additional context
No response
The text was updated successfully, but these errors were encountered: