Skip to content

Experiment: Thrown errors passing through startSpan should be associated with first passed through span #16206

Description

@lforst

Description

Today, an error is only associated with the span that was active at the time captureException(err) was called. This leads to interesting situations like the following:

function foo() {
  startSpan({ name: "foo" }, () => { // <-- Error will be associated with this span, even though it was thrown in the "bar" span
    try {
      bar();
    } catch (e) {
      captureException(e);
    }
  });
}

function bar() {
  startSpan({ name: "bar" }, () => {
    throw new Error();
  });
}

We could experiment with adding a try-catch to the startSpan wrappers that writes a non-enumerable span ID to errors that pass through (if they didn't have one yet), which is then picked up and preferred by the error processing pipeline over the span ID that is on the scope.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions