08 May 2023 03:44 PM - last edited on 09 May 2023 10:52 AM by MaciejNeumann
I'm just dipping my toes in Dynatrance, and I'm wondering if what I am observing is expected behaviour, a misconfiguration from my side, or... a bug?
Basically I'm testing to see if web requests are being logged to Dynatrace, and I noticed that if I do a network call with a completion handler it shows up in the dashboard, but if I use async / await it does not. Code samples:
/// Do a network call "the traditional way"
private func doWebRequest() {
isLoading = true
let task = URLSession.shared.dataTask(
with: URLRequest(url: URL(string: "https://www.example.com/nl")!),
completionHandler: { data, response, error in
if let response = response as? HTTPURLResponse {
print("Got response with status code \(response.statusCode)")
print("Expected content length: \(response.expectedContentLength)")
}
isLoading = false
}
)
task.resume()
}
/// Do a network call using async / await
private func doWebRequest() async {
isLoading = true
do {
let (_, response) = try await URLSession.shared.data(
for: URLRequest(url: URL(string: "https://www.example.com/en")!)
)
if let response = response as? HTTPURLResponse {
print("Got response with status code \(response.statusCode)")
print("Expected content length: \(response.expectedContentLength)")
}
isLoading = false
} catch {
isLoading = false
}
}
The first example gets logged (the /nl/) call, but the second doesn't (/en/).
Any thoughts on this?
09 May 2023 11:06 AM
This seems to be the same as this RFE: Add support for Swift Concurrency