Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually consume URLSessionTaskMetrics data #3180

Open
philipphofmann opened this issue Jul 21, 2023 Discussed in #3150 · 1 comment
Open

Manually consume URLSessionTaskMetrics data #3180

philipphofmann opened this issue Jul 21, 2023 Discussed in #3150 · 1 comment

Comments

@philipphofmann
Copy link
Member

Discussed in #3150

Originally posted by WFT July 14, 2023
Does Sentry support gathering URLSessionTaskTransactionMetrics with its automatic URLSession breadcrumbs/performance tracking? If so, how do I enable it? As far as I can tell the default options don't do it.

It would be helpful to track the performance of our API from the perspective of our end users to know at least:

  • “secure connection time” AKA tls time
  • fetchStartDate -> responseStartDate AKA “time to first byte”

URLSessionTaskMetrics provides excellent information for HTTP requests. You can retrieve the metrics via URLSessionTaskDelegate. Swizzling these delegates is a dangerous option we don't want to implement. Instead, we could offer a manual API do set some type of SentryURLSessionTaskDelegate to forward these metrics to the SDK. We still need to figure out how to map the data to our HTTP instrumentation. A proper SentryURLSessionTaskDelegate could fully replace the SentryNetworkTrackingIntegration with swizzling.

The URLSessionTaskMetrics works by using a delegate with something like the following

guard let imgUrl = URL(string: "https://sentry-brand.storage.googleapis.com/sentry-logo-black.png") else {
    return
}
let session = URLSession(configuration: URLSessionConfiguration.default)
let dataTask = session.dataTask(with: imgUrl) { (_, _, _) in }
dataTask.delegate = Delegate()
dataTask.resume()

class Delegate: NSObject, URLSessionTaskDelegate {
    func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {

    }
}
@philipphofmann philipphofmann changed the title Add manual APIs for URLSessionTaskMetrics Manually consume URLSessionTaskMetrics data Jul 21, 2023
@philipphofmann
Copy link
Member Author

The main benefit of this feature is that we can add NSURLSessionTaskTransactionMetrics.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Discussion
Development

No branches or pull requests

2 participants