onError method

void onError(
  1. Object error, [
  2. StackTrace? stackTrace,
  3. String? errorCategory
])

Implementation

void onError(Object error, [StackTrace? stackTrace, String? errorCategory]) {
  span.recordException(error, stackTrace: stackTrace ?? StackTrace.current);

  // No HTTP response was ever received: report status 0 so failure
  // classification can separate transport failures from 4xx/5xx responses.
  if (!_hasResponse) {
    span.setAttribute(Attribute.fromInt('http.response.status_code', 0));
  }

  final category = errorCategory ?? classifyError(error);
  span.setAttribute(
    Attribute.fromString('error.type', error.runtimeType.toString()),
  );
  span.setAttribute(Attribute.fromString('http.error.category', category));
  span.setStatus(StatusCode.error, error.toString());
}