-
Notifications
You must be signed in to change notification settings - Fork 498
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
Enable back pressure monitor in Potel #3602
Open
antonpirker
wants to merge
3
commits into
potel-base
Choose a base branch
from
antonpirker/potel/back-pressure
base: potel-base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from random import random | ||
import random | ||
|
||
from opentelemetry import trace | ||
|
||
|
@@ -45,6 +45,18 @@ def dropped_result(span_context): | |
# type: (SpanContext) -> SamplingResult | ||
trace_state = span_context.trace_state.update(SENTRY_TRACE_STATE_DROPPED, "true") | ||
|
||
# Tell Sentry why we dropped the transaction/span | ||
client = sentry_sdk.get_client() | ||
if client.monitor and client.monitor.downsample_factor > 0: | ||
reason = "backpressure" | ||
else: | ||
reason = "sample_rate" | ||
|
||
client.transport.record_lost_event(reason, data_category="transaction") | ||
|
||
# Only one span (the transaction itself) is discarded, since we did not record any spans here. | ||
client.transport.record_lost_event(reason, data_category="span") | ||
|
||
return SamplingResult( | ||
Decision.DROP, | ||
trace_state=trace_state, | ||
|
@@ -107,6 +119,11 @@ def should_sample( | |
# Check if there is a traces_sample_rate | ||
sample_rate = client.options.get("traces_sample_rate") | ||
|
||
# Down-sample in case of back pressure monitor says so | ||
# TODO: this should only be done for transactions (aka root spans) | ||
if client.monitor: | ||
sample_rate /= 2**client.monitor.downsample_factor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this below the |
||
|
||
# If the sample rate is invalid, drop the span | ||
if not is_valid_sample_rate(sample_rate, source=self.__class__.__name__): | ||
logger.warning( | ||
|
@@ -115,7 +132,7 @@ def should_sample( | |
return dropped_result(parent_span_context) | ||
|
||
# Roll the dice on sample rate | ||
sampled = random() < float(sample_rate) | ||
sampled = random.random() < float(sample_rate) | ||
|
||
# TODO-neel-potel set sample rate as attribute for DSC | ||
if sampled: | ||
|
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
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.
to match the logic in the earlier tracing impl, we should rather do this at the end of the transaction flow, so I'd not do this here but in span processor
on_end
and only for the root span case. Here it will apply to every span and the numbers will be wrong.