Encoders¶
Encoders serialize events into a wire format before writing them to a sink. You select an encoder
with the encoder.type field. If omitted, metrics default to prometheus_text and logs default
to json_lines.
prometheus_text¶
Prometheus text exposition format (v0.0.4). Each event becomes one line:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
precision |
integer | no | full f64 precision | Decimal places for metric values (0--17). |
Text-based formats preserve trailing zeros: a value of 100.0 with precision: 2 renders
as 100.00.
This encoder supports metrics only. It does not support log events.
influx_lp¶
InfluxDB line protocol. Each event becomes one line with tags, a field, and a nanosecond timestamp:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
field_key |
string | no | "value" |
The InfluxDB field key for the metric value. |
precision |
integer | no | full f64 precision | Decimal places for metric values (0--17). |
This encoder supports metrics only. It does not support log events.
json_lines¶
JSON Lines (NDJSON) format. Each event is one JSON object per line.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
precision |
integer | no | full f64 precision | Decimal places for metric values (0--17). |
For metrics:
{"name":"cpu_usage","value":50.0,"labels":{"host":"web-01"},"timestamp":"2026-03-23T15:28:32.321Z"}
{"name":"cpu_usage","value":99.606,"labels":{"host":"web-01"},"timestamp":"2026-03-23T15:28:32.321Z"}
Note
JSON has no trailing-zero concept. With precision: 2, a value of 100.0 still renders
as 100.0 in JSON output (not 100.00). The rounding is still applied -- it just does not
add trailing zeros that JSON would strip.
For logs:
{"timestamp":"2026-03-23T14:59:04.840Z","severity":"info","message":"test log","fields":{}}
The precision field only affects metric values. Log events have no numeric value to format.
This is the default encoder for log scenarios. It supports both metrics and logs.
syslog¶
RFC 5424 syslog format. Encodes log events as syslog lines.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
hostname |
string | no | "sonda" |
The HOSTNAME field in the syslog header. |
app_name |
string | no | "sonda" |
The APP-NAME field in the syslog header. |
This encoder supports logs only. It does not support metric events.
remote_write¶
Prometheus remote write protobuf format. Encodes metrics as length-prefixed protobuf
TimeSeries messages.
Note
This encoder requires the remote-write Cargo feature flag. Pre-built release binaries
include this feature. If building from source: cargo build --features remote-write -p sonda.
No additional parameters.
This encoder must be paired with the remote_write sink, which handles batching, snappy
compression, and HTTP POSTing with the correct protocol headers. See
Sinks - remote_write for details.
otlp¶
OTLP protobuf format. Encodes metrics as OTLP Gauge data points and logs as OTLP
LogRecord messages, using length-prefixed protobuf serialization.
Feature flag and build requirement
This encoder requires the otlp Cargo feature flag. Pre-built release binaries and Docker
images do not include this feature. You must build from source:
cargo build --features otlp -p sonda.
No additional parameters.
This encoder must be paired with the otlp_grpc sink, which handles batching and gRPC delivery
to an OpenTelemetry Collector. See Sinks - otlp_grpc for details.
The encoder supports both metrics and logs. Set the sink's signal_type to match your scenario
type (metrics or logs).
Value precision¶
The prometheus_text, influx_lp, and json_lines encoders accept an optional precision
field that controls how many decimal places appear in metric values.
- Range: 0 to 17 (an f64 has approximately 15--17 significant digits).
- Default: omit the field to keep full f64 precision.
- Effect: values are rounded to the specified number of decimal places using standard rounding.
You can set precision in a YAML scenario file or from the CLI with --precision:
The --precision flag works with --encoder or on its own. When you pass --precision without
--encoder, it overrides the precision of whatever encoder your YAML file specifies:
The syslog, remote_write, and otlp encoders do not support precision. Syslog encodes log
events only (no numeric values), and remote write and OTLP use binary protobuf encoding.
See examples/precision-formatting.yaml
for a complete scenario that demonstrates precision with multiple encoders.
Encoder compatibility¶
| Encoder | Metrics | Logs | Precision | Feature flag |
|---|---|---|---|---|
prometheus_text |
yes | no | yes | -- |
influx_lp |
yes | no | yes | -- |
json_lines |
yes | yes | yes | -- |
syslog |
no | yes | -- | -- |
remote_write |
yes | no | -- | remote-write |
otlp |
yes | yes | -- | otlp |