question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Callback not called when sentry is not registered

See original GitHub issue

Package

Sentry

.NET Flavor

.NET

.NET Version

6.0.0

OS

Any (not platform specific)

SDK Version

3.33.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

We have some internal nuget packages that integrate with Sentry if sentry is registered. We currently do something like:

hub = serviceProvider.GetService<IHub>() ?? HubAdapter.Instance;

Now when calling WithScopeAsync when Sentry has not been registered in the .net core app, the code is not called:

await _hub.WithScopeAsync(async scope =>
    ... //This code is not called if sentry is not registered
);

I tracked it down to this line of code: https://github.com/getsentry/sentry-dotnet/blob/410b30d2ce0c4db93c050778249b0d812aff089c/src/Sentry/SentryScopeManagerExtensions.cs#L52

Expected Result

Code is being called even if sentry is not registered

Actual Result

Code is not being called

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Vandersteencommented, Aug 7, 2023

Thanks for the tips, I’ll have a look.

I guess as the original issue is ‘resolved’ you can go ahead and close this ticket.

I would still be awesome if the callback was still called, but for now we’ll work around that

0reactions
jamescrosswellcommented, Aug 7, 2023

I haven’t played too much with the settings (so MaxBreadcrumbs is the default I guess)

OK. That, at the very least, puts a cap on the number of breadcrumbs that can pile up. You’ll only ever have a maximum of 100 per scope (by default). So memory consumption on the application won’t grow indefinitely.

You still have a practical problem of ensuring that you have all the relevant breadcrumbs and they’re not drowned out in the noise of a bunch of irrelevant logs.

There are a couple of tools at your disposal there.

You can set minimum levels when configuring logging:

Log.Logger = new LoggerConfiguration()
  .WriteTo.Sentry(o =>
  {
    // Debug and higher are stored as breadcrumbs (default is Information)
    o.MinimumBreadcrumbLevel = LogEventLevel.Debug;
    // Warning and higher is sent as event (default is Error)
    o.MinimumEventLevel = LogEventLevel.Warning;
  })
  .CreateLogger();

Another is the SetBeforeBreadcrumb hook but you need some way to sift the logs/breadcrumbs you’re interested in from those you’re not. I’m not sure I have any silver bullets there… it might be a matter of playing around to see if there are any obvious markers in combinations of things like Breadcrumb.Type, Breadcrumb.Category or possibly information stored in the Breadcrumb.Data dictionary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering for Spring - Java
Filtering Error Events. Configure your SDK to filter error events by using the beforeSend callback method and configuring, enabling, or disabling integrations.
Read more >
Airflow Not Sending Errors to Sentry Automatically
(I am confident that the sentry_dsn value works, as our code has custom code that we use in failure callbacks that does send...
Read more >
Surpressing issues from going to Sentry
I would like to block a few events from going to Sentry using the before_send callback, however the events kept on showing on...
Read more >
Sentry in Nova no always propagating correctly
The proposed changes allow the user to specify a callback to report Nova's errors to services like Sentry, Bugsnag, etc. Copy Nova::report(function ($exception) ......
Read more >
Unified API - Sentry Developer Documentation
In this case, certain callbacks, such as configure_scope or event processors, may not be invoked. As a result, breadcrumbs are not recorded.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found