Skip to content

Disable tracing if events are not allowed to be sent#1421

Merged
st0012 merged 2 commits intomasterfrom
disable-tracing-when-sending-is-not-allowed
Apr 29, 2021
Merged

Disable tracing if events are not allowed to be sent#1421
st0012 merged 2 commits intomasterfrom
disable-tracing-when-sending-is-not-allowed

Conversation

@st0012
Copy link
Copy Markdown
Contributor

@st0012 st0012 commented Apr 28, 2021

Users can enable/disable the SDK's event sending with enabled_environments config option. And when the current environment doesn't match the enabled_environments, the SDK will not send any events. But currently, the SDK would still start transactions under such condition.

Even though those transactions would not be sent later (stopped by Client#send_event), it'd still create sampling logs, which are noisy and confusing to users.

So this commit fixes the issue by making tracing activation aware of the event sending state.

@st0012 st0012 added this to the 4.4.0 milestone Apr 28, 2021
@st0012 st0012 requested a review from rhcarvalho April 28, 2021 13:38
@st0012 st0012 self-assigned this Apr 28, 2021
@st0012 st0012 changed the title Stop sampling if events are not allowed to be sent Stop transaction sampling if events are not allowed to be sent Apr 28, 2021
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 28, 2021

Codecov Report

Merging #1421 (80a2c30) into master (74d082b) will increase coverage by 0.61%.
The diff coverage is 99.05%.

❗ Current head 80a2c30 differs from pull request most recent head 0b308af. Consider uploading reports for the commit 0b308af to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1421      +/-   ##
==========================================
+ Coverage   98.21%   98.83%   +0.61%     
==========================================
  Files         213      118      -95     
  Lines        9920     6173    -3747     
==========================================
- Hits         9743     6101    -3642     
+ Misses        177       72     -105     
Impacted Files Coverage Δ
sentry-ruby/spec/sentry_spec.rb 99.61% <98.63%> (-0.39%) ⬇️
sentry-ruby/lib/sentry/configuration.rb 97.93% <100.00%> (ø)
sentry-ruby/spec/sentry/configuration_spec.rb 98.75% <100.00%> (+0.07%) ⬆️
sentry-rails/lib/sentry/rails/active_job.rb 97.05% <0.00%> (-0.09%) ⬇️
sentry-rails/lib/sentry/rails/configuration.rb 100.00% <0.00%> (ø)
...-sidekiq/spec/sentry/sidekiq/error_handler_spec.rb 100.00% <0.00%> (ø)
...entry-raven/lib/raven/breadcrumbs/sentry_logger.rb
sentry-raven/lib/raven/base.rb
sentry-raven/spec/raven/logger_spec.rb
sentry-raven/lib/raven/core_ext/object/deep_dup.rb
... and 91 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74d082b...0b308af. Read the comment docs.

Copy link
Copy Markdown
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I generally understood the problem this is trying to solve and the current solution addresses the problem. 👍

However there's one violation of the sampling rules, and we need to sync on how the config of the SDK works with regards to tracing.

it "sets @sampled to false and return" do
transaction = described_class.new(sampled: true, hub: Sentry.get_current_hub)
transaction.set_initial_sample_decision(sampling_context: {})
expect(transaction.sampled).to eq(false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about this for a while. At first I thought neither true nor false fit here, because both of those mean a sampling decision was actually made, in which case nil would be more appropriate.

However, the sampling rule is that explicit sample decision always has precedence:

  1. If a sampling decision is passed to startTransaction (startTransaction({name: "my transaction", sampled: true})), that decision will be used, regardlesss of anything else

So in this particular example, since the sampling decision was passed to .new, it should not have changed.

In any case, tracing is effectively disabled, startTransaction should not instantiate transactions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed the decision making issue in #1423

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @st0012. I've chatted with the team and looked at code in other SDKs, I retract my comment for now.
Python and JS do exactly as Ruby does now, despite not adhering 100% to the spec as written.
So instead of going back and forth with this, let's just leave it as it is for now, and revisit it later as we rethink tracing as a whole.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I implemented this behavior based on what I saw in sentry-python. I thought the spec you posted was to correct that.

Users can enable/disable the SDK's event sending with
`enabled_environments` config option. And when the current environment
doesn't match the `enabled_environments`, the SDK will not send any
events. But currently, the SDK would still start transactions under such
condition.

Even though those transactions would not be sent later (stopped by
`Client#send_event`), it'd still create sampling logs, which are noisy
and confusing to users.

So this commit fixes the issue by making tracing activation aware of the
event sending state.
@st0012 st0012 changed the title Stop transaction sampling if events are not allowed to be sent Disable tracing if events are not allowed to be sent Apr 29, 2021
@st0012 st0012 force-pushed the disable-tracing-when-sending-is-not-allowed branch from 01e68ed to 15458a3 Compare April 29, 2021 13:17
@st0012 st0012 merged commit ace176c into master Apr 29, 2021
@st0012 st0012 deleted the disable-tracing-when-sending-is-not-allowed branch April 29, 2021 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants