Open AbhiPrasad opened 1 year ago
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,
},
},
},
});
}
}
});
@AbhiPrasad anyway this could be done server side?
We don't attach this information in any way on spans (the sentry schema for spans has no concept for events), so currently no.
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.
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.