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

Generate errors from OpenTelemetry data #31

Open
3 of 8 tasks
AbhiPrasad opened this issue Feb 13, 2023 · 3 comments
Open
3 of 8 tasks

Generate errors from OpenTelemetry data #31

AbhiPrasad opened this issue Feb 13, 2023 · 3 comments
Labels
Grooming Backlog Grooming Candidate

Comments

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Feb 13, 2023

In OpenTelemetry, spans can have exception events.

Let's create Sentry errors from these exception events and send them to Sentry! We can link them to the parent transaction via trace context.

Span span = myTracer.startSpan(/*...*/);
try {
  // Code that does the actual work which the Span represents
} catch (Throwable e) {
  span.recordException(e, Attributes.of("exception.escaped", true));
  throw e;
} finally {
  span.end();
}

The advantage of doing this is that we'll get this working out of the box for users who already have errors instrumented with OpenTelemetry.

OpenTelemetry Exceptions

  1. AbhiPrasad
  2. AbhiPrasad
  3. AbhiPrasad
@AbhiPrasad
Copy link
Member Author

Here's a basic JavaScript example to make this work.

otelSpan.events.forEach(event => {
  if (event.name === 'exception') {
    const attributes = event.attributes;
    if (attributes) {
      const message = attributes[SemanticAttributes.EXCEPTION_MESSAGE] as string;

      const syntheticError = new Error(message);
      syntheticError.stack = attributes[SemanticAttributes.EXCEPTION_STACKTRACE] as string;
      syntheticError.name = attributes[SemanticAttributes.EXCEPTION_TYPE] as string;

      hub.captureException(syntheticError, {
        captureContext: {
          contexts: {
            trace: {
              trace_id: otelSpan.spanContext().traceId,
              span_id: otelSpan.spanContext().spanId,
              parent_span_id: otelSpan.parentSpanId,
            },
          },
        },
      });
    }
  }
});

@smeubank
Copy link
Member

@AbhiPrasad anyway this could be done server side?

@AbhiPrasad
Copy link
Member Author

We don't attach this information in any way on spans (the sentry schema for spans has no concept for events), so currently no.

@stephanie-anderson stephanie-anderson added the Grooming Backlog Grooming Candidate label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Grooming Backlog Grooming Candidate
Projects
Development

No branches or pull requests

3 participants