pub struct ECSLayerBuilder { /* private fields */ }
Expand description
Builder for a subscriber Layer writing ECS compatible json lines to a writer.
Example:
use tracing_ecs::ECSLayerBuilder;
// creates a minimal layer logging to stdout, and install it
ECSLayerBuilder::default()
.stdout()
.install()
.unwrap();
Implementations§
Source§impl ECSLayerBuilder
impl ECSLayerBuilder
pub fn with_extra_fields<F: Serialize>( self, extra_fields: F, ) -> Result<Self, Error>
pub fn with_attribute_mapper<M>(self, attribute_mapper: M) -> Selfwhere
M: AttributeMapper,
Sourcepub fn with_span_events(self, span_events: FmtSpan) -> Self
pub fn with_span_events(self, span_events: FmtSpan) -> Self
Setup span events logging. Events supported: NEW
, ENTER
, EXIT
, CLOSE
.
Each configured span event (eg. enter span) will output a new log event line with an event
object having the following attributes:
kind
:span
action
: eithernew
,enter
,exit
orclose
Example:
use tracing_ecs::ECSLayerBuilder;
use tracing_subscriber::fmt::format::FmtSpan;
ECSLayerBuilder::default()
.with_span_events(FmtSpan::ENTER | FmtSpan::EXIT)
.stdout()
.install()
.unwrap();
Event log line example:
{
"@timestamp": "2025-07-24T08:24:19.733176000Z",
"event": {
"action": "enter",
"kind": "span"
},
"span": {
"id": "1",
"name": "span_name"
}
}
Sourcepub fn normalize_json(self, normalize_json: bool) -> Self
pub fn normalize_json(self, normalize_json: bool) -> Self
Control the normalization (keys de-dotting) of the generated json in the sense of https://www.elastic.co/guide/en/ecs/current/ecs-guidelines.html.
By default, normalization is enabled, thus logging host.hostname="localhost"
will output:
{"host":{"hostname": "localhost"}}
With normalization disabled:
{"host.hostname": "localhost"}
Depending on your use case you may want to disable normalization if it’s done elsewhere in your log processing pipeline.
Benchmarks suggests a 30% speed up on log generation. (benches run on an Apple M2 Pro) it will
also allocate less because, normalization recursively recreates a brand new json Value
(not measured).