Skip to content

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

@winjaychan

Description

@winjaychan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-javacommunityIssues and PRs created by the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions