Rust event macros do not export correctly using the message field
Here's the rust code that I defined the export with
pub fn init_otlp_tracing(endpoint: &str) -> Result<sdktrace::Tracer, TraceError> {
let tracer = new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(endpoint),
)
.with_trace_config(
opentelemetry_sdk::trace::config().with_resource(Resource::new(vec![
opentelemetry::KeyValue::new(
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
"example-otlp",
),
])),
)
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
Ok(tracer)
}
This is my event macro
event!(target: "target", Level::INFO, name = "xxxx", severity = "severity", message="hello");
I have also conducted the following tests
let message = "hello";
event!(target: "target", Level::INFO, name = "xxxx", severity = "severity", message);
event!(target: "target", Level::INFO, name = "xxxx", severity = "severity", message = message);
event!(target: "target", Level::INFO, name = "xxxx", severity = "severity", message = %message);
But nothing has been gleaned from Collector about this. There are only two attributes, name and severity.
Yes,
message
is a special field.When you log with a tracing macro that uses
println!
-style content, it will be stored as a"message"
attribute. The following are equivalent:In your tests though, you aren't using the former syntax and your own
message
attribute gets passed as-is.When bridging from a tracing
Event
to an opentelemetryEvent
, the tracing-opentelemetry bidge will interpret the"message"
tracing attribute as the opentelemetry event name. I don't know what this means for the OLTP collector you are using, but it will likely appear separately from the rest of the attributes.