> For the complete documentation index, see [llms.txt](https://taskflow-1.gitbook.io/taskflow-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://taskflow-1.gitbook.io/taskflow-docs/observability.md).

# Observability

What each service emits, and which signals page a human. The rule that shapes everything below: logs, metrics, and traces carry user IDs, never email addresses — PII in logs is a severity-1 incident (see `incident-runbook.md`).

## Logs

* Structured JSON to stdout, shipped centrally; stopping that shipping is step one of the log-leak runbook procedure.
* Required fields: `ts`, `service`, `level`, `request_id`, and `user_id` when a user context exists.
* `request_id` is minted at the edge and propagated into worker job payloads, so one user action can be followed across `api-service`, the queue, and `worker`.

## Metrics

* Per endpoint: request rate, error rate split by the error `code` values in `taskflow-api-docs` (`errors.md`), and duration p50/p95/p99.
* Per queue: depth, oldest job age, and dead-letter list size.
* PostgreSQL: connection count, replica lag, and queries slower than 500 ms.

## Traces

* OpenTelemetry spans in `api-service` for PostgreSQL queries and Redis enqueues; `worker` spans link back through `request_id`.
* Traces sample at 10% normally and 100% for requests that end in a 5xx, so failures are always traceable after the fact.

## Alerts

| Signal                       | Threshold               | Response                                          |
| ---------------------------- | ----------------------- | ------------------------------------------------- |
| `/health` reports `degraded` | 2 minutes               | Page on-call                                      |
| Dead-letter list size        | > 0 for 10 minutes      | Page on-call (poison job — `incident-runbook.md`) |
| Replica lag                  | > 30 s for 5 minutes    | Ticket, next business day                         |
| p99 latency on task list     | > 800 ms for 15 minutes | Ticket, next business day                         |

Every paging alert names its runbook section. An alert without a runbook entry is a review finding, not a nuisance to silence.

## Demo implementation note

The demo implementation (demo-app) covers the Logs slice of this page: one structured JSON line per request to stdout with `ts`, `service`, `level`, `request_id`, `method`, `status`, and `duration_ms`, and the request ID echoed as the `X-Request-ID` response header (an inbound ID is propagated; otherwise one is minted at the demo, which is its own edge). Two adaptations keep the severity-1 rule intact: the logged path is the matched route template (or `<unmatched>`), never the raw path, and `user_id` is omitted because the demo has no authenticated user context. Metrics, traces, central log shipping, and propagation into worker job payloads remain production-only and are not implemented by the demo.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://taskflow-1.gitbook.io/taskflow-docs/observability.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
