pub type FieldMappingFn = dyn for<'a> Fn(&'a SpanData, &'a ModelConfig) -> &'a str + Send + Sync;
Expand description

Custom mapping between opentelemetry spans and datadog spans.

User can provide custom function to change the mapping. It currently supports customizing the following fields in Datadog span protocol.

field namedefault value
service nameservice name configuration from ModelConfig
nameopentelemetry instrumentation library name
resourceopentelemetry name

The function takes a reference to SpanData and a reference to ModelConfig as parameters. It should return a &str which will be used as the value for the field.

If no custom mapping is provided. Default mapping detailed above will be used.

For example,

use opentelemetry_datadog::{ApiVersion, new_pipeline};
fn main() -> Result<(), opentelemetry::trace::TraceError> {
   let tracer = new_pipeline()
           .with_service_name("my_app")
           .with_api_version(ApiVersion::Version05)
           // the custom mapping below will change the all spans' name to datadog spans
           .with_name_mapping(|span, model_config|{
                "datadog spans"
            })
           .with_agent_endpoint("http://localhost:8126")
           .install_batch(opentelemetry_sdk::runtime::Tokio)?;

   Ok(())
}