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.

Separate root scope used on the finalizer thread

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? sentry.dotnet.serilog 3.3.4 sentry.dotnet.nlog 2.1.8

Steps to Reproduce

  1. Call logger.Debug("debug messages")
  2. Call Task.Run(()=>{ throw new Exception(); });

Minimal proof of concept repo: https://github.com/Genteure/SentryMissingBreadcrumbPoc

Expected Result

“debug messages” is visible on sentry dashboard as breadcrumb.

image

Actual Result

No breadcrumb is available.

image

The exception is not added to breadcrumb either.

image

Screenshots from my published application:

This is from a older version that uses NLog instead of Serilog I disabled sentry’s UnhanledException integration via DisableAppDomainUnhandledExceptionCapture(), capturing errors by routing exceptions through NLog or Serilog so it would also be saved in log files. image

Previous errors from TaskScheduler.UnobservedTaskException are sent as breadcrumb, but all other messages are missing. image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
bruno-garciacommented, Jun 18, 2021

We’ll address this through: #628 and we plan to tackle it soon

0reactions
bruno-garciacommented, Dec 7, 2021

I meant “doesn’t it”? Yes, that’s my understanding, as expanded:

Once it finds no catch block to handle, it invokes the event handlers

The reasoning described earlier on this thread makes sense. That in the case of the finalizer thread, the scope from the AsyncLocal isnt’ available. I don’t believe there’s a work around to propagate the scope from one async local into the finalizer thread but if you’d be OK with a global scope, this could sorted out through #628 #448 which needs to land for desktop and mobile scenarios where scope data is fairly global.

We’ve implemented global scope:

The way the Sentry SDK handles scopes is so that different threads and async flows have different scopes. You can change that behavior (and arguably it should be something we do by default for WPF and WinForms apps) to have a single, global scope.

That means that anywhere you call ConfigureScope, will affect any event, happening in any thread. One side effect though is that SentrySdk.WithScope will no longer work. We have an issue to introduce an alternative:

You can turn on global mode with: https://github.com/getsentry/sentry-dotnet/blob/41cf450f3000f7a2a0311d85011a4ca5bbacd56a/src/Sentry/SentryOptions.cs#L33

SentrySdk.Init(o => {
o.Dsn = ..;
o.IsGlobalModeEnabled = true);
});

Please note we’ll make that the default for desktop apps like WPF and WinForms through:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can java finalize an object when it is still in scope?
What I think is happening is that a is getting detected as having no references after the second line of main() and getting...
Read more >
Make Scope data global on desktop and mobile · Issue #628
I wanted to track events and I was receiving them through different callbacks on different threads. As a workaround I ended up creating...
Read more >
When everything you know is wrong, part two
The finalizer thread runs the finalizers, the GC thread identifies dead objects that do not need finalization and reclaims their memory.
Read more >
NET Matters: Debugging finalizers
Debugging finalizers. Stephen Toub. Q I have a bunch of custom types that, for one reason or another, need to implement IDisposable.
Read more >
Finalization - Chris Brumme's Weblog
We currently use a single high priority Finalizer thread to walk the ReadyToFinalize queue. This thread dequeues each object, executes its ...
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