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

Network traffic (= traces) not captured for URLSession.data(...) methods #1288

Closed
gdeff opened this issue May 24, 2023 · 3 comments · Fixed by #1394
Closed

Network traffic (= traces) not captured for URLSession.data(...) methods #1288

gdeff opened this issue May 24, 2023 · 3 comments · Fixed by #1394
Assignees
Labels
bug Something isn't working

Comments

@gdeff
Copy link

gdeff commented May 24, 2023

Hello,

In our iOS project we have set the Datadog SDK and activated trace collection.

The bug is that our requests/responses are not captured by Datadog. No trace is sent to Datadog server so we cannot find them into the Datadog UI.

After a little of investigation in the Datadog iOS SDK code, we noticed that there is a swizzling mechanism on URLSession.dataTask() methods. This mechanism is responsible for capturing traces.
In our project, we do not use URLSession.dataTask() methods but URLSession.data() methods which are their "async/await" version and available since iOS 15. More precisely, we observe that the following methods are not supported by this swizzling mechanism:

  • URLSession.data(for: URLRequest) -> (Data, URLResponse)
  • URLSession.data(from: URL) -> (Data, URLResponse)
  • URLSession.data(for: URLRequest, delegate: (URLSessionTaskDelegate)?) -> (Data, URLResponse)
  • URLSession.data(from: URL, delegate: (URLSessionTaskDelegate)?) -> (Data, URLResponse)

Could you, please, update the code in order that the Datadog iOS SDK support these methods ?

@ganeshnj ganeshnj self-assigned this May 31, 2023
@ganeshnj
Copy link
Contributor

Since iOS 16, there have been some changes for async APIs in URLSession where not all delegates methods are called. This causes in failure in detection of request start and stop.

Only NSURLSessionTask.resume and URLSessionTaskDelegate.urlSession(_:task:didFinishCollecting:) are called, hence we need to modify the way we collect the metrics for async APIs (atleast) for iOS 16 and above.

I quickly checked the hypothesis on develop...ganeshnj/fix/1288-url-session-instrumentation branch and I was able to collect metrics for async APIs.

There was a similar issue in open-telemetry/opentelemetry-swift#398 as well which was recently fixed.

@ganeshnj
Copy link
Contributor

We have merged the change in develop branch and will be made available in future version of the SDK.

@ganeshnj ganeshnj reopened this Oct 18, 2023
@ncreated
Copy link
Member

Instrumentation for async/await APIs was introduced in 2.5.0 - I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants