How do I access this ID info given a URLSession ?
There isn’t a way to do that directly. Honestly, the ability to do that would be super useful and I encourage you to file an enhancement request for us to add it as a property to the task metrics API. Please post your bug number, just for the record.
The indirect way to do that is with the connection tuple, as I outlined earlier. To test this out I created a small Mac app that connects to port 80 on example.com
. I then filtered the log for my app and the subsystem com.apple.network
. The first log entry I saw was this:
type: info
time: 09:23:31.709387+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_connection_create_with_id [C2] create connection to example.com:80
That tells me the connection ID ([C2]
) and the DNS name and port. I then saw this:
type: info
time: 09:23:31.711564+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_resolver_create_dns_getaddrinfo_locked_block_invoke [C2.1] Got 3 DNS results
type: info
time: 09:23:31.711576+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_resolver_create_dns_getaddrinfo_locked_block_invoke [C2.1] Got DNS result type ServiceBinding ifindex=0 example.com example.com. <NULL>
type: info
time: 09:23:31.711585+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_resolver_create_dns_getaddrinfo_locked_block_invoke [C2.1] Got DNS result type Add ifindex=0 example.com example.com. 2606:2800:21f:cb07:6820:80da:af6b:8b2c
type: info
time: 09:23:31.711592+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_resolver_create_dns_getaddrinfo_locked_block_invoke [C2.1] Got DNS result type Add ifindex=0 example.com example.com. 93.184.215.14
This is the DNS resolution results, telling me the inputs Network frameworks Happy Eyeballs algorithm. Note how the connection ID is shown as [C2.1]
, a ‘child’ of the [C2]
we saw earlier.
Later on I saw this:
type: default
time: 09:23:32.064699+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_flow_connected [C2.1.2 93.184.215.14:80 in_progress channel-flow (satisfied (Path is satisfied), viable, interface: utun8, ipv4, ipv6, dns, uses wifi)] Output protocol connected (tcp)
indicating that the child flow is connected. Note that this is a grandchild of the original flow. There’s one of these for each of the connections that Happy Eyeballs ‘races’.
Finally, I saw this:
type: default
time: 09:23:32.066020+0100
process: Test757473
subsystem: com.apple.network
category: connection
message: nw_flow_connected [C2 93.184.215.14:80 in_progress parent-flow (satisfied (Path is satisfied), interface: utun8, ipv4, ipv6, dns, uses wifi)] Output protocol connected (endpoint_flow)
indicating that this caused the parent flow to be connected.
Keep in mind that I’m using TCP here. You’ll see different stuff for a QUIC connection.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"