-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add max_attributes_per_event and max_attributes_per_link. #521
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d73a4b5
feat: add max_attributes_per_event and max_attributes_per_link.
TommyCpp 5269e8a
fix: bugs, add unit tests.
TommyCpp 816f1d7
fix: format
TommyCpp f409212
fix: use truncate instead of drain.
TommyCpp c58a9d6
feat: add span limit.
TommyCpp d3fa480
fix: rename SpanLimit to SpanLimits
TommyCpp be8636c
fix: make span limits non optional.
TommyCpp 90df68a
Merge branch 'main' into tommycpp/span_limit
jtescher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// # Span limit | ||
/// Erroneous code can add unintended attributes, events, and links to a span. If these collections | ||
/// are unbounded, they can quickly exhaust available memory, resulting in crashes that are | ||
/// difficult to recover from safely. | ||
/// | ||
/// To protected against those errors. Users can use span limit to configure | ||
/// - Maximum allowed span attribute count | ||
/// - Maximum allowed span event count | ||
/// - Maximum allowed span link count | ||
/// - Maximum allowed attribute per span event count | ||
/// - Maximum allowed attribute per span link count | ||
/// | ||
/// If the limit has been breached. The attributes, events or links will be dropped based on their | ||
/// index in the collection. The one added to collections later will be dropped first. | ||
|
||
pub(crate) const DEFAULT_MAX_EVENT_PER_SPAN: u32 = 128; | ||
pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_SPAN: u32 = 128; | ||
pub(crate) const DEFAULT_MAX_LINKS_PER_SPAN: u32 = 128; | ||
pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_EVENT: u32 = 128; | ||
pub(crate) const DEFAULT_MAX_ATTRIBUTES_PER_LINK: u32 = 128; | ||
|
||
/// Span limit configuration to keep attributes, events and links to a span in a reasonable number. | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct SpanLimits { | ||
/// The max events that can be added to a `Span`. | ||
pub max_events_per_span: u32, | ||
/// The max attributes that can be added to a `Span`. | ||
pub max_attributes_per_span: u32, | ||
/// The max links that can be added to a `Span`. | ||
pub max_links_per_span: u32, | ||
/// The max attributes that can be added into an `Event` | ||
pub max_attributes_per_event: u32, | ||
/// The max attributes that can be added into a `Link` | ||
pub max_attributes_per_link: u32, | ||
} | ||
|
||
impl Default for SpanLimits { | ||
fn default() -> Self { | ||
SpanLimits { | ||
max_events_per_span: DEFAULT_MAX_EVENT_PER_SPAN, | ||
max_attributes_per_span: DEFAULT_MAX_ATTRIBUTES_PER_SPAN, | ||
max_links_per_span: DEFAULT_MAX_LINKS_PER_SPAN, | ||
max_attributes_per_link: DEFAULT_MAX_ATTRIBUTES_PER_LINK, | ||
max_attributes_per_event: DEFAULT_MAX_ATTRIBUTES_PER_EVENT, | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be optional? Could switch tests to use
Default::default()
instead ofNone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
span_limit
isNone
. Then we will try to get the span limit from the tracer provider. If there isn't a tracer provider connected with the tracer, we will use the default.Sometimes we may change the
span_limit
during the span building(For example, we may record the number of dropped entities in the future) so we may pass modified span_limit. But we want to keep the span limit the same as the tracer provider, we can passNone
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yeah we should store them somewhere. Maybe best path is to have
SpanLimits
not be optional here and add dropped counts toSpanData
? keeps things simple and tracks attribute drops without having to upgrade the provider.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. I removed the option around
SpanLimits
. I probably would open another PR to address how to record and expose the number of dropped entities.