anushkagupta200615-jpg opened a new pull request, #16371:
URL: https://github.com/apache/dubbo/pull/16371
## What is the purpose of the change?
This PR addresses issue #16165 where `MDC.get("traceId")` returns `null` in
Dubbo 3.3.2 logs, preventing trace IDs from propagating to logging patterns
like `%X{traceId}`.
**Root Cause:**
While Dubbo's Micrometer Observation integration successfully captures the
`TraceContext` and injects it into Dubbo's internal `RpcContext`, it did not
explicitly populate the underlying SLF4J `MDC`. Unless a user was running a
strictly configured Spring Boot Actuator environment (which natively registers
Micrometer's `MDCScopeDecorator`), the trace context was lost for loggers on
Dubbo's worker threads.
**Fix:**
- Updated `DubboServerTracingObservationHandler` and
`DubboClientTracingObservationHandler` to explicitly push `traceId` and
`spanId` into `org.slf4j.MDC` during `onScopeOpened()`.
- Implemented `onScopeClosed()` to clean up the MDC state via
`MDC.remove()`, preventing context leaks across reused Dubbo worker threads.
- Wrapped the MDC interactions in a `try-catch(Throwable)` block as a safety
mechanism to prevent `NoClassDefFoundError` crashes in edge cases where a user
excludes `slf4j-api` from their classpath.
## Checklist
- [x] Make sure there is a
[GitHub_issue](https://github.com/apache/dubbo/issues/16165) field for the
change.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction. If the new
feature or significant change is committed, please remember to add sample in
[dubbo samples](https://github.com/apache/dubbo-samples) project.
- [x] Make sure gitHub actions can pass. [Why the workflow is failing and
how to fix it?](../CONTRIBUTING.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]