# Logs and server telemetry

> Set up structured JSON logs, log levels, metrics, Sentry error tracking and run inspection on the 10xGraph API server, and see what each setting writes.

Source: https://10xgraph.com/docs/server/observability
Last updated: 2026-11-25

The API server writes application logs to stdout with a request id. Metrics are off until you add a `metrics` block to `10xgraph.json`. The audit log, Sentry and tracing are optional.

## Logs

The API server writes its application logs to stdout, with secrets redacted (`LOG_REDACT_SECRETS`, on by default). `LOG_LEVEL` is the content switch: message text appears only at `DEBUG`, and `INFO` logs ids only. See [What the framework redacts, and what is yours](/docs/concepts/events-and-observability#what-the-framework-redacts-and-what-is-yours). Each request gets an id, returned in the `X-Request-ID` response header and attached to the log lines of that request.

Set `LOG_FORMAT=json` to write every log line as one JSON object (`ts`, `level`, `logger`, `message`, plus `request_id`, `transport` and `user_id` when known and `exc_info` for an exception). The default is `text`. Use `json` in production so your log pipeline can parse and index the lines. `10xgraph build` sets `LOG_FORMAT=json` in the generated Dockerfile, Compose file and Kubernetes manifest.

```bash
LOG_FORMAT=json
LOG_LEVEL=INFO
```

### Log levels

Core and the API follow one rule for levels.

| Level | What it carries | Volume |
|---|---|---|
| `DEBUG` | Everything needed to follow a run: each step, node (with duration), route and why it was taken, interrupts, saves, state loads (cache, Postgres or new thread), LLM calls (start, end, duration, finish reason, tokens), tool calls (start, end, status), ToolGuard decisions, and per-request API lines (run request, thread lock, idempotency, RBAC decisions, WebSocket sessions, job enqueue, start and end). Message text, tool arguments and model output appear only here. | As much as useful |
| `INFO` | Once per process or per run: the `Started:` summary and shutdown (API), setup lines with the settings in force (checkpointer, store, publishers; no URLs or credentials), `Graph run started` and `Graph run ended`, rare events (fallback model, crash recovery, stop), and refusals tied to limits (rate limit, request size, run and connection caps, busy thread). | About two lines per run |
| `WARNING` | The framework fell back, retried, dropped or ignored something and went on, such as a model retry, an open Redis breaker or a publisher drop. Auth refusals while the [audit log](/docs/server/audit-log) is off. | Only when you should know |
| `ERROR` | A run, request, job or save failed. A 5xx carries the traceback. | Real failures only |

Handled 4xx errors log at `DEBUG`. Per-token and per-chunk lines are never logged; the chunk count goes in the run-end line.

### One run at INFO and at DEBUG

At `INFO`, a run writes two core lines. The examples use the core library's own text format (the server's text format differs; see `LOG_FORMAT`); ids are made up:

```text
[2026-11-30 10:12:01,402] INFO tenxgraph.graph [run=r_8f2 thread=t_41 node=-]: Graph run started: thread_id=t_41, streaming=False, input_messages=1
[2026-11-30 10:12:03,118] INFO tenxgraph.graph [run=r_8f2 thread=t_41 node=-]: Graph run ended: thread_id=t_41, status=completed, steps=3, last_node=MAIN, duration=1.72s
```

`status` is `completed`, `interrupted`, `stopped`, `cancelled` or `failed`. At `DEBUG` the same run also shows the steps between them, with the message formats from the code:

```text
DEBUG tenxgraph.graph [run=r_8f2 thread=t_41 node=-]: Step 1 of 25: entering node 'MAIN'
DEBUG tenxgraph.agent [run=r_8f2 thread=t_41 node=MAIN]: LLM call start: provider=openai, model=gpt-4o, messages=2, tools=1, stream=False
DEBUG tenxgraph.agent [run=r_8f2 thread=t_41 node=MAIN]: LLM call ended: model=gpt-4o, duration=640ms, status=ok, finish_reason=tool_calls, ...
DEBUG tenxgraph.graph [run=r_8f2 thread=t_41 node=MAIN]: Node 'MAIN' ended: status=ok, duration=0.652s
DEBUG tenxgraph.graph [run=r_8f2 thread=t_41 node=-]: Route 'MAIN' -> 'TOOL': condition returned TOOL
DEBUG tenxgraph.graph.tool_node [run=r_8f2 thread=t_41 node=TOOL]: Executing tool 'get_weather' with 1 arguments
DEBUG tenxgraph.graph.tool_node [run=r_8f2 thread=t_41 node=TOOL]: Tool 'get_weather' ended: duration=12ms, status=ok
```

Every core record carries `run_id`, `thread_id`, `user_id` and `node`. The text format shows run, thread and node; the JSON format adds `user_id`.

### Raise one area to DEBUG

Every core logger lives under `tenxgraph`, so stdlib levels work per area. In your own code:

```python
import logging

logging.getLogger("tenxgraph.checkpointer").setLevel(logging.DEBUG)
```

A child logger such as `tenxgraph.checkpointer.pg` follows its parent unless you set it. In the API server, `LOG_LEVEL` sets the level for the API loggers and for the core `tenxgraph` loggers together, so `LOG_LEVEL=DEBUG` shows core and API detail at once. The server's console handler is set to `LOG_LEVEL` too, so a single logger cannot go below it there; set `LOG_LEVEL=DEBUG` for the whole process, or raise one area in your own process as above.

### Logger names

| Logger | Covers |
|---|---|
| `tenxgraph.graph` | Run loop, routing, nodes, compile |
| `tenxgraph.agent`, `tenxgraph.llm` | Agent and LLM calls, retries, fallback, rate limiter |
| `tenxgraph.graph.tool_node` | Tool execution, ToolGuard, MCP calls |
| `tenxgraph.state` | State load and merge, summaries |
| `tenxgraph.checkpointer`, `.pg`, `.sqlite` | Checkpointers |
| `tenxgraph.store`, `tenxgraph.store.pgvector` | Stores and PgVectorStore |
| `tenxgraph.publisher`, `tenxgraph.trace_export` | Event publishers and trace export |
| `tenxgraph.media` | Media storage, resolving and offload |
| `tenxgraph.realtime` | Realtime sessions |
| `tenxgraph.authz` | Permission checks in core |
| `tenxgraph.prebuilt.*` | Prebuilt agents |
| `10xgraph-api`, `tenxgraph_api` | API server, app lifecycle, auth, errors, rate limit, concurrency |
| `tenxgraph_api.jobs` | Background jobs, workers and the scheduler |
| `tenxgraph_api.media` | API media routes |
| `tenxgraph_api.audit` | The audit log sink |

### What each level shows about people

- `DEBUG` shows content on purpose, so you can check a run: message text, tool arguments, model output, thread names and file names. Treat `DEBUG` logs as containing personal data.
- `INFO`, `WARNING` and `ERROR` carry ids, types, counts and durations, not that content. One exception: a tool denied by policy logs a `WARNING` with the tool name, the policy reason and the user id.
- Use `LOG_LEVEL=INFO` or higher in production and `DEBUG` only while you debug.
- The user id does not depend on the level. It follows `observability.user_id_mode` (`raw`, `hash` or `mask`) in the `user_id` field of every JSON record, in the API auth `WARNING` lines and in the API `DEBUG` lines that name a user. Some core `DEBUG` lines put a user id in the message text (checkpointer thread lines, `Permission ... denied for user`); core does not know the API's mode, so those are raw. The core `INFO` run lines carry the thread id, not the user id.
- Secrets are masked at every level unless `LOG_REDACT_SECRETS=false`.
- The [audit log](/docs/server/audit-log) is separate and always keeps the real `user_id`.

See [What the framework redacts, and what is yours](/docs/concepts/events-and-observability#what-the-framework-redacts-and-what-is-yours) for the full list.

Ship stdout to storage you retain and protect (Docker or Kubernetes logging, Fluent Bit, Vector, a SIEM). 10xGraph does not store logs. For a record of who accessed or changed which data, turn on the [audit log](/docs/server/audit-log).

To configure logging in your own process (outside the server), see [Logging and secret redaction](/docs/reference/python/runtime-utilities#logging-and-secret-redaction).

## Metrics

When `OTEL_ENABLED=true`, the API and the background worker do this for you: they install a `MeterProvider` that exports to `OTEL_EXPORTER_OTLP_ENDPOINT` (the console when it is unset outside production) and call `setup_otel_metrics()`, so the metrics below, and the task metrics in [background tasks](/docs/server/background-tasks), reach your collector along with the traces. To export metrics to Prometheus or Grafana without the legacy settings, use the `metrics` block instead. See [Metrics with Prometheus and Grafana](/docs/guides/metrics-prometheus-grafana). When the block is enabled, it owns metrics and this path sends traces only.

The in-process metrics API (`counter`, `timer`, `snapshot`, `setup_otel_metrics`) is in [Metrics instrumentation](/docs/reference/python/runtime-utilities#metrics-instrumentation).

### Framework-instrumented metrics

The 10xGraph framework automatically records these:

The `tool` attribute is the tool name only when the node can run that tool. A name the model made up is recorded as `"unknown"`, so unknown names cannot create new series.

| Metric | Type | Attributes |
|---|---|---|
| `tenxgraph.node.executions` | counter | `node` |
| `tenxgraph.node.errors` | counter | `node` |
| `tenxgraph.node.timeouts` | counter | `node` |
| `tenxgraph.node.stopped` | counter | `node` |
| `tenxgraph.node.duration` | timer | `node`, `outcome` |
| `tenxgraph.tool.calls` | counter | `node`, `tool` |
| `tenxgraph.tool.errors` | counter | `node`, `tool` |
| `tenxgraph.tool.timeouts` | counter | `node`, `tool` |
| `tenxgraph.tool.duration` | timer | `node`, `tool`, `outcome` |
| `tenxgraph.llm.duration` | timer | `provider`, `model`, `status` |
| `tenxgraph.llm.tokens` | counter | `provider`, `model`, `type` |
| `background_task_manager.tasks_created` | counter | - |
| `background_task_manager.tasks_completed` | counter | - |
| `background_task_manager.tasks_failed` | counter | - |
| `background_task_manager.tasks_dropped` | counter | - |
| `background_task_manager.tasks_cancelled` | counter | - |
| `background_task_manager.tasks_timed_out` | counter | - |
| `pg_checkpointer.save_state.attempts` | counter | - |
| `pg_checkpointer.save_state.success` | counter | - |
| `pg_checkpointer.save_state.error` | counter | - |
| `pg_checkpointer.save_state.conflict` | counter | - |
| `pg_checkpointer.save_state.duration` | timer | - |
| `pg_checkpointer.save_checkpoint.attempts` | counter | - |
| `pg_checkpointer.save_checkpoint.success` | counter | - |
| `pg_checkpointer.save_checkpoint.error` | counter | - |
| `pg_checkpointer.save_checkpoint.conflict` | counter | - |
| `pg_checkpointer.save_checkpoint.duration` | timer | - |
| `pg_checkpointer.save_state_cache.duration` | timer | - |
| `tenxgraph.publish.duration` | timer | `publisher` |
| `tenxgraph.publish.batches` | counter | `publisher` |
| `tenxgraph.publish.events` | counter | `publisher` |
| `tenxgraph.publish.dropped` | counter | `publisher` |

`pg_checkpointer.save_state.conflict` counts optimistic-concurrency rejections. `background_task_manager.tasks_dropped` counts events shed under backpressure.

`tenxgraph.publish.*` come from the Kafka, Redis and RabbitMQ publishers, which batch events. `tenxgraph.publish.dropped` counts events dropped because the publisher queue was full, so a rising value means the broker is slower than your event rate. `tenxgraph.publish.duration` times one batch for those publishers and one send for the others. `pg_checkpointer.save_state_cache.duration` times one state-cache write to Redis.

A trace backend that is down logs once, not once per batch: the `tenxgraph.trace_export` logger writes one WARNING naming the endpoint when exports start failing and one INFO when they recover. Other observability failures are logged at debug level and never propagate to the caller: a misconfigured exporter does not crash the API.

## Error tracking with Sentry

Sentry is optional. Install the extra:

```bash
pip install "10xgraph-api[sentry]"
```

Configure Sentry via environment variables:

| Variable | Default | Description |
|---|---|---|
| `SENTRY_DSN` | (none) | Sentry DSN. When unset or empty, Sentry is disabled. |
| `SENTRY_TRACES_SAMPLE_RATE` | 0.1 | Share of requests to trace (0.0 to 1.0). Higher rates incur tracing costs. |
| `SENTRY_PROFILES_SAMPLE_RATE` | 0.0 | Share of traces to profile (0.0 to 1.0). Profiling is expensive; 0.0 disables it. |

Example `.env` file:

```bash
SENTRY_DSN="https://key@sentry.io/project-id"
SENTRY_TRACES_SAMPLE_RATE=0.1
SENTRY_PROFILES_SAMPLE_RATE=0.01
```

When the API starts, Sentry initialization is best-effort: if the SDK is not installed or DSN is invalid, a warning is logged and the server continues. Only HTTP 5xx status codes are reported to Sentry; client errors (4xx) are not, preventing floods of validation error events. The error handlers log a handled 4xx at DEBUG (method, path, status, error code) without a traceback, and a 5xx as ERROR with the traceback. Only ERROR logs become Sentry events; warnings and info lines stay breadcrumbs. Request bodies are never sent to Sentry (`max_request_body_size="never"`), nor are local variables or default PII. Log text, exception values and request URLs go through the same secret redaction as stdout (`before_breadcrumb` and `before_send`), and `user_id` follows `observability.user_id_mode`. `LOG_REDACT_SECRETS=false` turns the secret redaction off in Sentry too. Message text still reaches Sentry if you log it, so keep `LOG_LEVEL` at `INFO` or above.

## The observability API endpoint

`GET /v1/observability/{thread_id}` rebuilds a run trace for a thread. It backs the playground's Run trace page and records nothing with `MODE=production`.

Query the latest run in a thread:

```bash
curl -H "Authorization: Bearer $TOKEN" \
  http://localhost:8000/v1/observability/thread-42
```

Or request a specific run:

```bash
curl -H "Authorization: Bearer $TOKEN" \
  "http://localhost:8000/v1/observability/thread-42?run_id=run_01ARZ3NDEKTSV4RRFFQ69G5FAV"
```

The response is wrapped in the standard envelope; `data` holds the thread's run list and the selected run's trace:

```json
{
  "data": {
    "thread_id": "thread-42",
    "run_count": 3,
    "run_ids": ["run_a", "run_b", "run_c"],
    "run": {
      "run_id": "run_c",
      "thread_id": "thread-42",
      "status": "done",
      "started_at": 1791469982.421,
      "finished_at": 1791469983.944,
      "duration_ms": 1523.0,
      "spans": [
        {
          "id": "s1",
          "name": "node: agent",
          "kind": "node",
          "parent": "root",
          "start_ms": 0.0,
          "duration_ms": 1420.0,
          "model": null,
          "input_tokens": null,
          "output_tokens": null
        }
      ],
      "events": [
        {
          "id": "e1",
          "type": "message",
          "node": "agent",
          "offset_ms": 1400.0,
          "summary": "assistant message"
        }
      ],
      "usage": {
        "prompt_tokens": 250,
        "completion_tokens": 89,
        "reasoning_tokens": 0,
        "total_tokens": 339
      },
      "llm_calls": 1,
      "tool_calls": 0,
      "iterations": 1
    }
  },
  "metadata": {}
}
```

`status` is one of `running`, `done`, `error` or `stopped`. Span `kind` is `root`, `node`, `llm` or `tool`. Event `type` is `message`, `updates`, `state`, `error` or `result`.

This endpoint is a development tool built for the playground's Run trace page. The traces come from an in-memory, process-local store that the server creates only when `MODE` is not `production`. With `MODE=production`, which the generated Docker files set, the store is never created: nothing is recorded, and the endpoint returns an empty result with `enabled: false` and `reason: "disabled_in_production"`. Other reasons are `store_unavailable` and `no_runs`. Use OTEL, LangSmith, Logfire or another publisher for production tracing. When enabled, it keeps at most 200 threads, 20 runs per thread and 2000 records per run, and a restart clears it. It is not a durable tracing backend. When no run exists for a thread, `run` is `null` and the endpoint still returns 200. It requires the `graph:read` permission, and with auth on the thread is read through the caller's scope, so a user can read traces only for their own threads by default. See [authorization](/docs/server/auth) for how to set up access control.

The TypeScript client wraps this endpoint as `client.observability(threadId, runId?)`.

For spans sent to an OTLP endpoint, Phoenix, Logfire or LangSmith, see [Send AI traces](/docs/guides/send-traces). For Prometheus and Grafana, see [Metrics with Prometheus and Grafana](/docs/guides/metrics-prometheus-grafana).

## What is in your traces

Spans carry `user_id`, `thread_id` and `run_id`. Set `"observability": {"user_id_mode": "hash"}` (or `"mask"`) in `10xgraph.json` to change how the user id appears. It applies to the server's OTEL publisher, for the `observability` block and for `OTEL_ENABLED`, and to the JSON log `user_id` field, the auth WARNING lines and Sentry. The audit log keeps the real id. `observability.level` defaults to `full`, which puts prompts, completions, tool I/O and graph state on spans; `standard` drops prompts, completions and tool I/O and keeps graph state on Phoenix node spans only, and `spans` carries neither. At `spans` errors carry only the exception type. Graph state never reaches plain OTLP, Logfire or LangSmith spans. See [What is in your traces and events](/docs/concepts/events-and-observability#what-is-in-your-traces-and-events).

## Related docs

- [Send AI traces](/docs/guides/send-traces)
- [Authentication and authorization](/docs/server/auth)
- [Production checklist](/docs/server/production-checklist)
- [Logging utilities reference](/docs/reference/python/runtime-utilities)
- [Metrics and publishers reference](/docs/reference/python/publishers)
