tracing-ecs-formatter
ECS (Elastic Common Schema) 8.11 JSON formatter for tracing-subscriber.
Produces JSON logs conforming to the ECS 8.11 specification, suitable for ingestion into Elasticsearch, Kibana, and other ECS-compatible systems.
Features
- ECS 8.11 compliant — Explicitly targets the latest ECS specification
- OpenTelemetry integration — Automatically extracts
trace.idandspan.idfrom OpenTelemetry context - Lightweight — Implements
FormatEventtrait, composes with existingtracing-subscriberlayers - Minimal dependencies — OpenTelemetry support is optional
- Service metadata — Built-in
service.nameandservice.versionfields
Installation
[]
= "1"
Without OpenTelemetry support (smaller dependency tree):
[]
= { = "1", = false }
Usage
use fmt;
use EcsFormatter;
Output
Each log event produces a single JSON line:
ECS Fields
| Field | Description |
|---|---|
@timestamp |
RFC 3339 timestamp |
log.level |
ERROR, WARN, INFO, DEBUG, or TRACE |
message |
Log message |
ecs.version |
Always "8.11" |
service.name |
Configured service name |
service.version |
Configured service version |
log.logger |
Tracing target (logger instance name) |
trace.id |
OpenTelemetry trace ID (when available) |
span.id |
OpenTelemetry span ID (when available) |
error.type |
Error type (when present) |
error.message |
Error message (when present) |
error.stack_trace |
Stack trace (when present) |
labels.* |
Additional fields from tracing events |
OpenTelemetry Integration
When used with tracing-opentelemetry, trace context is automatically included:
use SubscriberExt;
use SubscriberInitExt;
use EcsFormatter;
Error Fields
Use dotted field names to populate ECS error fields:
Custom Fields
Any additional fields are output as labels.*:
Output:
Works with all field types:
Feature Flags
| Feature | Default | Description |
|---|---|---|
opentelemetry |
Yes | Enables trace.id and span.id extraction from OpenTelemetry context |
License
Licensed under Apache License, Version 2.0.