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

Fix URLSession instrumentation in iOS 16 #398

Merged
merged 6 commits into from
Apr 11, 2023

Conversation

nachoBonafonte
Copy link
Member

iOS 16 broke async/await URLSession instrumentation, add extra code to make it work:

Only NSURLSessionTask.resume and URLSessionTaskDelegate.urlSession(_:task:didFinishCollecting:) are being called (contrary to what documentation says), try to move all the logic to these two methods

Also for async/await calls without delegate set a task delegate so that the delegate method is called and we can capture it

Added many tests exercising async await network calls

…o make it work:

Only  NSURLSessionTask.resume and URLSessionTaskDelegate.urlSession(_:task:didFinishCollecting:) are being called (contrary to what documentation says), try to move all the logic to these two methods
Also for async/await calls without delegate set a task delegate so that the taskdelegate method is called
}
#else
let version = UIDevice.current.systemVersion
if let versionNumber = Double(version),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would https://forums.swift.org/t/swift-concurrency-back-deployment/51908/13 be preferred to check for concurrency availability?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only fails in iOS 16, previous versions work with async/await perfectly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, bizarre! good spot

Make InstrumentationUtils.usesUndocumentedAsyncAwaitMethods a static variable so it is only calculated once
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Patch coverage: 52.45% and project coverage change: -0.07 ⚠️

Comparison is base (fd2171e) 62.39% compared to head (6a6246e) 62.33%.

❗ Current head 6a6246e differs from pull request most recent head d9909d7. Consider uploading reports for the commit d9909d7 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #398      +/-   ##
==========================================
- Coverage   62.39%   62.33%   -0.07%     
==========================================
  Files         253      253              
  Lines       11770    11824      +54     
==========================================
+ Hits         7344     7370      +26     
- Misses       4426     4454      +28     
Impacted Files Coverage Δ
...ntation/URLSession/URLSessionInstrumentation.swift 68.02% <22.22%> (-3.33%) ⬇️
...trumentation/URLSession/InstrumentationUtils.swift 93.65% <95.65%> (+1.15%) ⬆️
...urces/Exporters/DatadogExporter/Utils/Device.swift 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nachoBonafonte nachoBonafonte marked this pull request as ready for review April 10, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants