Analyze HTTP traffic in Instruments

Description: Learn to use the Instruments Network template to record and analyze your app's HTTP traffic. We'll show you how to explore and visualize the behavior of sessions, tasks, and individual HTTP requests to ensure data is transmitted efficiently and respects people's privacy.

Track hierarchy

  • HTTP Traffic instruments
    • Number of active tasks
  • Process
    • Debuggable process and background tasks daemon
  • Session
    • One track per URLSession object
    • Individual task intervals
    • Configurable session name:
let session = URLSession(configuration: .default)
session.sessionDescription = "Main Session"
  • Domain
    • Only task that requested in the domain
    • More detail about tasks
    • Individual transactions
    • Transaction states

Task timing

  • Structural timing from start till the end

let task = session.dataTask(with: url) {
  /* handle result */ // 👈🏻 Complete event triggers here
}

task.resume() // 👈🏻 Resume event triggers here

Task Identifier

let task = session.dataTask(with: url) {
  /* handle result */
}
task.taskDescription = "Load Thumbnail"
task.resume()
task.taskIdentifier // 👈🏻 this identifier will be shown in instruments

Task Error

  • Ability to distinguish error and success with color

Transactions

  • Request + response pair being handled by the URL Loading system
  • Contains all the HTTP Layer information
  • URL, Http version, connection, cache info
  • Request + Response header
  • Request + Response body
  • And more

Transaction states

  • Multiple states to add information for distinction between each block
States

Instrument

  • Focus on the task description
Focus on the task description
  • Expand the task description
Expand task description
  • Filter by connection
Filter task
  • Identify the http task issues (Ex: Staircase problem)
Problem
  • Identify the request (Ex: wrong expiration date of cookie)
Problem 1
  • Identify the backtrace (Ex: cached response)
Problem 2
  • Filter the session (Ex: Found an issue with the data that sent to server)
Problem 3
  • Export the report to .har extension
Export
  • Output
  • Save and export report to .har to analyse issues
  • .har is a JSON structure
JSON

Next Steps

  • Target app today to detect problems
  • Name your URL Session and URLSessionTask for easier debugging
  • Adopt latest networking protocols
  • Audit your app requests to check if can send less information

Missing anything? Corrections? Contributions are welcome 😃

Related