Trait AttributeMapper

Source
pub trait AttributeMapper:
    Send
    + Sync
    + 'static {
    // Required method
    fn map(&self, span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>;
}
Expand description

Map span attributes name to ECS field name

§Trait implementations

This trait is implemented on HashMap<String, String> and HashMap<&'static str, &'static str> to allow a direct mapping from a map.

Example

use tracing_ecs::ECSLayerBuilder;
use maplit::hashmap;

ECSLayerBuilder::default()
    .with_attribute_mapper(hashmap!(
        "txid" => "transaction.id",
        "request_ip" => "source.ip",
    )).stdout().install().unwrap();

It is also implemented on HashMap<String, HashMap<String, String>> and HashMap<&'static str, HashMap<&'static str, &'static str>>. In this case, the first map level maps span names and the second attribute names.

Example

use tracing_ecs::ECSLayerBuilder;
use maplit::hashmap;

ECSLayerBuilder::default()
    .with_attribute_mapper(hashmap!(
        "request" => hashmap!(
            "method" => "http.request.method",
            "request_ip" => "source.ip",
        ),
        "cron" => hashmap!(
            "request_ip" => "cron.source.ip",
        ),
    )).stdout().install().unwrap();

Required Methods§

Source

fn map(&self, span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>

Given a span name and the name of an attribute, return the mapped attribute name

Trait Implementations§

Source§

impl Default for Box<dyn AttributeMapper>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Implementations on Foreign Types§

Source§

impl AttributeMapper for HashMap<&'static str, &'static str>

Source§

fn map(&self, _span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>

Source§

impl AttributeMapper for HashMap<&'static str, HashMap<&'static str, &'static str>>

Source§

fn map(&self, span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>

Source§

impl AttributeMapper for HashMap<String, String>

Source§

fn map(&self, _span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>

Source§

impl AttributeMapper for HashMap<String, HashMap<String, String>>

Source§

fn map(&self, span_name: &str, name: Cow<'static, str>) -> Cow<'static, str>

Implementors§

Source§

impl<F> AttributeMapper for F
where F: for<'a> Fn(&'a str, Cow<'static, str>) -> Cow<'static, str> + Send + Sync + 'static,