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.
15pub(crate) const DEFAULT_MAX_EVENT_PER_SPAN: u32 = 128;
16pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_SPAN: u32 = 128;
17pub(crate) const DEFAULT_MAX_LINKS_PER_SPAN: u32 = 128;
18pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_EVENT: u32 = 128;
19pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_LINK: u32 = 128;
20
21/// Span limit configuration to keep attributes, events and links to a span in a reasonable number.
22#[derive(Copy, Clone, Debug)]
23pub struct SpanLimits {
24 /// The max events that can be added to a `Span`.
25 pub max_events_per_span: u32,
26 /// The max attributes that can be added to a `Span`.
27 pub max_attributes_per_span: u32,
28 /// The max links that can be added to a `Span`.
29 pub max_links_per_span: u32,
30 /// The max attributes that can be added into an `Event`
31 pub max_attributes_per_event: u32,
32 /// The max attributes that can be added into a `Link`
33 pub max_attributes_per_link: u32,
34}
35
36impl Default for SpanLimits {
37 fn default() -> Self {
38 SpanLimits {
39 max_events_per_span: DEFAULT_MAX_EVENT_PER_SPAN,
40 max_attributes_per_span: DEFAULT_MAX_ATTRIBUTES_PER_SPAN,
41 max_links_per_span: DEFAULT_MAX_LINKS_PER_SPAN,
42 max_attributes_per_link: DEFAULT_MAX_ATTRIBUTES_PER_LINK,
43 max_attributes_per_event: DEFAULT_MAX_ATTRIBUTES_PER_EVENT,
44 }
45 }
46}