applyResponse method

void applyResponse({
  1. required int statusCode,
  2. String? reasonPhrase,
  3. String? protocolVersion,
})

Implementation

void applyResponse({
  required int statusCode,
  String? reasonPhrase,
  String? protocolVersion,
}) {
  _hasResponse = true;
  span.setAttribute(
    Attribute.fromInt('http.response.status_code', statusCode),
  );
  if (reasonPhrase != null) {
    span.setAttribute(Attribute.fromString('http.status_text', reasonPhrase));
  }
  span.setAttribute(
    Attribute.fromString(
      'network.protocol.version',
      protocolVersion ?? '1.1',
    ),
  );

  if (statusCode >= 400) {
    span.setAttribute(
      Attribute.fromString('error.type', statusCode.toString()),
    );
    span.setAttribute(
      Attribute.fromString('http.error.category', 'http_client'),
    );
    span.setStatus(StatusCode.error, 'HTTP $statusCode');
  }
}