Diffinery

homeflare/celldpublic

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