Skip to content

Flutter network logs

The SDK captures the HTTP traffic of your Flutter app and adds it to the activity log that accompanies bug reports, crash reports and error reports, so you can see the request that failed before an issue. Requests made with dart:io, which package:http and Dio use by default, are captured automatically. With network monitoring enabled, the SDK also measures the performance of your requests across all users.

What gets captured

Network logging starts when the SDK is started. No other configuration is needed. It covers every HttpClient of dart:io that your app creates after start, and so the requests of:

  • package:http with its default client;
  • Dio with its default adapter;
  • any other package that sends its requests with dart:io.

Clients created before start are not captured, so create them after it. The SDK also captures requests that your app or its plugins send with the native HTTP stacks:

HTTP stack iOS Android
dart:io, package:http, Dio Captured Captured
cupertino_http, and plugins that use URLSession Captured, like in a native iOS app Not applicable
cronet_http, ok_http, native Dio adapters, and plugins that use their own HTTP client on Android Not applicable Not captured

On Android, the SDK captures native requests only of OkHttp clients that your Kotlin code sets up with the Appelium interceptor.

If your app sets HttpOverrides.global, set it before start; the SDK keeps the overrides that it finds. Overrides that you set later replace the SDK's, and requests of clients created inside HttpOverrides.runZoned with other overrides are not captured.

What an entry contains

  • the URL, method and status code. A redirected request is logged once, with the URL that your app requested;
  • request and response headers, in their order and with repeated names as separate fields. dart:io gives the SDK lowercase names;
  • request and response bodies, up to their first 25,000 characters, with the size of the whole body. Bodies with an image/* content type are counted but not logged;
  • the duration of the request, the server time from a Server-Timing header, the download time, and the transferred bytes. dart:io measures no DNS lookup, connection or TLS time.

Network logs are uploaded only as part of a bug, crash or error report.

Tip

If you already print network requests with print or a logging interceptor, you may want to stop doing so to avoid duplicate logs.

Redact sensitive data

Headers and bodies are logged as they are

By default, network logs contain complete headers, including Authorization and Cookie, and complete bodies. If your requests carry tokens, passwords or personal data, set an obfuscation handler before or right after start.

The quickest option is one of the built-in handlers:

// Keeps the URL with masked credentials, query values and fragment, the method and the status code; drops headers and bodies
AppeliumFeedback.networkRequestObfuscationHandler = const RejectSensitiveDataObfuscationHandler();

// Drops network logs completely
AppeliumFeedback.networkRequestObfuscationHandler = const RejectAllLogsObfuscationHandler();

The built-in handlers apply to every captured request, also to those of the native HTTP stacks, unless you set a native handler for them.

For full control, implement NetworkRequestObfuscationHandler. Both methods receive the captured value and return the version to log, or null to leave it out of the log:

class NetworkLogRedactor implements NetworkRequestObfuscationHandler {
  const NetworkLogRedactor();

  @override
  NetworkRequest? obfuscateNetworkRequest(NetworkRequest request) {
    return NetworkRequest(
      url: request.url,
      httpMethod: request.httpMethod,
      headerFields: [
        for (final header in request.headerFields)
          if (header.name.toLowerCase() != 'authorization') header,
      ],
    );
  }

  @override
  NetworkResponse? obfuscateNetworkResponse(NetworkResponse response) {
    return NetworkResponse(
      url: response.url,
      statusCode: response.statusCode,
      headerFields: [
        for (final header in response.headerFields)
          if (header.name.toLowerCase() != 'set-cookie') header,
      ],
      error: response.error,
    );
  }
}

AppeliumFeedback.networkRequestObfuscationHandler = const NetworkLogRedactor();
  • Returning null for a request leaves out the request and its response.
  • Returning null for a response leaves out only the response.
  • The handler applies to network logs in reports. Network monitoring metrics do not contain headers or bodies.

Requests of the native HTTP stacks

A handler that you implement in Dart applies to the requests of dart:io. The requests that the SDK captures from the native HTTP stacks, such as those of cupertino_http and plugins on iOS or of OkHttp clients with the Appelium interceptor on Android, are logged as they are, unless you also set a handler in your app's native code. Set it as early as possible, before Dart's main runs:

In ios/Runner/AppDelegate.swift, before application(_:didFinishLaunchingWithOptions:) calls super:

import AppeliumFeedbackKit

override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    AppeliumFeedback.networkRequestObfuscationHandler = NetworkLogRedactor()
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

NetworkLogRedactor implements the iOS handler.

In your MainActivity, with the native SDK as a dependency of your app module:

import android.os.Bundle
import com.appelium.feedback.AppeliumFeedback
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        AppeliumFeedback.networkRequestObfuscationHandler = NetworkLogRedactor()
        super.onCreate(savedInstanceState)
    }

}

NetworkLogRedactor implements the Android handler.

A native handler applies only to the native HTTP stacks; the Dart handler keeps applying to dart:io. With a built-in handler in Dart, you need no native one.

Network monitoring

Network monitoring adds aggregated performance metrics on top of the logs. Enable it in start:

AppeliumFeedback.start(
  apiKeys: apiKeys,
  networkMonitoring: NetworkMonitoringConfiguration.enabled,
);

For every captured request, the SDK records:

  • the host, method, URL path pattern and status code;
  • the timings that its HTTP stack measures: for dart:io, the request, server and download time;
  • the transferred bytes, the HTTP protocol and the connection type: Wi-Fi, wired Ethernet or, on cellular, the generation from 2G to 5G.

These metrics are uploaded when the app moves to the background, and they never include headers, bodies or query values. Requests to localhost and requests that your app cancelled are not included. Network monitoring is disabled while a native debugger is attached.

Use these to get more out of the metrics: