androidfirebaseperformancebytecodefirebase-performance

How Firebase Performance Monitoring intercepts outgoing http requests in android?


From firebase's help doc https://firebase.google.com/docs/perf-mon/network-traces?platform=android , it states

For all app types, Performance Monitoring automatically collects a trace for each network request issued by your app, called an HTTP/S network request trace Performance Monitoring automatically collects metrics for network requests that use the following networking libraries: OkHttp3, Java's URLConnection, Apache HttpClient

How are they tracking the http requests automatically without using any interceptors ? are they using any byte code manipulation to track them ?


Solution

  • Yes, it is using bytecode manipulation on Android. That's what the plugin does at build time. It finds all occurrences of API calls that look like HTTP requests (URLConnection, Apache HTTPClient, and OKHTTP), and decorates those calls with an object that monitors their use at runtime.

    If you want a deep dive into how that actually works, watch this talk.