Skip to content

.tip

· one of the small things

recordException does not fail the span, setStatus does

span.recordException(err) attaches the stack as an event and leaves the status UNSET, which backends read as a success.

} catch (err) {
  span.recordException(err);
  span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
  throw err;
} finally {
  span.end();
}

Error-rate panels and tail sampling policies both filter on the status code, so a span carrying only the exception event is invisible to both. Leave the status alone for outcomes you expect, like a 404 on a lookup that is allowed to miss.

opentelemetryobservability