Diffinery

homeflare/celldpublic

celld/docs/telemetry.md
134 lines · 6.0 KBRaw History
1# Telemetry
2
3celld can record traces and logs for the requests it serves. The
4feature is off by default, and the off state costs nothing. Set
5`CELLD_OTEL=1` to turn it on.
6
7The default sink is the fleet bucket. celld writes Parquet files under
8the `telemetry/` prefix, so a fleet with a bucket has observability
9with no other service. DuckDB can query these files directly. An
10alternative sink sends the same data to an OpenTelemetry collector.
11
12The schema is version `v0-unstable`. The column names can change
13before a stable release, and each file carries the schema version in
14its object metadata.
15
16## Configuration
17
18| variable | default | effect |
19| --- | --- | --- |
20| `CELLD_OTEL` | `0` | Set this value to `1` to enable telemetry. |
21| `CELLD_OTEL_SINK` | `bucket` | `bucket` writes Parquet to the fleet bucket. `otlp` sends OTLP/HTTP protobuf to a collector instead. |
22| `CELLD_OTEL_BUCKET` | the fleet bucket | A different bucket for the Parquet files, on the same endpoint and credentials. |
23| `CELLD_OTEL_RETENTION` | `30d` | celld deletes telemetry files older than this. `none` disables the deletion, so your own lifecycle rules can control the data. |
24| `CELLD_OTEL_FLUSH_MS` | `300000` | celld writes a Parquet file after this many milliseconds of buffered events. |
25| `CELLD_OTEL_FLUSH_BYTES` | `5242880` | celld writes a Parquet file after the buffered events reach this many bytes. celld uses the limit it reaches first. |
26| `OTEL_TRACES_SAMPLER` | `parentbased_always_on` | A standard sampler name. `traceidratio` with `OTEL_TRACES_SAMPLER_ARG` records a fraction of the traces. |
27| `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4318` | The collector base URL, for the `otlp` sink. `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_TIMEOUT` also apply. |
28| `OTEL_SERVICE_NAME` | `celld` | The service name in the exported resource. |
29
30The `bucket` sink requires the node to have a fleet bucket
31(`CELLD_BUCKET`). The `otlp` sink works on a node without one.
32
33## What celld records
34
35celld records a span for each request a stateless Worker serves, for
36each event a cell serves (a fetch, an alarm, an RPC, a WebSocket
37message), for each outbound `fetch()`, and for each cell start. A
38span carries the request id, the cell, the isolate, the
39queue wait, the outbound URL and status, and the durability facts the
40runtime already knows.
41
42celld also records each `console.log` line as a log record. The log
43record carries the trace id and the span id of the handler that wrote
44it, so a query can join the logs to the traces. The correlation
45survives `await`.
46
47celld reads the W3C `traceparent` header on incoming requests, so its
48spans join the trace of the system in front of it. celld sends a
49`traceparent` header on outbound `fetch()`, so downstream systems can
50join too. A Worker call to a Durable Object stays in one trace.
51
52The sampler decides at the start of a request. An unsampled request
53records nothing and costs almost nothing. Under load, telemetry sheds
54before requests do, and celld counts what it sheds.
55
56celld records no metrics yet. The spans carry the durations and the
57queue waits, so many questions a metric answers have an answer in the
58traces, and a metrics signal can come later without a change to the
59trace schema.
60
61## Query the bucket with DuckDB
62
63```sql
64INSTALL httpfs; LOAD httpfs;
65CREATE SECRET celld_telemetry (
66 TYPE s3, KEY_ID '...', SECRET '...',
67 ENDPOINT 's3.example.com', URL_STYLE 'path'
68);
69CREATE VIEW traces AS SELECT * FROM
70 read_parquet('s3://YOUR-BUCKET/telemetry/traces/*/*/*/*/*/*.parquet');
71CREATE VIEW logs AS SELECT * FROM
72 read_parquet('s3://YOUR-BUCKET/telemetry/logs/*/*/*/*/*/*.parquet');
73
74-- The slowest requests.
75SELECT name, duration_us, trace_id FROM traces
76 ORDER BY duration_us DESC LIMIT 20;
77
78-- Every log line, inside the span that wrote it.
79SELECT l.body, t.name, t.duration_us FROM logs l
80 JOIN traces t ON l.trace_id = t.trace_id AND l.span_id = t.span_id;
81```
82
83An S3-compatible endpoint such as minio needs `URL_STYLE 'path'` in
84the secret, and a plain-HTTP endpoint also needs `USE_SSL false`. AWS
85itself does not need either.
86
87The files are partitioned by node and by hour:
88`telemetry/traces/<node>/<yyyy>/<mm>/<dd>/<hh>/<id>.parquet`. A query
89that reads one day therefore touches only that day's files.
90
91## File size and compaction
92
93celld writes one Parquet file for each flush, on a time limit or a
94size limit, whichever it reaches first. The defaults are 5 minutes
95(`CELLD_OTEL_FLUSH_MS=300000`) and 5 MB (`CELLD_OTEL_FLUSH_BYTES=5242880`).
96
97Keep the defaults if you run no compaction job. They make files large
98enough for a fast query with no other moving part. A query sees an
99event up to 5 minutes after the request, so the default suits an
100investigation after the fact.
101
102Set `CELLD_OTEL_FLUSH_MS=10000` for a near-live view, such as a
103dashboard or an active debug session: a query then sees an event
104within 10 seconds. A short flush makes many small files, and DuckDB
105opens every file a query reads, so you must also run the compaction
106job below. Turn on the compaction job first, then shorten the flush,
107or queries grow slow within hours.
108
109The `otlp` sink is the other route to a near-live view. It sends each
110batch to a collector, so set the same short `CELLD_OTEL_FLUSH_MS`.
111
112## Compaction
113
114Run a compaction job on a maintenance node, not on a celld node. celld
115does not compact its own files, because the serving path must not do
116storage maintenance and each node writes only the files it produced.
117
118The job rewrites one past hour of small files into one large file.
119DuckDB does the work:
120
121```sql
122COPY (
123 SELECT * FROM
124 read_parquet('s3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/*.parquet')
125 ORDER BY start_unix_us
126) TO 's3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/compacted.parquet'
127 (FORMAT parquet, COMPRESSION zstd);
128```
129
130Run the job once an hour, for the hour that just ended. Do not compact
131the current hour, because a node still writes to it. Delete the source
132files after DuckDB writes the compacted file. The compacted file is
133also smaller, because zstd compresses one sorted batch better than
134many separate files.