<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionTaskTransactionMetrics",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSessionTaskTransactionMetrics"
  },
  "title" : "URLSessionTaskTransactionMetrics"
}
-->

# URLSessionTaskTransactionMetrics

An object that encapsualtes the performance metrics collected by the URL Loading System during the execution of a session task.

```
class URLSessionTaskTransactionMetrics
```

## Overview

Each [`URLSessionTaskTransactionMetrics`](/documentation/Foundation/URLSessionTaskTransactionMetrics) object consists of a [`request`](/documentation/Foundation/URLSessionTaskTransactionMetrics/request) and [`response`](/documentation/Foundation/URLSessionTaskTransactionMetrics/response) property, corresponding to the request and response of the corresponding task. It also contains temporal metrics, starting with [`fetchStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/fetchStartDate) and ending with [`responseEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/responseEndDate), as well as other characteristics like [`networkProtocolName`](/documentation/Foundation/URLSessionTaskTransactionMetrics/networkProtocolName) and [`resourceFetchType`](/documentation/Foundation/URLSessionTaskTransactionMetrics/resourceFetchType).

### Understanding temporal metrics

The figure below shows the sequence of events for a URL session task, which correspond to the temporal metrics captured by [`URLSessionTaskTransactionMetrics`](/documentation/Foundation/URLSessionTaskTransactionMetrics).

![Diagram showing the temporal metrics for a URL session task. When a task starts, it performs a DNS lookup and then starts a connection. If the connection is encrypted, the user agent starts a TLS security handshake to secure the connection. After the connection to the server is established, the user agent requests the specified resource, and receives a response.](images/com.apple.foundation/media-3162616@2x.png)

For all metrics with a start and end date, if an aspect of the task was not completed, then its corresponding end date metric is `nil`. This can happen if name lookup begins, but the operation either times out, fails, or the client cancels the task before the name can be resolved. In this case, the [`domainLookupEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/domainLookupEndDate) property is `nil`, along with all metrics for aspects that occurred afterwards.

### Measuring tasks using iCloud Private Relay

iCloud Private Relay can change the timing and sequence of events for your tasks by sending requests through a set of privacy proxies. All tasks that use iCloud Private Relay set the [`isProxyConnection`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isProxyConnection) property in their transaction metrics. In this case, the [`remoteAddress`](/documentation/Foundation/URLSessionTaskTransactionMetrics/remoteAddress) property contains the address of the proxy, and not the origin server.

Tasks to different hosts can reuse the same transport connection, just like how tasks can already share a connection when using HTTP/2. In these cases, a proxied task may not report any [`secureConnectionStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/secureConnectionStartDate) or [`secureConnectionEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/secureConnectionEndDate).

## Topics

### Accessing request and response

[`request`](/documentation/Foundation/URLSessionTaskTransactionMetrics/request)

The transaction request.

[`response`](/documentation/Foundation/URLSessionTaskTransactionMetrics/response)

The transaction response.

### Accessing temporal metrics

[`fetchStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/fetchStartDate)

The time when the task started fetching the resource, from the server or locally.

[`domainLookupStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/domainLookupStartDate)

The time immediately before the task started the name lookup for the resource.

[`domainLookupEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/domainLookupEndDate)

The time after the name lookup was completed.

[`connectStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/connectStartDate)

The time immediately before the task started establishing a TCP connection to the server.

[`secureConnectionStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/secureConnectionStartDate)

The time immediately before the task started the TLS security handshake to secure the current connection.

[`secureConnectionEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/secureConnectionEndDate)

The time immediately after the security handshake completed.

[`connectEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/connectEndDate)

The time immediately after the task finished establishing the connection to the server.

[`requestStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/requestStartDate)

The time immediately before the task started requesting the resource, regardless of whether it is retrieved from the server or local resources.

[`requestEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/requestEndDate)

The time immediately after the task finished requesting the resource, regardless of whether it was retrieved from the server or local resources.

[`responseStartDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/responseStartDate)

The time immediately after the task received the first byte of the response from the server or from local resources.

[`responseEndDate`](/documentation/Foundation/URLSessionTaskTransactionMetrics/responseEndDate)

The time immediately after the task received the last byte of the resource.

### Accessing data transfer metrics

[`countOfRequestBodyBytesBeforeEncoding`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfRequestBodyBytesBeforeEncoding)

The size of the upload body data, file, or stream, in bytes.

[`countOfRequestBodyBytesSent`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfRequestBodyBytesSent)

The number of bytes transferred for the request body.

[`countOfRequestHeaderBytesSent`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfRequestHeaderBytesSent)

The number of bytes transferred for the request header.

[`countOfResponseBodyBytesAfterDecoding`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfResponseBodyBytesAfterDecoding)

The size of data delivered to your delegate or completion handler.

[`countOfResponseBodyBytesReceived`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfResponseBodyBytesReceived)

The number of bytes transferred for the response body.

[`countOfResponseHeaderBytesReceived`](/documentation/Foundation/URLSessionTaskTransactionMetrics/countOfResponseHeaderBytesReceived)

The number of bytes transferred for the response header.

### Accessing transaction characteristics

[`networkProtocolName`](/documentation/Foundation/URLSessionTaskTransactionMetrics/networkProtocolName)

The network protocol used to fetch the resource.

[`remoteAddress`](/documentation/Foundation/URLSessionTaskTransactionMetrics/remoteAddress)

The IP address string of the remote interface for the connection.

[`remotePort`](/documentation/Foundation/URLSessionTaskTransactionMetrics/remotePort)

The port number of the remote interface for the connection.

[`remotePort`](/documentation/Foundation/NSURLSessionTaskTransactionMetrics/remotePort)

The port number of the remote interface for the connection.

[`localAddress`](/documentation/Foundation/URLSessionTaskTransactionMetrics/localAddress)

The IP address string of the local interface for the connection.

[`localPort`](/documentation/Foundation/URLSessionTaskTransactionMetrics/localPort)

The port number of the local interface for the connection.

[`negotiatedTLSCipherSuite`](/documentation/Foundation/URLSessionTaskTransactionMetrics/negotiatedTLSCipherSuite)

The TLS cipher suite the task negotiated with the endpoint for the connection.

[`negotiatedTLSProtocolVersion`](/documentation/Foundation/URLSessionTaskTransactionMetrics/negotiatedTLSProtocolVersion)

The TLS protocol version the task negotiated with the endpoint for the connection.

[`localPort`](/documentation/Foundation/NSURLSessionTaskTransactionMetrics/localPort)

The port number of the local interface for the connection.

[`negotiatedTLSCipherSuite`](/documentation/Foundation/NSURLSessionTaskTransactionMetrics/negotiatedTLSCipherSuite)

The TLS cipher suite the task negotiated with the endpoint for the connection.

[`negotiatedTLSProtocolVersion`](/documentation/Foundation/NSURLSessionTaskTransactionMetrics/negotiatedTLSProtocolVersion)

The TLS protocol version the task negotiated with the endpoint for the connection.

[`isCellular`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isCellular)

A Boolean value that indicates whether the connection operates over a cellular interface.

[`isExpensive`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isExpensive)

A Boolean value that indicates whether the connection operates over an expensive interface.

[`isConstrained`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isConstrained)

A Boolean value that indicates whether the connection operates over an interface marked as constrained.

[`isProxyConnection`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isProxyConnection)

A Boolean value that indicastes whether the task used a proxy connection to fetch the resource.

[`isReusedConnection`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isReusedConnection)

A Boolean value that indicates whether the task used a persistent connection to fetch the resource.

[`isMultipath`](/documentation/Foundation/URLSessionTaskTransactionMetrics/isMultipath)

A Boolean value that indicates whether the connection uses a successfully negotiated multipath protocol.

[`resourceFetchType`](/documentation/Foundation/URLSessionTaskTransactionMetrics/resourceFetchType)

A value that indicates whether the resource was loaded, pushed, or retrieved from the local cache.

[`URLSessionTaskMetrics.ResourceFetchType`](/documentation/Foundation/URLSessionTaskMetrics/ResourceFetchType)

The manner in which a resource is fetched.

[`domainResolutionProtocol`](/documentation/Foundation/URLSessionTaskTransactionMetrics/domainResolutionProtocol)

DNS protocol used for domain resolution.

[`URLSessionTaskMetrics.DomainResolutionProtocol`](/documentation/Foundation/URLSessionTaskMetrics/DomainResolutionProtocol)

### Creating transaction metrics

[`init()`](/documentation/Foundation/URLSessionTaskTransactionMetrics/init())

Creates a transaction metrics instance.

[`new()`](/documentation/Foundation/URLSessionTaskTransactionMetrics/new())

Creates a new transaction metrics instance.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)