Sub topic 12
Diagnosing a running application with loggers, env, mappings, and thread dumps
This chapter assumes you have Actuator on the classpath and know how to expose endpoints with management.endpoints.web.exposure.include. It also assumes you can secure endpoints with Spring Security. Diagnostic endpoints reveal internals, so securing them matters more here than for health or info.
Why diagnostic endpoints need care
The endpoints in this chapter answer questions such as "which log level is active?", "where did this property value come from?", and "why is the app stuck?". They help in an incident. They also expose configuration, routes, and stack traces. Expose them only to trusted callers, ideally on a separate management port.
management:
endpoints:
web:
exposure:
include: health,loggers,env,mappings,beans,threaddump
endpoint:
env:
show-values: when-authorizedSince Spring Boot 3.0, env and configprops mask values by default. The show-values setting controls who sees the real values.
Changing log levels with loggers
GET /actuator/loggers lists every logger with its configured and effective level. Request one logger by name to see just that entry:
curl http://localhost:8080/actuator/loggers/com.example.ordersTo change a level at runtime, send a POST with the new level:
curl -X POST http://localhost:8080/actuator/loggers/com.example.orders \
-H "Content-Type: application/json" \
-d '{"configuredLevel": "DEBUG"}'The change takes effect immediately and needs no restart. It is lost when the application restarts. To reset the logger to its inherited level, post {"configuredLevel": null}.
Finding where a value came from with env
GET /actuator/env shows every property source in order of precedence. Query a single property to see which source supplies the winning value:
curl http://localhost:8080/actuator/env/server.portThe response lists activeProfiles, the propertySources that define the property, and the final property with its source. This is the quickest way to learn why a setting differs between environments. For example, an environment variable may override a value in application.yml.
Seeing request routes with mappings
GET /actuator/mappings lists every request mapping, including the handler method, the HTTP methods, and the URL patterns. Use it when a request returns 404 or reaches the wrong controller. A missing entry means the controller was not scanned or a condition disabled it.
Related endpoints show the application's structure:
| Endpoint | What it shows |
|---|---|
| `beans` | Every bean in the context and its dependencies |
| `conditions` | Which auto-configurations matched and why |
| `configprops` | Bound `@ConfigurationProperties` values |
| `threaddump` | Stack trace of every live thread |
Reading a thread dump
GET /actuator/threaddump returns the state of each thread as JSON. Add the header Accept: text/plain to get the familiar text format that thread-analysis tools read.
curl -H "Accept: text/plain" http://localhost:8080/actuator/threaddumpLook for these patterns:
- Many threads in
BLOCKEDwaiting on the same lock point to contention or a deadlock. - Many request threads in
WAITINGorTIMED_WAITinside a database or HTTP client call suggest a slow dependency or an exhausted connection pool. - A thread pool with all threads busy and none idle explains requests that queue up.
Take two or three dumps a few seconds apart. A thread that appears in the same place in every dump is stuck, not just passing through.
Common errors
- Endpoint returns 404: the id is not in the exposure list.
- Endpoint returns 401 or 403: the security filter chain requires a role you did not send.
- Values show as
******: masking is active. Grant the caller access withshow-values: when-authorized. - Log level resets after a restart: the POST changes memory only. Put lasting changes in
logging.level.*properties.
Exercise
Requests to /orders return 404 in production, but work locally. Which two Actuator endpoints would you check first, and what would you look for in each?
Show answer
Check /actuator/mappings to confirm the /orders handler is registered. If it is missing, check /actuator/conditions or /actuator/env. The cause may be a condition or profile property that disables the controller in production. Use env to see which source sets that property.
Exercise
You set a logger to DEBUG through the loggers endpoint. After a deployment the extra logs are gone. Why, and how do you make the change permanent?
Show answer
The POST changes the level only in the running process's memory, so a restart discards it. Set logging.level.com.example.orders=DEBUG in application properties or an environment variable to keep it.