Installation
Install as Agent Plugin
Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install spring-observability@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin spring-observability v1.0.0 follows the Agent Plugins spec.
Install with the gh extension
gh skills-hub install spring-observability Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/spring-observability/ Extract the ZIP to .github/skills/ in your repo. The folder name must match spring-observability for Copilot to auto-discover it.
Skill Files (6)
SKILL.md 3.7 KB
---
name: spring-observability
description: 'Add and review observability in Spring Boot 3/4 apps: Actuator exposure and health probes, Micrometer metrics, Observation API, OpenTelemetry tracing and OTLP/Prometheus export, structured logging with correlation ids, and safe use of heapdump/threaddump. Use when instrumenting, monitoring or troubleshooting a Spring Boot service.'
---
# Spring Boot observability
Covers Actuator, Micrometer, the Observation API, tracing, and logging. Details in `references/`. For JDK-level diagnosis (thread dumps, JFR, heap analysis) see the `java-diagnostics` skill; for securing endpoints see `spring-security`.
## Safety rules
- Never read or print secrets (`.env`, credentials, tokens) while inspecting configuration or `/actuator/env`.
- Never expose `heapdump` or `threaddump` over public HTTP. The only exception is a temporary, user-consented window with authentication, TLS and network restriction, removed afterwards (same policy in `java-diagnostics`).
- Never expose `env`, `configprops`, `loggers`, or `shutdown` in production without authentication and network restrictions.
- Pin dependency versions via the Boot BOM; do not add explicit versions for Boot-managed artifacts.
## Detect first
Check the Boot version (3.x or 4.x) and what is already present (`spring-boot-starter-actuator`, `micrometer-registry-*`, tracing/OTel dependencies, `logback-spring.xml`). Boot 4 modularized observability (`spring-boot-micrometer-*`, `spring-boot-opentelemetry`) but starters still bring them in.
## Quick start
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
```yaml
management:
endpoints:
web:
exposure:
include: health,info,prometheus # allow-list, never "*" in production
endpoint:
health:
probes:
enabled: true # /actuator/health/liveness and /readiness
show-details: when-authorized
```
## Topics
- [Actuator, health groups and probes, endpoint exposure](references/actuator.md)
- [Micrometer metrics and Prometheus/OTLP export](references/metrics.md)
- [Observation API and tracing with OpenTelemetry](references/tracing-observation.md)
- [Structured logging and correlation ids](references/logging.md)
- [Heapdump/threaddump caveats and runtime diagnosis](references/dumps-and-diagnostics.md)
## Checklist
- [ ] Only needed endpoints exposed and secured; separate management port if possible.
- [ ] Liveness/readiness probes configured for the platform (Kubernetes); readiness group includes critical dependencies only.
- [ ] Metrics exported to the chosen backend; common tags (`application`, `env`) set; no high-cardinality tags (user ids, URLs with ids).
- [ ] Tracing sampling probability set deliberately (Boot default 10%).
- [ ] Logs carry trace/span ids; JSON structured logs in production.
- [ ] Custom observations/metrics have tests.
## Local runtime insights (optional)
For a local-only developer console (and an opt-in MCP server) that shows a running Spring Boot or Quarkus app's runtime state, see BootUI: https://github.com/jdubois/boot-ui and https://www.julien-dubois.com/boot-ui/. Its agent skill can be installed with `gh skill install jdubois/boot-ui skills/bootui`.
- Ask the user for consent before adding any dependency.
- Use it only in a dev/local profile (for example a Maven/Gradle profile or `developmentOnly` configuration); never ship it to production.
- Follow BootUI's own documentation for coordinates and setup rather than copying them here.
See also: <https://docs.spring.io/spring-boot/reference/actuator/observability.html> and <https://docs.micrometer.io/micrometer/reference/>.
references/
actuator.md 1.9 KB
# Actuator
Dependency: `spring-boot-starter-actuator`.
## Exposure
- Web exposure defaults to `health` only (Boot 3/4). Allow-list explicitly: `management.endpoints.web.exposure.include=health,info,metrics,prometheus`.
- Disable the rest: `management.endpoints.access.default=none` then enable chosen ones (`management.endpoint.<id>.access=read-only`) on Boot 3.4+; older `management.endpoint.<id>.enabled` still works on 3.3 and earlier.
- Move to an internal port: `management.server.port=9090` (and `management.server.address`).
- Secure with Spring Security: see `spring-security` skill, `references/actuator-protection.md` in that skill.
- Info: `management.info.env.enabled=true`, `management.info.git.mode=simple`, `management.info.build` via the build plugin's `build-info` goal.
## Health
```yaml
management:
endpoint:
health:
show-details: when-authorized
roles: ACTUATOR_ADMIN
probes:
enabled: true
group:
readiness:
include: readinessState,db
liveness:
include: livenessState
```
- Probes (`/actuator/health/liveness`, `/readiness`) are enabled automatically on Kubernetes; enabling them elsewhere requires `probes.enabled=true` (Boot 4 enables them by default).
- Liveness must not depend on external systems (a failing DB must not restart the pod). Put DB, broker, etc. only in readiness if at all.
- Custom indicators: implement `HealthIndicator` (or `ReactiveHealthIndicator`); keep checks fast with timeouts.
- Graceful shutdown: `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=30s`.
## Other useful endpoints
`metrics`, `prometheus`, `loggers` (change levels at runtime; protect), `httpexchanges` (needs an `HttpExchangeRepository` bean), `scheduledtasks`, `caches`, `startup` (needs `BufferingApplicationStartup`). Treat `env`, `configprops`, `beans`, `mappings` as sensitive.
dumps-and-diagnostics.md 1.4 KB
# Heapdump, threaddump and runtime diagnosis
## Caveats
- `/actuator/heapdump` returns an HPROF file containing everything in memory: credentials, tokens, personal data. It also pauses the JVM and can be several GB.
- `/actuator/threaddump` reveals class names, thread states and sometimes parameters; it is a reconnaissance aid for attackers.
- Policy (shared with `java-diagnostics`): never expose either over public HTTP. The only exception is a temporary, user-consented window with authentication (admin role), TLS, and network restriction (separate management port, internal only), removed afterwards.
- Treat downloaded dumps as sensitive data; store encrypted, delete after analysis, never attach to public tickets.
- Boot 3.x/4.x can restrict access with `management.endpoint.heapdump.access=none` (Boot 3.4+); on older versions use `enabled=false`.
## Using them safely
```yaml
management:
endpoints:
web:
exposure:
include: health,info,threaddump # heapdump only when needed
endpoint:
threaddump:
access: read-only
```
Pair with a Spring Security chain restricting `EndpointRequest.to("heapdump","threaddump")` to an admin role (see `spring-security`).
## Going deeper
For JDK tools (`jcmd`, `jstack`, `jfr`, `jmap`, Eclipse MAT, JFR recording and analysis), use the `java-diagnostics` skill. Actuator metrics (`jvm.memory.used`, `jvm.gc.pause`, `hikaricp.connections.*`, `executor.*`) usually tell you which tool to reach for.
logging.md 1.7 KB
# Logging
## Structured logging (Boot 3.4+)
Built in; no extra dependency for ECS, Logstash and GELF formats.
```yaml
logging:
structured:
format:
console: ecs # also: logstash, gelf
file: ecs
ecs:
service:
name: orders
version: 1.4.0
environment: prod
```
- Customize JSON with `logging.structured.json.include/exclude/rename/add.*`. For code-based customization, implement `StructuredLoggingJsonMembersCustomizer` and register its fully qualified class name with `logging.structured.json.customizer`, or list the implementation under `org.springframework.boot.logging.structured.StructuredLoggingJsonMembersCustomizer` in `META-INF/spring.factories`. A Spring `@Bean` alone is not discovered: logging initializes before the application context.
- Custom format: implement `StructuredLogFormatter<E>` and set `logging.structured.format.console` to its class name.
- Use plain text locally and JSON in production profiles (`application-prod.yml`).
- Stack trace shaping: `logging.structured.json.stacktrace.*`.
## Correlation ids
- With tracing on the classpath, `traceId` and `spanId` are put in the MDC and appear in the default log pattern and in structured output.
- Without tracing, set a correlation id yourself (servlet filter putting a header value into `MDC`, cleared in `finally`).
- Customize the pattern: `logging.pattern.correlation=[%X{traceId:-},%X{spanId:-}] `; include with `logging.include-application-name`/`logging.include-application-group` (Boot 3.4+).
- Propagate the id to downstream calls (automatic for tracing-enabled clients).
## Practices
- Never log secrets, tokens, passwords, or full personal data.
- Change levels at runtime only via a secured `loggers` endpoint.
metrics.md 2.0 KB
# Micrometer metrics
Boot auto-configures a composite `MeterRegistry` plus a registry for each `micrometer-registry-*` found on the classpath.
## Export
- Prometheus scrape: add `io.micrometer:micrometer-registry-prometheus` (version managed by Boot) and expose `prometheus`. Endpoint: `/actuator/prometheus`.
- OTLP push: `io.micrometer:micrometer-registry-otlp`, then `management.otlp.metrics.export.url=http://collector:4318/v1/metrics`. With Boot 4 `spring-boot-starter-opentelemetry` also provides OTLP export of metrics, traces and logs, check the Boot reference for current properties.
- Disable all exporters in tests: `management.defaults.metrics.export.enabled=false`.
## Common tags
```java
@Bean
MeterRegistryCustomizer<MeterRegistry> commonTags(@Value("${spring.application.name}") String app) {
return r -> r.config().commonTags("application", app);
}
```
(Package: Boot 3.x `org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer`; Boot 4.x `org.springframework.boot.micrometer.metrics.autoconfigure.MeterRegistryCustomizer`.) Alternatively `management.metrics.tags.application=${spring.application.name}`.
## Custom metrics
```java
Counter.builder("orders.created").tag("channel", "web").register(registry).increment();
Timer.builder("orders.processing").publishPercentileHistogram().register(registry).record(() -> process());
Gauge.builder("orders.queue.size", queue, Queue::size).register(registry);
```
- Use `@Timed`/`@Counted` only with the `TimedAspect`/`CountedAspect` beans and AOP present.
- Keep tag cardinality bounded (never user ids, raw URLs, exception messages).
- HTTP server metrics: `http.server.requests` is on by default; enable histograms with `management.metrics.distribution.percentiles-histogram.http.server.requests=true`.
- JVM, DB pool (HikariCP), cache, Kafka and executor metrics are automatic when present.
## Testing
Use `SimpleMeterRegistry` in unit tests, and `@AutoConfigureObservability` (or enable export explicitly) in slices that disable metrics by default.
tracing-observation.md 2.7 KB
# Observation API and tracing
## Observation API
One instrumentation point produces metrics and traces (Micrometer Observation).
```java
@Service
class OrderService {
private final ObservationRegistry registry;
OrderService(ObservationRegistry registry) { this.registry = registry; }
Order place(Order o) {
return Observation.createNotStarted("order.place", registry)
.lowCardinalityKeyValue("channel", o.channel()) // metric + span tag
.highCardinalityKeyValue("order.id", o.id()) // span tag only
.observe(() -> doPlace(o));
}
}
```
Or annotate with `@Observed(name = "order.place")` and register an `ObservedAspect` bean (needs `spring-boot-starter-aop`/AspectJ on the classpath; Boot 4 names it `spring-boot-starter-aspectj`). Customize via `ObservationFilter`, `ObservationPredicate`, and `ObservationConvention` beans.
## Tracing with OpenTelemetry
Boot 3.x (bridge to the OTel SDK):
- `io.micrometer:micrometer-tracing-bridge-otel` and `io.opentelemetry:opentelemetry-exporter-otlp` (versions managed by Boot).
Boot 4.x:
- `org.springframework.boot:spring-boot-starter-opentelemetry` (documented as the OpenTelemetry starter for traces, metrics, logs via OTLP). Zipkin: `spring-boot-starter-zipkin`.
- Modular artifacts exist (`spring-boot-micrometer-tracing-opentelemetry`, `spring-boot-opentelemetry`), but prefer starters. Verify names against your Boot version's reference docs.
```yaml
management:
tracing:
sampling:
probability: 1.0 # default 0.1; use 1.0 only in dev/test
# Boot 3.5:
otlp:
tracing:
endpoint: http://localhost:4318/v1/traces
# Boot 4.0 (replaces the block above):
# opentelemetry:
# tracing:
# export:
# otlp:
# endpoint: http://localhost:4318/v1/traces
spring:
application:
name: orders # becomes service.name
```
- Propagation defaults to W3C `traceparent`; `management.tracing.propagation.type` can add B3.
- Auto-instrumented: Spring MVC/WebFlux and `RestClient`, `RestTemplate`, `WebClient` built from the injected builders. JDBC needs additional instrumentation such as datasource-micrometer.
- Messaging observations require an explicit opt-in. For Kafka, enable both `spring.kafka.template.observation-enabled=true` and `spring.kafka.listener.observation-enabled=true` (both default to false) to create producer/listener spans and propagate tracing context. For RabbitMQ or another messaging technology, check its version-specific template/listener observation settings rather than assuming tracing dependencies enable them.
- Local backends: Zipkin, Jaeger, or Grafana LGTM via Testcontainers/`spring-boot-docker-compose` in dev only.
- Do not put PII or secrets in span attributes.
License (MIT)
View full license text
MIT License Copyright GitHub, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.