opentelemetry_sdk/trace/
span_limit.rs

1/// # Span limit
2/// Erroneous code can add unintended attributes, events, and links to a span. If these collections
3/// are unbounded, they can quickly exhaust available memory, resulting in crashes that are
4/// difficult to recover from safely.
5///
6/// To protected against those errors. Users can use span limit to configure
7///  - Maximum allowed span attribute count
8///  - Maximum allowed span event count
9///  - Maximum allowed span link count
10///  - Maximum allowed attribute per span event count
11///  - Maximum allowed attribute per span link count
12///
13/// If the limit has been breached. The attributes, events or links will be dropped based on their
14/// index in the collection. The one added to collections later will be dropped first.
15
16pub(crate) const DEFAULT_MAX_EVENT_PER_SPAN: u32 = 128;
17pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_SPAN: u32 = 128;
18pub(crate) const DEFAULT_MAX_LINKS_PER_SPAN: u32 = 128;
19pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_EVENT: u32 = 128;
20pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_LINK: u32 = 128;
21
22/// Span limit configuration to keep attributes, events and links to a span in a reasonable number.
23#[derive(Copy, Clone, Debug)]
24pub struct SpanLimits {
25    /// The max events that can be added to a `Span`.
26    pub max_events_per_span: u32,
27    /// The max attributes that can be added to a `Span`.
28    pub max_attributes_per_span: u32,
29    /// The max links that can be added to a `Span`.
30    pub max_links_per_span: u32,
31    /// The max attributes that can be added into an `Event`
32    pub max_attributes_per_event: u32,
33    /// The max attributes that can be added into a `Link`
34    pub max_attributes_per_link: u32,
35}
36
37impl Default for SpanLimits {
38    fn default() -> Self {
39        SpanLimits {
40            max_events_per_span: DEFAULT_MAX_EVENT_PER_SPAN,
41            max_attributes_per_span: DEFAULT_MAX_ATTRIBUTES_PER_SPAN,
42            max_links_per_span: DEFAULT_MAX_LINKS_PER_SPAN,
43            max_attributes_per_link: DEFAULT_MAX_ATTRIBUTES_PER_LINK,
44            max_attributes_per_event: DEFAULT_MAX_ATTRIBUTES_PER_EVENT,
45        }
46    }
47}