Diffinery

homeflare/celldpublic

celld/docs/telemetry.md
154 lines · 7.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. celld ignores a malformed header and starts a new trace. A
51Worker call to a Durable Object stays in one trace.
52
53The sampler decides at the start of a request. An unsampled request
54records nothing and costs almost nothing. Under load, telemetry sheds
55before requests do, and celld counts what it sheds.
56
57A sampling ratio of `0` records no traces, and a ratio of `1` records
58every trace. An intermediate ratio makes the same trace-id decision on
59each node.
60
61celld keeps a valid incoming context when the sampler rejects it. An
62outbound `fetch()` or Durable Object call keeps the trace id, uses a new
63span id, and keeps the sampled flag clear.
64
65celld records no metrics yet. The spans carry the durations and the
66queue waits, so many questions a metric answers have an answer in the
67traces, and a metrics signal can come later without a change to the
68trace schema.
69
70## Query the bucket with DuckDB
71
72```sql
73INSTALL httpfs; LOAD httpfs;
74CREATE SECRET celld_telemetry (
75 TYPE s3, KEY_ID '...', SECRET '...',
76 ENDPOINT 's3.example.com', URL_STYLE 'path'
77);
78CREATE VIEW traces AS SELECT * FROM
79 read_parquet('s3://YOUR-BUCKET/telemetry/traces/*/*/*/*/*/*.parquet');
80CREATE VIEW logs AS SELECT * FROM
81 read_parquet('s3://YOUR-BUCKET/telemetry/logs/*/*/*/*/*/*.parquet');
82
83-- The slowest requests.
84SELECT name, duration_us, trace_id FROM traces
85 ORDER BY duration_us DESC LIMIT 20;
86
87-- Every log line, inside the span that wrote it.
88SELECT l.body, t.name, t.duration_us FROM logs l
89 JOIN traces t ON l.trace_id = t.trace_id AND l.span_id = t.span_id;
90```
91
92An S3-compatible endpoint such as minio needs `URL_STYLE 'path'` in
93the secret, and a plain-HTTP endpoint also needs `USE_SSL false`. AWS
94itself does not need either.
95
96The files are partitioned by node and by hour:
97`telemetry/traces/<node>/<yyyy>/<mm>/<dd>/<hh>/<id>.parquet`. A query
98that reads one day therefore touches only that day's files.
99
100## File size and compaction
101
102celld writes one Parquet file for each flush, on a time limit or a
103size limit, whichever it reaches first. The defaults are 5 minutes
104(`CELLD_OTEL_FLUSH_MS=300000`) and 5 MB (`CELLD_OTEL_FLUSH_BYTES=5242880`).
105
106Keep the defaults if you run no compaction job. They make files large
107enough for a fast query with no other moving part. A query sees an
108event up to 5 minutes after the request, so the default suits an
109investigation after the fact.
110
111Set `CELLD_OTEL_FLUSH_MS=10000` for a near-live view, such as a
112dashboard or an active debug session: a query then sees an event
113within 10 seconds. A short flush makes many small files, and DuckDB
114opens every file a query reads, so you must also run the compaction
115job below. Turn on the compaction job first, then shorten the flush,
116or queries grow slow within hours.
117
118The `otlp` sink is the other route to a near-live view. It sends each
119batch to a collector, so set the same short `CELLD_OTEL_FLUSH_MS`.
120
121The `otlp` sink makes no more than five attempts for a batch when a
122transient failure occurs. It uses exponential backoff with jitter, and it
123uses an applicable `Retry-After` value from the collector. The exporter caps
124each delay at 30 seconds, so a collector cannot suspend a batch indefinitely.
125HTTP 408, 429, 502, 503, and 504 responses are transient failures. A
126permanent refusal drops the batch immediately.
127
128The exporter owns one retrying batch, and the input channel holds 8192
129new events. An outage cannot make either bound grow. celld drops and counts
130new telemetry when the channel is full, so request handling continues.
131
132## Compaction
133
134Run a compaction job on a maintenance node, not on a celld node. celld
135does not compact its own files, because the serving path must not do
136storage maintenance and each node writes only the files it produced.
137
138The job rewrites one past hour of small files into one large file.
139DuckDB does the work:
140
141```sql
142COPY (
143 SELECT * FROM
144 read_parquet('s3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/*.parquet')
145 ORDER BY start_unix_us
146) TO 's3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/compacted.parquet'
147 (FORMAT parquet, COMPRESSION zstd);
148```
149
150Run the job once an hour, for the hour that just ended. Do not compact
151the current hour, because a node still writes to it. Delete the source
152files after DuckDB writes the compacted file. The compacted file is
153also smaller, because zstd compresses one sorted batch better than
154many separate files.