Skip to content
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

since vesion 1.30, can not get trace.id from MDC #3865

Open
winjaychan opened this issue Nov 8, 2024 · 2 comments
Open

since vesion 1.30, can not get trace.id from MDC #3865

winjaychan opened this issue Nov 8, 2024 · 2 comments
Labels
agent-java community Issues and PRs created by the community

Comments

@winjaychan
Copy link

We kindly ask to post all questions and issues on the Discuss forum first. In addition to awesome, knowledgeable community contributors, core APM developers are on the forums every single day to help you out as well, so your questions will reach a wider audience there. If we confirm that there is a bug, then you can open an issue in this repo.

Describe the bug

since vesion 1.30, can not get trace.id from MDC

Steps to reproduce

@ControllerAdvice
@Slf4j
public class GlobalResponseBodyAdvice implements ResponseBodyAdvice<Object> {
    @Override
    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
        return true;
    }

    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
        log.info("trace.id:{}", MDC.get("trace.id"));
        return body;
    }
}

agent jar: elastic-apm-agent-1.30.1.jar or after this version
call MDC.get("trace.id"), it returns null
Image

agent jar: elastic-apm-agent-1.29.0.jar
call MDC.get("trace.id"), it returns the correct string
Image

Expected behavior

call MDC.get("trace.id"), it should return the correct string.

or how can I get correct string

Debug logs

Click to expand
replace this line with your debug logs
@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage labels Nov 8, 2024
@jackshirazi
Copy link
Contributor

The mechanism you were using was an unsupported internal mechanism used to hold the value prior to 1.30. In 1.30 support for all of the different types of logging systems were centralized in the agent to no longer use the logger MDCs (some didn't even have one), and instead to use an internal agent map. So the trace ID is no longer available from the MDC.

Perhaps using ecs logging is what you want?

@winjaychan
Copy link
Author

The mechanism you were using was an unsupported internal mechanism used to hold the value prior to 1.30. In 1.30 support for all of the different types of logging systems were centralized in the agent to no longer use the logger MDCs (some didn't even have one), and instead to use an internal agent map. So the trace ID is no longer available from the MDC.

Perhaps using ecs logging is what you want?

Is there any api to get the traceid from the internal agent map?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community
Projects
None yet
Development

No branches or pull requests

2 participants