tracing_serde_wire/
lib.rs

1//! # Wire types for use with tracing-serde-structured crate
2//!
3//! This crate contains a number of high level types that contain the individual
4//! [tracing-rs] event types that are created via the [tracing-serde-structured]
5//! crate.
6//!
7//! These types can be used as a simple "wire format" between a tracing subscriber
8//! which obtains and serializes the events, and a remote collector, which receives
9//! and deserializes the events
10//!
11//! [tracing-rs]: https://tracing.rs
12//! [tracing-serde-structured]: https://github.com/jamesmunns/tracing-serde-structured
13//!
14//! Currently, this crate contains no code, and only data type definitions.
15#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
16#![no_std]
17
18use serde::{Serialize, Deserialize};
19
20use tracing_serde_structured::{
21    SerializeAttributes,
22    SerializeRecord,
23    SerializeEvent,
24    SerializeId,
25};
26
27/// Tracing Wire "Other" messages
28///
29/// This type contains messages that are not directly sourced from tracing events,
30/// but are sometimes necessary during establishing or maintaining of the connection.
31#[derive(Debug, Serialize, Deserialize)]
32pub enum TWOther {
33    /// One or more events have been discarded without being transmitted via a `Packet`.
34    /// This is used when the local buffer has become full, and it was no longer possible
35    /// to transmit the stream of events uninterrupted.
36    MessageDiscarded,
37
38    /// A collection of metadata items about the device that is producing trace events.
39    DeviceInfo {
40        clock_id: u32,
41        ticks_per_sec: u32,
42        device_id: [u8; 16],
43    },
44}
45
46/// A tracing wire Packet type
47///
48/// This type is the "outer wrapper", typically sent as the single message on the wire.
49/// Devices producing tracing messages will emit a stream of Packets, which will be
50/// individually processed by the remote collector
51#[derive(Debug, Serialize, Deserialize)]
52pub struct Packet<'a> {
53    #[serde(borrow)]
54    pub message: TracingWire<'a>,
55    pub tick: u64,
56}
57
58/// The tracing wire event enumeration
59///
60/// This enumeration contains all possible event kinds that are produced by tracing-rs,
61/// plus a `TWOther` variant for non-tracing metadata to be sent.
62#[derive(Debug, Serialize, Deserialize)]
63#[non_exhaustive]
64pub enum TracingWire<'a> {
65    NewSpan {
66        id: SerializeId,
67        #[serde(borrow)]
68        attrs: SerializeAttributes<'a>,
69        values: SerializeRecord<'a>,
70    },
71    Record {
72        values: SerializeRecord<'a>,
73        span: SerializeId,
74    },
75    RecordFollowsFrom {
76        follows: SerializeId,
77        span: SerializeId,
78    },
79    Event(SerializeEvent<'a>),
80    Enter(SerializeId),
81    Exit(SerializeId),
82    Close(SerializeId),
83    IdClone {
84        new: SerializeId,
85        old: SerializeId,
86    },
87    Other(TWOther),
88}