Skip to content

HTTP Traffic Logs

The SDK offers specialized logging APIs for capturing information about network requests. Exposed in the form of log method calls the APIs can be used to manually log information about each request and response.

Tip

The recommended way to add Capture logs for network traffic in an app is through Capture Networking Integrations integrations.

Kotlin
val requestInfo = HttpRequestInfo(
    host = "<endpoint_host>",
    path = HttpUrlPath("<endpoint_path>", "<endpoint_path_template>"),
    method = "<http_request_method>",
    headers = emptyMap(),
)
Logger.log(requestInfo)

val responseInfo = HttpResponseInfo(
    request = requestInfo,
    response = HttpResponse(
        result = HttpResponse.HttpResult.SUCCESS,
        statusCode = 200,
        headers = emptyMap(),
    ),
    durationMs = 500,
    metrics = HTTPRequestMetrics(
        requestBodyBytesSentCount = 1,
        responseBodyBytesReceivedCount = 2,
        requestHeadersBytesCount = 3,
        responseHeadersBytesCount = 3,
        dnsResolutionDurationMs = 1234,
    ),
)
Logger.log(responseInfo)
Java
HttpRequestInfo requestInfo = new HttpRequestInfo(
  "<endpoint_host>", //host
  HttpUrlPath("<endpoint_path>", "<endpoint_path_template>"), //path
  "<http_request_method>" //method
  Collections.emptyMap(), // HTTP headers
);
Logger.log(requestInfo);

HttpResponseInfo responseInfo = new HttpResponseInfo(
  requestInfo, //request
  new HttpResponse(
    HttpResponse.HttpResult.SUCCESS, //result
    200 //statusCode,
    Collections.emptyMap(), // HTTP headers
  ),
  500, //durationMs
  new HttpRequestMetrics(
    1, // requestBodyBytesSentCount
    2, // responseBodyBytesReceivedCount
    3, // requestHeadersBytesCount
    4, // responseHeadersBytesCount
    1234 // dnsResolutionDurationMs
  )
);
Logger.log(responseInfo);
Swift
let requestInfo = HTTPRequestInfo(
    host: "<endpoint_host>",
    path: HTTPURLPath(value: "<endpoint_path>", template: "endpoint_path_template"),
    method: "<http_request_method>",
    headers: [:],
)
Logger.log(requestInfo)

let responseInfo = HTTPResponseInfo(
    requestInfo: requestInfo,
    response: .init(
      result: .success,
      statusCode: 200,
      headers: [:],
      error: nil,
    ),
    duration: 0.5,
    metrics: .init(
      requestBodyBytesSentCount: 1,
      responseBodyBytesReceivedCount: 2,
      requestHeadersBytesCount: 3,
      responseHeadersBytesCount: 4,
      dnsResolutionDuration: 1.23
    )
)
Logger.log(responseInfo)

Fields

HTTP logs emitted with the use of HttpRequestInfo (Android) / HTTPRequestInfo (iOS) and HttpResponseInfo (Android) / HTTPResponseInfo (iOS) types contain multiple HTTP-specific fields outlined below.

The description of the specific fields discusses the intended values of these fields and how the Capture OkHttp (Android) and URLSession (iOS) integrations use these fields.

Request and response info objects can be manually initialized and logged by a customer of the Capture SDK. This flexibility means that depending on the values of the parameters passed to the initializers of these objects, the final values of the outlined fields may differ from what is described below.

When logging network traffic manually, reuse the same instance of HttpRequestInfo (Android) or HTTPRequestInfo (iOS) for logging both request and response information.

HTTP Request Fields

Field Name Field Key Example Values Notes
Method _method GET, POST
Host _host bitdrift.io
Path _path /v1/ping/123
Path Template _path_template /v1/ping/<id> A version of path with high-cardinality portions (if any) replaced with a a string placeholder (e.g., <id>). If a path template is not provided at the time of initialization, the SDK tries to find and replace high-cardinality portions of the path with the <id> placeholder on its own.
Protocol _protocol http/1.0, http/1.1, h2 The HTTP Protocol of the Request.
Query _query q=foo&source=bar
Request Body Size (Expected) _request_body_bytes_expected_to_send_count 123 The number of body bytes expected to be sent for a given request. On Android, it does not take into account any body payload modifications performed by the Interceptor chain (e.g. compression).
Span ID _span_id 8bcbbef6-7b3a-44c7-8c8e-47c5c15f2412 Each request-response pair shares the same span ID value.

HTTP Response Fields

Field Name Field Key Example Values Notes
Init Duration _fetch_init_duration_ms 55 Client time overhead before connecting.
TCP Duration _tcp_duration_ms 97 The cumulative duration of all TCP handshakes performed during the execution of a given HTTP request.
TLS Duration _tls_duration_ms 102 The cumulative duration of all TLS handshakes performed during the execution of a given HTTP request.
DNS Duration _dns_duration_ms 223 The duration of time the DNS query(ies) for a given request took. Present only on response logs for requests that triggered DNS lookups, as opposed to those that used previously cached DNS results (a common case).
Response Latency _response_latency_ms 865 The cumulative duration of all responses from the time the request is sent to the time we get the first byte from the server.
Duration _duration_ms 1342 The total roundtrip duration of a request / response pair.
Error Code _error_code -1009 Presents a code for client-side errors in cases where a request fails due to issues such as timeout or cancellation.
Error Message _error_message The Internet connection appears to be offline.
Host _host bitdrift.io
Method _method GET, POST
Path _path /v1/ping/123
Path Template _path_template /v1/ping/<id> A version of path with high-cardinality portions (if any) replaced with a a string placeholder (e.g., <id>). If a path template is not provided at the time of initialization, the SDK tries to find and replace high-cardinality portions of the path with the <id> placeholder on its own.
Protocol _protocol http/1.0, http/1.1, h2 The HTTP Protocol of the Response.
Query _query q=foo&source=bar
Request Body Size (Sent) _request_body_bytes_sent_count 1234 The number of request body bytes sent over-the-wire. It takes into account compression if one is used by the app.
Request Headers Size _request_headers_bytes_count 1234 The number of request headers bytes sent. This represents the over-the-wire bytes on iOS and an estimate of the over-the-wire bytes before they are compressed with HPACK on Android.
Response Body Size _response_body_bytes_received_count 1234 The number of response body bytes received over-the-wire.
Response Headers Size _response_headers_bytes_count 1234 The number of response headers bytes sent. This represents the over-the-wire bytes on iOS and an estimate of the over-the-wire bytes before they are compressed with HPACK on Android.
Result _result success, failure, canceled
Span ID _span_id 8bcbbef6-7b3a-44c7-8c8e-47c5c15f2412 Each request-response pair shares the same span ID value.
Status Code _status_code 200, 401 Present only if client receives a response from a server.