Diffinery

homeflare/celldpublic

celld/docs/telemetry.md
168 lines · 7.7 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 write telemetry to the fleet bucket.
6Set `CELLD_OTEL=http://collector:4318` to send telemetry to an OTLP collector.
7
8The default sink is the fleet bucket. celld writes Parquet files under
9the `telemetry/` prefix, so a fleet with a bucket has observability
10with no other service. DuckDB can query these files directly. An
11alternative sink sends the same data to an OpenTelemetry collector.
12
13The schema is version `v0-unstable`. The column names can change
14before a stable release, and each file carries the schema version in
15its object metadata.
16
17## Configuration
18
19| variable | default | effect |
20| --- | --- | --- |
21| `CELLD_OTEL` | `0` | `0` disables telemetry. `1` writes Parquet to the fleet bucket. An HTTP(S) collector base URL selects OTLP/HTTP protobuf. |
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` | The estimated buffered bytes that trigger a flush before the interval ends. |
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_HEADERS` | unset | A comma-separated list of `name=value` headers for the collector. |
28| `OTEL_EXPORTER_OTLP_TIMEOUT` | `10000` | The collector request timeout in milliseconds. |
29| `OTEL_SERVICE_NAME` | `celld` | The service name in the exported resource. |
30
31The `bucket` sink requires the node to have a fleet bucket
32(`CELLD_BUCKET`). The `otlp` sink works on a node without one.
33
34Use a full HTTP(S) collector base URL without a query or a fragment.
35celld adds `/v1/traces` and `/v1/logs` to its path for the two signals.
36`CELLD_OTEL` supplies the collector address, so celld does not read
37`OTEL_EXPORTER_OTLP_ENDPOINT`.
38
39`CELLD_OTEL_SINK` is removed. Remove this setting before starting the node.
40For a collector, copy its full base URL into `CELLD_OTEL`. For the fleet bucket, keep `CELLD_OTEL=1`.
41
42
43## What celld records
44
45celld records a span for each request a stateless Worker serves, for
46each event a cell serves (a fetch, an alarm, an RPC, a WebSocket
47message), for each outbound `fetch()`, and for each cell start. A
48span carries the request id, the cell, the isolate, the
49queue wait, the outbound URL and status, and the durability facts the
50runtime already knows.
51
52celld also records each `console.log` line as a log record. The log
53record carries the trace id and the span id of the handler that wrote
54it, so a query can join the logs to the traces. The correlation
55survives `await`.
56
57celld reads the W3C `traceparent` header on incoming requests, so its
58spans join the trace of the system in front of it. celld sends a
59`traceparent` header on outbound `fetch()`, so downstream systems can
60join too. celld ignores a malformed header and starts a new trace. A
61Worker call to a Durable Object stays in one trace.
62
63The sampler decides at the start of a request. An unsampled request
64records nothing and costs almost nothing. Under load, telemetry sheds
65before requests do, and celld counts what it sheds.
66
67A sampling ratio of `0` records no traces, and a ratio of `1` records
68every trace. An intermediate ratio makes the same trace-id decision on
69each node.
70
71celld keeps a valid incoming context when the sampler rejects it. An
72outbound `fetch()` or Durable Object call keeps the trace id, uses a new
73span id, and keeps the sampled flag clear.
74
75celld records no metrics yet. The spans carry the durations and the
76queue waits, so many questions a metric answers have an answer in the
77traces, and a metrics signal can come later without a change to the
78trace schema.
79
80## Query the bucket with DuckDB
81
82```sql
83INSTALL httpfs; LOAD httpfs;
84CREATE SECRET celld_telemetry (
85 TYPE s3, KEY_ID '...', SECRET '...',
86 ENDPOINT 's3.example.com', URL_STYLE 'path'
87);
88CREATE VIEW traces AS SELECT * FROM
89 read_parquet('s3://YOUR-BUCKET/telemetry/traces/*/*/*/*/*/*.parquet');
90CREATE VIEW logs AS SELECT * FROM
91 read_parquet('s3://YOUR-BUCKET/telemetry/logs/*/*/*/*/*/*.parquet');
92
93-- The slowest requests.
94SELECT name, duration_us, trace_id FROM traces
95 ORDER BY duration_us DESC LIMIT 20;
96
97-- Every log line, inside the span that wrote it.
98SELECT l.body, t.name, t.duration_us FROM logs l
99 JOIN traces t ON l.trace_id = t.trace_id AND l.span_id = t.span_id;
100```
101
102An S3-compatible endpoint such as minio needs `URL_STYLE 'path'` in
103the secret, and a plain-HTTP endpoint also needs `USE_SSL false`. AWS
104itself does not need either.
105
106The files are partitioned by node and by hour:
107`telemetry/traces/<node>/<yyyy>/<mm>/<dd>/<hh>/<id>.parquet`. A query
108that reads one day therefore touches only that day's files.
109
110## File size and compaction
111
112celld writes one Parquet file for each flush, on a time limit or a
113size target, whichever it reaches first. The default interval is 5 minutes
114(`CELLD_OTEL_FLUSH_MS=300000`). The default size target is 5 MiB of estimated
115buffered events (`CELLD_OTEL_FLUSH_BYTES=5242880`). The event that reaches
116the target can take the batch past it.
117
118Keep the defaults if you run no compaction job. They make files large
119enough for a fast query with no other moving part. The default batching
120delay can reach 5 minutes, so the default suits an investigation after the fact.
121
122Set `CELLD_OTEL_FLUSH_MS=5000` for a five-second batching interval.
123An upload, a retry, or collector processing can add a delivery delay.
124A short flush makes many small files, and DuckDB
125opens every file a query reads, so you must also run the compaction
126job below. Turn on the compaction job first, then shorten the flush,
127or queries grow slow within hours.
128
129The `otlp` sink is the other route to a near-live view. It sends each
130batch to a collector, so set the same short `CELLD_OTEL_FLUSH_MS`.
131
132The `otlp` sink makes no more than five attempts for a batch when a
133transient failure occurs. It uses exponential backoff with jitter, and it
134uses an applicable `Retry-After` value from the collector. The exporter caps
135each delay at 30 seconds, so a collector cannot suspend a batch indefinitely.
136HTTP 408, 429, 502, 503, and 504 responses are transient failures. A
137permanent refusal drops the batch immediately.
138
139The exporter owns one retrying batch, and the input channel holds 8192
140new events. An outage cannot make either bound grow. celld drops and counts
141new telemetry when the channel is full, so request handling continues.
142
143The retention sweep runs at startup and six hours after each completed sweep. It deletes expired
144objects and preserves objects within the configured retention window.
145
146## Compaction
147
148Run a compaction job on a maintenance node, not on a celld node. celld
149does not compact its own files, because the serving path must not do
150storage maintenance and each node writes only the files it produced.
151
152The job rewrites one past hour of small files into one large file.
153DuckDB does the work:
154
155```sql
156COPY (
157 SELECT * FROM
158 read_parquet('s3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/*.parquet')
159 ORDER BY start_unix_us
160) TO 's3://YOUR-BUCKET/telemetry/traces/<node>/2026/08/09/22/compacted.parquet'
161 (FORMAT parquet, COMPRESSION zstd);
162```
163
164Run the job once an hour, for the hour that just ended. Do not compact
165the current hour, because a node still writes to it. Delete the source
166files after DuckDB writes the compacted file. The compacted file is
167also smaller, because zstd compresses one sorted batch better than
168many separate files.