firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.69k stars 1.48k forks source link

[Swift Concurrency] Performance Monitoring does not collect network traces when using URLSession's `async` methods #11861

Open moyerr opened 1 year ago

moyerr commented 1 year ago

Description

I noticed that my app's network requests were not showing up at all in Performance Monitoring. I traced the issue to the fact that I am using URLSession's concurrency (async/await) APIs.

I can tell everything is set up properly because I can see the network traces when I use URLSession's closure-based APIs.

Reproducing the issue

// ❌ This network call does not show up in Performance Monitoring
let (data, response) = try await URLSession.shared.data(for: request)

// ✅ This network call does show up in Performance monitoring
URLSession.shared
  .dataTask(with: try request) { data, response, error in
    // Handle the response
  }
  .resume()

Firebase SDK Version

10.15.0

Xcode Version

14.3.1

Installation Method

Swift Package Manager

Firebase Product(s)

Performance

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

No response

If using CocoaPods, the project's Podfile.lock

No response

google-oss-bot commented 1 year ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

rizafran commented 1 year ago

Hi @moyerr, I tried to reproduce the issue using the code snippet you shared, but I'm able to see my network requests in the console. Could you provide an MCVE or complete code snippet that reproduces the issue?

google-oss-bot commented 1 year ago

Hey @moyerr. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@moyerr if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

roger-smith commented 1 year ago

I am seeing the same issue, but it appears to be iOS version specific.

I am able to see logs for requests made using the completionHandler based URLSession functions across all iOS versions without any issues

Firebase version:

Xcode version:

Brooksie18 commented 1 year ago

Hey I was just checking out some things in the pics I took last night of someone’s phone. Can you guys tell me what’s going on ? If it’s what I’m thinking I need confirmation that I’m either wrong or right.BrooksieOn Oct 18, 2023, at 12:57 PM, Morgan Chen @.***> wrote: Reopened #11861.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

Brooksie18 commented 1 year ago

BrooksieOn Oct 18, 2023, at 1:09 PM, Rachel McBride @.> wrote:Hey I was just checking out some things in the pics I took last night of someone’s phone. Can you guys tell me what’s going on ? If it’s what I’m thinking I need confirmation that I’m either wrong or right.BrooksieOn Oct 18, 2023, at 12:57 PM, Morgan Chen @.> wrote: Reopened #11861.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

SwiftNativeDeveloper commented 10 months ago

Is it possible that the method swizzling isn't attaching to the async variant of URLSession and thus it isn't instrumenting it?

You could write an extension on URLSession that wrappers the async call and creates an HTTPMetric. Automatically start before making the call, and stop on response or throws. To prevent double reporting disable the instrumentation. The downside of this is you don't get the app lifecycle traces then--such as _app_start. Presently that 100% internal and a developer cannot replicate it because of lack of public initializers on the FIRTrace and inability to set custom start/stop times.

I don't want any method swizzling going on for this exact kind of reason and want to be 100% in control of the network traces. https://github.com/firebase/firebase-ios-sdk/issues/12177

MichaelVerdon commented 2 weeks ago

I can confirm I have reliably been able to reproduce this issue even on the latest version.