recordResponse method

void recordResponse({
  1. int? statusCode,
  2. int? responseSize,
  3. String? reasonPhrase,
})

Records a request the service answered.

A 4xx or 5xx becomes an exception event, not a span status. That is what the iOS Agent's own URLSessionInstrumentation does for the traffic it instruments, and the Plugin matches it so one fleet reads the same however a request was made (ADR-0016). exception.type is the status code and exception.message the reason phrase, as it does.

Note what this costs: an exception event becomes an APM error document, so every 4xx and 5xx counts toward a service's error rate. Neither span carries a failed status, so event.outcome on the exit span is derived from http.status_code at intake, and the Request Transaction stays unknown.

A null statusCode records nothing. Some transports type it nullable, and a code the Plugin did not receive is not one it can invent. reasonPhrase is likewise the transport's to supply, and absent rather than invented.

Implementation

void recordResponse({
  int? statusCode,
  int? responseSize,
  String? reasonPhrase,
}) {
  if (statusCode != null) {
    _span.setInt('http.status_code', statusCode);

    if (statusCode >= 400) {
      // The status code as the type, so a query can group by it — the Agent uses
      // the same shape. The phrase is the message when the transport supplied one.
      _span.recordException(
        reasonPhrase ?? 'HTTP $statusCode',
        type: '$statusCode',
      );
    }
  }

  if (responseSize != null) {
    _span.setInt('http.response_body.size', responseSize);
  }
}