Skip to content
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

Fix: Ignore DiagnosticSource Integration if no Sampling available. #1238

Merged
merged 15 commits into from
Oct 12, 2021

Conversation

lucas-zimerman
Copy link
Collaborator

This PR solves two use cases.

  • The integration was being enabled despite TracesSampleRate being set to zero.
  • Spans were being created for Transactions that weren't going to be sent to Sentry.

The first issue is solved by disabling the integration during the application's startup if found that TracesSampleRate is set to zero.

The latter is fixed by not trying to retrieve/create a span if the current transaction is not being sampled.

@lucas-zimerman lucas-zimerman changed the title [DRAFT] Fix: Ignore DiagnosticSource Integration if no Sampling available. Fix: Ignore DiagnosticSource Integration if no Sampling available. Oct 5, 2021
@lucas-zimerman lucas-zimerman marked this pull request as ready for review October 5, 2021 14:11
@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Merging #1238 (81585a6) into main (5f5ef4a) will increase coverage by 0.02%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1238      +/-   ##
==========================================
+ Coverage   81.55%   81.57%   +0.02%     
==========================================
  Files         212      212              
  Lines        6971     7024      +53     
  Branches     1454     1463       +9     
==========================================
+ Hits         5685     5730      +45     
- Misses        838      846       +8     
  Partials      448      448              
Impacted Files Coverage Δ
...ce/Internals/DiagnosticSource/SentrySqlListener.cs 81.50% <77.55%> (-3.05%) ⬇️
...Internals/DiagnosticSource/SentryEFCoreListener.cs 88.75% <85.29%> (+1.95%) ⬆️
...osticSource/SentryDiagnosticListenerIntegration.cs 100.00% <100.00%> (+28.57%) ⬆️

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 5f5ef4a...81585a6. Read the comment docs.

Copy link
Contributor

@josh-degraw josh-degraw left a comment

Choose a reason for hiding this comment

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

Were the errant spans that were being created only happening for the SentryEFCoreListener and the SentrySqlListener?

@lucas-zimerman
Copy link
Collaborator Author

Were the errant spans that were being created only happening for the SentryEFCoreListener and the SentrySqlListener?

Yes

@lucas-zimerman
Copy link
Collaborator Author

As discussed here https://discord.com/channels/621778831602221064/621792783316942878/896041457264259103
DiagnosticSource spans will be created even if the transaction is not eligible/sampled.

@SimonCropp
Copy link
Contributor

@lucas-zimerman i took the liberty of handling the merge conflict on the pr.

But this looks good to me. A couple of minor comments above, but nothing that should block this one

@lucas-zimerman lucas-zimerman merged commit 4aa8f81 into main Oct 12, 2021
@lucas-zimerman lucas-zimerman deleted the fix/ignore-diagnosticsource-with-no-transactions branch October 12, 2021 14:28
_diagnosticListener = DiagnosticListener.AllListeners.Subscribe(_subscriber);
if (options.TracesSampleRate == 0)
{
options.DiagnosticLogger?.Log(SentryLevel.Info, "DiagnosticSource Integration is now disabled due to TracesSampleRate being set to zero.");
Copy link
Member

Choose a reason for hiding this comment

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

Prefer LogInfo instead of Log(Level.Info

if (options.TracesSampleRate == 0)
{
options.DiagnosticLogger?.Log(SentryLevel.Info, "DiagnosticSource Integration is now disabled due to TracesSampleRate being set to zero.");
options.DisableDiagnosticSourceIntegration();
Copy link
Member

Choose a reason for hiding this comment

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

THe integration instance was already called, why mutate options after the fact to remove it?
It's probably best to remove this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants