Diffinery

homeflare/celldpublic

celld/docs/telemetry.md
141 lines · 6.3 KBRaw History
1# Telemetry
2
3celld can record traces and logs for the requests it serves. Telemetry is off
4by default and costs nothing when off. `CELLD_OTEL=1` writes Parquet files
5under the `telemetry/` prefix of the fleet bucket, which DuckDB can query
6directly. `CELLD_OTEL=http://collector:4318` sends the same data to an
7OpenTelemetry collector.
8
9The schema is version `v0-unstable`, so column names can change before a
10stable release. Each file carries the version in the object metadata name
11`celld-schema`, or `celld_schema` on an `az://` bucket.
12
13## Configuration
14
15| variable | default | effect |
16| --- | --- | --- |
17| `CELLD_OTEL` | `0` | `0` disables telemetry. `1` writes Parquet to the fleet bucket. An HTTP(S) collector base URL selects OTLP/HTTP protobuf. |
18| `CELLD_OTEL_BUCKET` | the fleet bucket | A different bucket for the Parquet files, on the same endpoint and credentials. |
19| `CELLD_OTEL_RETENTION` | `30d` | celld deletes telemetry files older than this. `none` disables the deletion, so your own lifecycle rules can control the data. |
20| `CELLD_OTEL_FLUSH_MS` | `300000` | celld writes a Parquet file after this many milliseconds of buffered events. |
21| `CELLD_OTEL_FLUSH_BYTES` | `5242880` | The estimated buffered bytes that trigger a flush before the interval ends. |
22| `OTEL_TRACES_SAMPLER` | `parentbased_always_on` | A standard sampler name. `traceidratio` with `OTEL_TRACES_SAMPLER_ARG` records a fraction of the traces. |
23| `OTEL_EXPORTER_OTLP_HEADERS` | unset | A comma-separated list of `name=value` headers for the collector. |
24| `OTEL_EXPORTER_OTLP_TIMEOUT` | `10000` | The collector request timeout in milliseconds. |
25| `OTEL_SERVICE_NAME` | `celld` | The service name in the exported resource. |
26
27The bucket sink requires `CELLD_BUCKET`. The OTLP sink does not.
28
29A collector URL must have no query or fragment. celld appends `/v1/traces` and
30`/v1/logs` to its path and ignores `OTEL_EXPORTER_OTLP_ENDPOINT`.
31
32`CELLD_OTEL_SINK` is removed, and a node with it set does not start. Put the
33collector base URL in `CELLD_OTEL`, or keep `CELLD_OTEL=1` for the bucket.
34
35## What celld records
36
37celld records a span for each stateless Worker request, each cell event (a
38fetch, an alarm, an RPC, a WebSocket message), each outbound `fetch()`, and
39each cell start. A span carries the request id, the cell, the isolate, the
40queue wait, the outbound URL and status, and the known durability facts.
41
42Each `console.log` line becomes a log record with the trace id and span id of
43its handler, across `await`. The record carries the console method's severity
44in `severity_number` and `severity_text` (OTLP fields and Parquet columns). The
45body holds only the message.
46
47| method | severity number | severity text |
48| --- | --- | --- |
49| `console.debug` | `5` | `DEBUG` |
50| `console.log`, `console.info` | `9` | `INFO` |
51| `console.warn` | `13` | `WARN` |
52| `console.error` | `17` | `ERROR` |
53
54Log files from earlier celld versions have no severity columns. Read a mix of
55versions with `union_by_name = true`.
56
57celld reads the W3C `traceparent` header on incoming requests and sends it on
58outbound `fetch()`. A malformed header starts a new trace. A Worker call to a
59Durable Object stays in one trace.
60
61The sampler decides at the start of a request, and an unsampled request
62records nothing. A ratio of `0` records no traces and `1` records all. An
63intermediate ratio makes the same trace-id decision on each node. celld keeps
64a valid incoming context that the sampler rejects: an outbound `fetch()` or
65Durable Object call keeps the trace id, uses a new span id, and keeps the
66sampled flag clear.
67
68Under load, telemetry sheds before requests do, and celld counts what it
69sheds. celld records no metrics yet.
70
71## Query the bucket with DuckDB
72
73```sql
74INSTALL httpfs; LOAD httpfs;
75CREATE SECRET celld_telemetry (
76 TYPE s3, KEY_ID '...', SECRET '...',
77 ENDPOINT 's3.example.com', URL_STYLE 'path'
78);
79CREATE VIEW traces AS SELECT * FROM
80 read_parquet('s3://YOUR-BUCKET/telemetry/traces/*/*/*/*/*/*.parquet');
81CREATE VIEW logs AS SELECT * FROM
82 read_parquet('s3://YOUR-BUCKET/telemetry/logs/*/*/*/*/*/*.parquet');
83
84-- The slowest requests.
85SELECT name, duration_us, trace_id FROM traces
86 ORDER BY duration_us DESC LIMIT 20;
87
88-- The error lines.
89SELECT time_unix_us, body FROM logs WHERE severity_number >= 17;
90
91-- Every log line, inside the span that wrote it.
92SELECT l.body, t.name, t.duration_us FROM logs l
93 JOIN traces t ON l.trace_id = t.trace_id AND l.span_id = t.span_id;
94```
95
96A non-AWS S3-compatible endpoint needs `URL_STYLE 'path'`. A plain-HTTP
97endpoint also needs `USE_SSL false`.
98
99Files are partitioned by node and hour:
100`telemetry/traces/<node>/<yyyy>/<mm>/<dd>/<hh>/<id>.parquet`.
101
102## Flushing and delivery
103
104celld writes one Parquet file per flush, at 5 minutes
105(`CELLD_OTEL_FLUSH_MS=300000`) or 5 MiB of estimated buffered events
106(`CELLD_OTEL_FLUSH_BYTES=5242880`), whichever comes first. The event that
107reaches the target can take the batch past it.
108
109Keep the defaults if you run no compaction job. They produce large files, but
110data can arrive up to 5 minutes late. `CELLD_OTEL_FLUSH_MS=5000` gives a
111five-second interval, plus upload or collector delay. A short interval makes
112many small files and slows queries within hours, so start the compaction job
113first. For a near-live view, use the OTLP sink with the same short interval.
114
115The OTLP sink makes at most five attempts per batch on a transient failure
116(HTTP 408, 429, 502, 503, or 504). It uses exponential backoff with jitter and
117honors `Retry-After`, with each delay capped at 30 seconds. A permanent
118refusal drops the batch.
119
120The exporter holds one retrying batch, and the input channel holds 8192 new
121events. When the channel is full, celld drops and counts new telemetry, so
122request handling continues.
123
124The retention sweep runs at startup and six hours after each completed sweep.
125
126## Compaction
127
128celld does not compact its own files. Run a compaction job on a maintenance
129node once an hour, for the hour that just ended. Do not compact the current
130hour, because a node still writes to it.
131
132```sql
133COPY (
134 SELECT * FROM
135 read_parquet('s3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/*.parquet')
136 ORDER BY start_unix_us
137) TO 's3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/compacted.parquet'
138 (FORMAT parquet, COMPRESSION zstd);
139```
140
141Delete the source files after DuckDB writes the compacted file.