# Traces and logs (OpenTelemetry)

Send Postdot's request traces, delivery traces and logs to your own OpenTelemetry collector.

URL: /docs/opentelemetry

Available from `0.1.0-alpha.10`. Off by default.

If you already run an OpenTelemetry collector or a tool that accepts OTLP (Grafana with
Tempo and Loki, SigNoz, Jaeger, Honeycomb and others), Postdot can send it traces and
logs. You then see how long each request took, which platform call slowed a publication
down, and the log lines of a failing request next to its trace.

Most installations do not need this: [Diagnostics](/docs/diagnostics/) answers "what is
broken" without any extra tool.

## Turn it on [#turn-it-on]

Postdot reads the standard OpenTelemetry variables. Set them in the environment of the
Postdot container, then restart it:

```sh
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
# Optional
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf    # or http/json
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20<token>
OTEL_SERVICE_NAME=postdot
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production
```

| Variable                                                  | Use                                                                    |
| --------------------------------------------------------- | ---------------------------------------------------------------------- |
| `OTEL_EXPORTER_OTLP_ENDPOINT`                             | Base address of the collector's OTLP/HTTP receiver, usually port 4318  |
| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`                      | Full address for traces only, if they go elsewhere                     |
| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`                        | Full address for logs only, if they go elsewhere                       |
| `OTEL_EXPORTER_OTLP_PROTOCOL`                             | `http/protobuf` (default) or `http/json`. gRPC is not supported        |
| `OTEL_EXPORTER_OTLP_HEADERS`                              | Headers for the collector, such as a token. URL-encode spaces as `%20` |
| `OTEL_SERVICE_NAME`                                       | The service name shown in your tool. Defaults to `postdot`             |
| `OTEL_RESOURCE_ATTRIBUTES`                                | Extra attributes, such as `deployment.environment=production`          |
| `OTEL_SDK_DISABLED`                                       | `true` turns export off without removing the other variables           |
| `OTEL_BSP_*`, `OTEL_BLRP_*`, `OTEL_EXPORTER_OTLP_TIMEOUT` | Batching and timeout tuning, as defined by OpenTelemetry               |

With only `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` set, Postdot sends traces and no logs, and
the other way round.

These settings live with the deployment, not in Studio: the collector is part of your
infrastructure, and every OpenTelemetry tool documents these same variables.

To check, open **Settings**, **Diagnostics** and run the checks: **OpenTelemetry export**
says whether export is on, with the service name, the protocol and the collector address.
The shared report only says "on" or "off", never the address.

## What Postdot sends [#what-postdot-sends]

**Traces**

- One span per HTTP request, named after the route (`GET /api/projects/:projectId`), with
  the method, path and status. A `traceparent` header from your reverse proxy is honoured,
  so its trace continues into Postdot. Requests to unknown paths share one name,
  `GET unmatched`.
- One span per background delivery: `postdot.publication.deliver`,
  `postdot.webhook.deliver` and `postdot.email.send`.
- One span per call to a platform or webhook receiver, as a child of the delivery or
  request that made it, with the method, host, path and status.

**Logs**

- The API's log lines, with the trace and span of the request that wrote them. They
  follow `LOG_LEVEL` and are still written to the container output.
- Each problem shown in Diagnostics, as an error log with its source and code.

**What Postdot never sends**: headers, cookies, query strings, request or response
bodies, post content, tokens or credentials. Calls to platforms and webhook receivers do
not carry a `traceparent` header, so third parties never see your trace identifiers.

Health checks (`/health`, `/ready`) and `/metrics` are not traced.

## Cost [#cost]

With the variables unset, nothing is started: no background timer, no buffer, no extra
work per request. With export on, spans and logs are sent in batches; if the collector is
down, Postdot keeps working and drops what it cannot send. On shutdown, Postdot waits up
to two seconds to send what is left.

## Prometheus metrics [#prometheus-metrics]

[Metrics](/docs/metrics/) stay separate and work as before: OpenTelemetry export adds
traces and logs, not metrics.
