Diffinery

homeflare/celldpublic

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