# Add useful logging, metrics, and tracing to a service

Plans the instrumentation a service needs so you can answer what broke, where, and for whom when something goes wrong.

- Topic: Software Development
- Framework: Few-Shot
- Level: Standard
- Tags: Data & Analytics, Coding, Code, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/add-useful-logging-metrics-and-tracing-to-a-service

## Prompt

```text
Help me add observability to a service.

**Service purpose:** [WHAT IT DOES]
**Stack:** [LANGUAGE, FRAMEWORK, HOW IT'S DEPLOYED]
**Observability tools:** [e.g. "OpenTelemetry", "Datadog", "Prometheus + Grafana", "CloudWatch", "none yet"]
**Key code paths:** [PASTE HANDLERS OR DESCRIBE MAIN FLOWS]
**Questions I can't answer today:** [e.g. "why some requests are slow", "which customer is affected"]

Produce:
1. **Logs:** what to log at each level (error, warn, info, debug), a structured log format with standard fields (timestamp, level, request/trace ID, user or tenant ID, operation, duration, outcome), and what must never be logged (passwords, tokens, full card numbers, personal data).
2. **Metrics:** for each main flow, the RED metrics (rate, errors, duration) plus resource and business metrics worth tracking. Name each metric, its type (counter, gauge, histogram), and labels. Warn about high-cardinality labels like user IDs.
3. **Traces:** which spans to create, what attributes to attach, and how to propagate context across HTTP calls, queues, and background jobs.
4. **Code examples:** instrumentation for 1-2 of my code paths in my stack.
5. **Dashboard:** the 6-8 panels to put on the service's main dashboard.

Prioritize: label each item "do first", "next", or "nice to have", so I can ship value in a day rather than boiling the ocean.
```

## What to fill in

- WHAT IT DOES
- LANGUAGE, FRAMEWORK, HOW IT'S DEPLOYED
- PASTE HANDLERS OR DESCRIBE MAIN FLOWS

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
