Encoders¶
An encoder serializes events into a wire format before a sink writes them. Set the format with the encoder.type field. Metric scenarios default to prometheus_text; log scenarios 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 formats keep trailing zeros. A value of 100.0 with precision: 2 renders as 100.00.
This encoder accepts metrics only. Log events are not supported.
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 accepts metrics only. Log events are not supported.
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 still applies; JSON simply does not add trailing zeros.
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 accepts logs only. Metric events are not supported.
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. To build from source: cargo build --features remote-write -p sonda.
No additional parameters.
Pair this encoder with the remote_write sink. The sink handles batching, snappy compression, and the HTTP POST 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. Build from source: cargo build --features otlp -p sonda.
No additional parameters.
Pair this encoder with the otlp_grpc sink. The sink 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 carries roughly 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.
Set precision on the encoder block in your scenario YAML:
encoder:
type: prometheus_text
precision: 2 # 99.60573 becomes 99.61
The syslog, remote_write, and otlp encoders do not support precision. Syslog encodes log events only, with no numeric values; remote write and OTLP use binary protobuf encoding.
See examples/precision-formatting.yaml for a complete scenario that uses precision with several 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 |