elastic / elastic/apm-agent-java

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

Open
#3,865 2 comments 0 reactions 0 assignees View on GitHub
agent-java community
Dominant language
Java
Stars
594
Forks
338
Avg merge
1d 13h
Merged PRs (30d)
25

Description

We kindly ask to post all questions and issues on the [Discuss forum](https://discuss.elastic.co/c/apm) 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 {
@Override
public boolean supports(MethodParameter returnType, Class> converterType) {
return true;
}

@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class> 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](https://github.com/user-attachments/assets/c4d7ac18-d960-47b5-b5be-42eebf8c37de)

agent jar: elastic-apm-agent-1.29.0.jar
call MDC.get("trace.id"), it returns the correct string
![Image](https://github.com/user-attachments/assets/b8155258-27fc-4a6e-b632-2eac44d43ccb)

## 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.