Skip to main content

Claude/ChatGPT Prompt to Add Full Observability to a Spring Boot App

Wire metrics, traces, and correlated logs into a Spring Boot 3 service with Micrometer, OpenTelemetry, Prometheus, and Tempo.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a senior Java platform engineer. Return working, copy-ready config and code, not pseudocode.

Context:
- App: orders-api (Spring Boot 3, Java 21)
- Metrics backend: Prometheus
- Trace backend: Grafana Tempo
- Log backend: Loki

Deliverables:
1. application.yaml enabling Micrometer metrics with Prometheus registry and useful tags (service, env, version).
2. OpenTelemetry tracing config exporting spans to the trace backend, with sampling guidance for prod.
3. Structured JSON logging that injects traceId and spanId into every line so logs join traces.
4. A sample instrumented @RestController showing a custom Timer/Counter and a manually started span.
5. Wiring to export metrics, traces, and logs to the chosen backends (or SaaS equivalent).
6. A short dashboard/alert starter list: latency p95, error rate, JVM heap.

Return the full application.yaml plus the annotated controller and any dependency snippets.

What this prompt does

This prompt makes the model wire full observability into a Spring Boot 3 service, returning copy-ready config and code rather than pseudocode. It covers all three pillars — metrics, traces, and logs — and, most importantly, correlates them so a log line carries the trace and span IDs that join it to the matching trace. That correlation is the single biggest debugging win when the first incident hits and you need to pivot from a log entry to the full request.

The [app_name] variable tags the service across all telemetry. [metrics_backend] is where Micrometer metrics are scraped or stored, [trace_backend] is where OpenTelemetry spans are exported, and [log_backend] is where structured logs ship. Naming each one lets the model wire the right exporters and registries instead of a generic setup. The output enables Prometheus metrics with useful tags, OTel tracing with sampling guidance, JSON logging that injects traceId and spanId, and a sample instrumented controller showing a custom Timer or Counter and a manually started span.

When to use it

  • Standing up a new Spring Boot 3 service that needs metrics, traces, and logs from the start.
  • Adding correlated logs-to-traces so you can jump from a log line to its trace.
  • Configuring Micrometer with a Prometheus registry and consistent service/env/version tags.
  • Wiring OpenTelemetry span export with sane production sampling.
  • Bootstrapping starter dashboards and alerts for latency p95, error rate, and JVM heap.
  • Instrumenting a hot endpoint with a custom metric and a manual span.

Example output

You get the full application.yaml plus an annotated controller and any dependency snippets. The yaml enables Micrometer metrics with a Prometheus registry and tags for service, env, and version; configures OTel tracing exporting to [trace_backend] with prod sampling guidance; and sets up structured JSON logging injecting traceId and spanId into every line. The sample @RestController shows a custom Timer/Counter and a manually started span. A short dashboard/alert starter list covering p95 latency, error rate, and heap rounds it out. It's a runnable observability setup, not fragments.

Pro tips

  • Never skip the correlated logging (deliverable 3) — joining logs to traces via traceId/spanId is the single biggest debugging win when an incident hits.
  • Set sampling low in production or the trace volume — and bill — quietly explodes; the prompt's sampling guidance is there for a reason.
  • Name [trace_backend], [metrics_backend], and [log_backend] precisely so the exporters target the right systems instead of placeholders.
  • Keep the service/env/version tags consistent across services so dashboards can filter and compare cleanly.
  • Use a clear [app_name] since it tags every metric, trace, and log line and becomes your primary filter dimension.
  • Start from the suggested p95-latency, error-rate, and heap alerts rather than inventing dashboards from scratch.

Frequently Asked Questions

Does it correlate logs with traces?
Yes, and that is the emphasis. Structured JSON logging injects traceId and spanId into every log line so logs join their corresponding traces. The prompt calls this the single biggest debugging win, because it lets you pivot from a log entry straight to the full request trace.
How should I set trace sampling for production?
The prompt includes sampling guidance and recommends keeping it low in production. High sampling generates large trace volumes that drive up storage and cost, so most services sample a small fraction of requests while still capturing enough traces to debug incidents.
Which backends does it support?
It targets whatever you name in `[metrics_backend]`, `[trace_backend]`, and `[log_backend]`, such as Prometheus for metrics, Tempo for traces, and Loki for logs. Setting these precisely ensures the generated exporters point at your real systems rather than placeholder configuration.
Does it include ready-made dashboards and alerts?
It provides a starter list rather than full dashboards, covering latency p95, error rate, and JVM heap. These are the standard first signals to watch, and the prompt expects you to expand them into complete dashboards in your chosen backend over time.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Java & Spring Boot Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support