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.

When capturing events with exception, link to current trace

See original GitHub issue

Regarding: https://github.com/getsentry/sentry-dotnet/pull/848#discussion_r582439193

If the current Span is already mapped to a different exception (via BindException/span.Finish(ex)), what should happen?

Also, if the current span on scope is the root transaction, but the exception is bound to some nested Span (or maybe even Span that’s not part of the bound Transaction), what should happen?

There are probably other similar edge cases.

@bruno-garcia

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Tyrrrzcommented, Mar 26, 2021

@bruno-garcia thanks, I think it’s clear now.

The second use case is already supported I believe. I will implement the first use case.

0reactions
bruno-garciacommented, Mar 26, 2021

Maciej helped me remember the original issue. I think it’s about being able to do this:

var span = hub.GetSpan()?.StartTransaction(...);

try
{
    // ...
}
catch (Exception ex)
{
    Sentry.CaptureException(ex);
}

// Not providing exception here
// It's automatically bound to the last captured exception
span?.Finish();

@bruno-garcia is this right?

That exception was captured within the scope of the open span, which is available on the Scope. So capturing the exception can copy the scope.context.trace information into the error event. That span is not connected to error that way, we don’t need to add anything from the error into the span.

This is one use case. There’s a second:

try {
Work();
catch (e) {
CaptureException(e);
}

Work() {
var child = span.startChild();
try {
throw null;
child.finish(); // assumes finishes with OK.
} catch(e){
child.finish(error);
throw;
}
}

With the snippet above, the transaction will be finished and flushed by the time the exception is rethrown. This means we’ll never know “within which span” let alone the trace that exception happened. The idea is to:

Work() {
var transaction = span.startTransaction();
try {
throw null;
transaction.finish(); // assumes finishes with OK.
} catch(e){
transaction.finish(e); // now the span has a reference to the Exception
throw;
}
}

The idea is to hold that Exception instance in a WeakRefMap so when we CaptureException(e) we can look up that exception by reference to get the Span instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExceptionDispatchInfo.Capture(Exception) Method
If the exception is active when it's captured, the current stack trace information and Watson information that's contained in the exception is stored....
Read more >
Can I get a stack trace when I catch an exception (Like I do ...
NullPointerException: Attempt to de-reference a null object. Is there any way to get the full stack trace from the Exception in the catch?...
Read more >
Capturing exceptions in OpenTelemetry .NET and Sentry.io
This is a bug in that has been fixed in Sentry.OpenTelemetry version 3.35.0. For full details see pull request #2515 but the TLDR; ......
Read more >
Tracing API - open-telemetry/opentelemetry-specification
the Span becomes non-recording by being ended (there might be exceptions when Tracer is streaming events and has no mutable state associated with...
Read more >
Bubbling and capturing
If an element has multiple event handlers on a single event, then even if one of them stops the bubbling, the other ones...
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