Sub topic 12
Diagnosing a running application with loggers, env, mappings, and thread dumps
This chapter assumes you have Actuator added to a Spring Boot application, know how to expose endpoints with management.endpoints.web.exposure.include, and have a basic idea of how Spring Security protects HTTP paths. It covers the endpoints you use when something is wrong in a running application and you cannot attach a debugger.
Why diagnostic endpoints need care
Diagnostic endpoints show how your application is wired and configured. That helps you, and it helps an attacker. The env endpoint can show configuration values, beans lists every component, heapdump returns process memory, and loggers can change logging at runtime.
Treat these endpoints as operator tools:
- Expose only the ones you need, and only in the environments where you need them.
- Require authentication and a dedicated role.
- Prefer a separate management port that is not reachable from the public internet.
The sections below show each endpoint, what it is for, and its edge cases.
Exposing the diagnostic endpoints
By default, only health is exposed over HTTP in Spring Boot 3. To use the endpoints in this chapter, list them explicitly:
management:
endpoints:
web:
exposure:
include: health,info,loggers,env,mappings,beans,conditions,threaddump,configprops
endpoint:
env:
show-values: when-authorized
configprops:
show-values: when-authorizedThe show-values property controls whether property values appear in the output. Its options are never, always, and when-authorized. The default is never, so values are replaced with ******. With when-authorized, values are shown only to users who pass the endpoint's role check (set with management.endpoint.env.roles). If you do not set roles, any authenticated user counts as authorized.
Actuator also sanitizes keys it recognizes as sensitive, such as names ending in password, secret, or token. Do not rely on this alone. A secret stored under an unusual key name may not be masked.
Changing log levels with loggers
When a bug appears only in production, you often want more logging for one package without a restart. The loggers endpoint does this.
A GET request to /actuator/loggers lists every logger with its configured and effective level. A request to /actuator/loggers/com.example.orders shows one logger:
{
"configuredLevel": null,
"effectiveLevel": "INFO"
}Here configuredLevel is null because no level is set explicitly on that logger. It inherits INFO from a parent, such as the root logger.
To change the level, send a POST request with the new level:
curl -X POST http://localhost:9090/actuator/loggers/com.example.orders \
-H "Content-Type: application/json" \
-d '{"configuredLevel": "DEBUG"}'The endpoint returns 204 No Content on success. To go back to the inherited level, send null:
curl -X POST http://localhost:9090/actuator/loggers/com.example.orders \
-H "Content-Type: application/json" \
-d '{"configuredLevel": null}'Points to remember:
- The change lives in memory. It is lost on restart, and it affects only the instance you called. In a cluster, you must call each instance.
- Changing
ROOTtoDEBUGcan flood your log storage and slow the application. Change the narrowest package that answers your question. - The change is a write operation, so your security rules must not let anonymous users reach it.
- Boot 3.x and later also support logger groups, such as
webandsql. Posting to/actuator/loggers/webchanges all loggers in that group.
Inspecting configuration with env and configprops
Configuration problems are common: the wrong profile is active, an environment variable overrides a file, or a placeholder resolves to an unexpected value. The env endpoint shows the Environment, which is made up of ordered property sources.
GET /actuator/env returns the active profiles and every property source. To find where one property comes from, request it by name:
curl http://localhost:9090/actuator/env/server.portThe response lists the winning value and each property source that defines the property, in precedence order:
{
"property": {
"source": "systemEnvironment",
"value": "******"
},
"activeProfiles": ["prod"],
"propertySources": [
{ "name": "server.ports" },
{ "name": "systemEnvironment",
"property": { "value": "******" } },
{ "name": "applicationConfig: [classpath:/application.yml]",
"property": { "value": "******", "origin": "class path resource [application.yml] - 3:9" } }
]
}The property.source field tells you which source won. The origin field, when present, points to the file and line. This answers questions such as "why is my timeout 5 seconds when the file says 30?" The usual answer is that an environment variable or command-line argument has higher precedence than the file.
The configprops endpoint is related but different. It shows the values bound to your @ConfigurationProperties beans, grouped by prefix. Use env to learn where a raw property comes from. Use configprops to see the final typed values your code actually receives, after relaxed binding and defaults.
Finding request mappings
The mappings endpoint lists every request mapping, which answers "is my controller registered, and what path does it use?" A 404 in production often turns out to be a wrong path prefix or a controller that was never scanned.
curl http://localhost:9090/actuator/mappingsThe response is grouped by context and by dispatcher type. In a servlet application, look under contexts.application.mappings.dispatcherServlets.dispatcherServlet. Each entry shows the handler method and the request conditions:
{
"handler": "com.example.orders.OrderController#find(Long)",
"predicate": "{GET [/orders/{id}], produces [application/json]}"
}Check the HTTP method, the path, and the produces or consumes conditions. A 406 or 415 response often traces back to a mismatch here.
The output is large. Pipe it through jq to filter it:
curl -s http://localhost:9090/actuator/mappings \
| jq '.contexts.application.mappings.dispatcherServlets.dispatcherServlet[]
| select(.details.requestMappingConditions.patterns[]? | startswith("/orders"))
| .predicate'Understanding wiring with beans and conditions
Two more endpoints explain auto-configuration behavior.
beanslists every bean in the application context with its type, scope, and dependencies. Use it to confirm that a bean exists and to see what it depends on.conditionsshows the auto-configuration report. For each auto-configuration class, it lists whether it matched (positiveMatches) or not (negativeMatches), with the reason. If an expectedDataSourceorObjectMapperis missing, this endpoint tells you which@ConditionalOnClassor@ConditionalOnMissingBeancheck failed.
For example, a negativeMatches entry may say that DataSourceAutoConfiguration did not match because a required class was not on the classpath. That points directly to a missing dependency.
Reading thread dumps
When an application hangs, responds slowly, or uses too much CPU, a thread dump shows what every thread is doing at one moment. Request it with:
curl -H "Accept: application/json" http://localhost:9090/actuator/threaddumpThe default response is JSON. Send Accept: text/plain to get the familiar text format that many analysis tools expect.
Each thread entry has a name, a state, and a stack trace. These are the states to look for:
| State | Meaning | What it can indicate |
|---|---|---|
| `RUNNABLE` | Executing or ready to execute | Normal work, or a CPU-heavy loop if many threads sit in the same method |
| `BLOCKED` | Waiting for a monitor lock held by another thread | Lock contention or a deadlock |
| `WAITING` | Waiting indefinitely, for example on `Object.wait` or `LockSupport.park` | Idle pool threads (normal) or a missing signal |
| `TIMED_WAITING` | Waiting with a timeout, such as `sleep` | Idle pools, polling, or slow downstream calls |
A practical routine:
- Take a dump, wait ten seconds, then take a second one. One dump is a snapshot. Two dumps show which threads are stuck and which are only passing through.
- Look for many threads with the same stack trace. Fifty request threads waiting in
HikariPool.getConnectionmeans the connection pool is exhausted. - Look for
BLOCKEDthreads, and check thelockOwnerNamefield to find the thread that holds the lock. - Check the
lockedMonitorsandlockedSynchronizersentries to follow a chain of waits.
In a JVM with virtual threads enabled, the Actuator thread dump covers platform threads. Use jcmd <pid> Thread.dump_to_file -format=json <file> when you need virtual threads as well.
Heap dumps and other endpoints
The heapdump endpoint returns an HPROF file with the full contents of the JVM heap. It is the right tool for memory leaks, and also the most dangerous endpoint, because it contains every object in memory, including credentials and user data. Expose it only when you need it, restrict it to an administrative role, and delete the files after analysis.
Other endpoints worth knowing:
| Endpoint | Purpose |
|---|---|
| `scheduledtasks` | Lists `@Scheduled` tasks and their intervals |
| `caches` | Lists caches and lets you clear them with `DELETE` |
| `httpexchanges` | Shows recent requests, only if you define an `HttpExchangeRepository` bean |
| `sbom` | Shows the software bill of materials when one is packaged |
| `startup` | Shows startup steps when `BufferingApplicationStartup` is configured |
Securing the diagnostic set
Combine the exposure list with a security rule. The filter chain below leaves health open, which monitoring systems often need, and restricts the rest to an operator role:
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class DiagnosticSecurityConfig {
@Bean
SecurityFilterChain diagnosticSecurity(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(auth -> auth
.requestMatchers(EndpointRequest.to("health")).permitAll()
.requestMatchers(HttpMethod.POST, "/actuator/loggers/**").hasRole("OPERATOR")
.requestMatchers(EndpointRequest.to("heapdump")).hasRole("ADMIN")
.anyRequest().hasRole("OPERATOR"))
.httpBasic(Customizer.withDefaults())
.csrf(csrf -> csrf.ignoringRequestMatchers(EndpointRequest.toAnyEndpoint()));
return http.build();
}
}The csrf line matters. Spring Security enables CSRF protection by default, which rejects POST requests without a token. A command-line client using HTTP Basic does not send one, so the loggers change would fail with 403. Disabling CSRF only for Actuator paths is acceptable when the endpoints use HTTP Basic, not browser sessions.
A diagnostic workflow
The diagram shows how the endpoints fit together when you investigate a symptom.
Common mistakes
- Leaving
show-valuesatalways. This exposes secrets to anyone who can reach the endpoint. - Forgetting that logger changes are per instance. A load balancer may send your next request to another instance, which still logs at the old level.
- Reading a single thread dump. One snapshot cannot distinguish a stuck thread from a busy one.
- Exposing diagnostic endpoints on the application port. A separate management port keeps them off public routes, and you can then block that port at the network level.
- Assuming
envshows the effective value of a typed property. Useconfigpropsfor the bound result.
Exercise
A request to /orders/42 returns 404 in production, but works locally. Which endpoint do you check first, and what do you look for? Then, a different problem: your service has a timeout property that you set to 30s in application.yml, but the application behaves as if it were 5s. Which endpoint do you use, and which field in the response explains the difference?
Show answer
For the 404, check /actuator/mappings and look for a handler whose predicate matches GET /orders/{id}. If it is missing, the controller was not registered, or a context path or prefix changed the real URL. For the timeout, call /actuator/env/<property name>. The property.source field shows which property source won, and the propertySources list shows every source that defines it. A higher-precedence source, such as an environment variable or command-line argument, is probably overriding the file value. The origin field points to the file and line when the value comes from a file.
Exercise
You post {"configuredLevel": "DEBUG"} to /actuator/loggers/com.example.billing on one of three instances, and the debug logs do not appear for the request you send next. Give two likely reasons.
Show answer
The next request may have been routed by the load balancer to a different instance, because logger changes affect only the instance that received the POST. Also, the logger name may not match the package that produces the logs, or the application may have restarted, since the change is kept in memory and is lost on restart. You can confirm the current level with GET /actuator/loggers/com.example.billing on each instance.