Skip to main content

TraceEvent

Derive Macro TraceEvent 

#[derive(TraceEvent)]
{
    // Attributes available to this derive:
    #[traceevent]
}
Available on crate feature dial9 only.
Expand description

Derives dial9_trace_format::TraceEvent for a struct with named fields.

Supported attributes:

  • #[traceevent(timestamp)] (field, required on exactly one u64 field): marks the event timestamp. It is encoded as a packed delta in the event header, not as a regular field.

  • #[traceevent(wire_slot)] (struct): opts the type into the encoder’s inline fast path by claiming a static wire-ID slot.

  • #[traceevent(name = <expr>)] (struct): overrides the wire event name (defaults to the struct name). Accepts any &'static str expression, not just a string literal, so callers can build a per-call-site-unique name — e.g. concat!("SpanEnter:", file!(), ":", line!()). Useful for generated structs that need a name the viewer recognizes (e.g. "SpanEnter:..."), which cannot be a valid Rust identifier.

  • #[traceevent(name = "...")] (field): overrides the field’s wire-schema name. This is useful for canonical names that are not valid Rust identifiers, such as "dial9.tokio.task_id".

  • #[traceevent(unit = "...")] (field): attaches a unit schema annotation so viewers render the field in that unit. Supported values: "ns", "us", "ms", "s", "bytes". Any other value is a compile error, as is placing unit on the timestamp field (the timestamp is encoded in the event header and is always nanoseconds).

  • #[traceevent(role = "...")] (field): attaches a dial9.role schema annotation, telling consumers what the field is structurally (e.g. "span.name"). The vocabulary lives in dial9_core::schema_extensions::roles; an unrecognized role is a compile error (it would otherwise decode as no role).

  • #[traceevent(kind = "...")] (field): attaches a kind schema annotation telling the viewer how to chart the field. Supported values: "gauge", "counter", "updown-counter". Any other value is a compile error, as is placing kind on the timestamp field.

A malformed or unrecognized traceevent key is a compile error. Only structs with named fields and at most one lifetime parameter are supported; type and const parameters are rejected.

§Example

#[derive(TraceEvent)]
struct RequestCompleted {
    #[traceevent(timestamp)]
    timestamp_ns: u64,
    #[traceevent(unit = "us")]
    latency_us: u64,
    status_code: u32,
}