10

I am not able to view detailed URL Patterns in Firebase Performance Monitoring even after the API having >30k samples in the past few months.

It just shows the root API domain like this:

api.myAppName.in/**

instead of something like

api.myAppName.in/app/v3/user/*/profile/

The console just shows a label "uncategorized" on the API with this message if you hover it

Detailed URL patterns from api.myAppName.in will appear as we collect a larger number of samples. Allow for up to 24 hours after collection.

But as mentioned earlier, it's been a few months and more than 30k samples.

I'm using retrofit, if that helps.

Ishaan Garg
  • 3,014
  • 3
  • 25
  • 28

2 Answers2

11

I have contacted Firebase support and their answer was:

...

  • As mentioned here, while Performance Monitoring reports most network requests for your app, some might not be reported. Hence, it is recommended to add monitoring for specific requests in your app.

  • In order for a request to be reported to the Performance Monitoring console, any trace that is start using the trace.start() must also be stopped by calling the trace.stop() method. Traces that are never
    stopped, are never reported.

  • Wildcarding is only based on path segment and not query strings. Query strings are ignored for purpose of aggregation in the dashboard.
  • For a domain a.b.c, it's path a.b.c/d/ should have been requested from several dozen unique devices in order for the path a.b.c/d/ to appear separately in the dashboard, in the time frame of your selected filter.
  • Known Issues with Performance Monitoring.

For the 4th point that I mentioned above, there is also one thing to keep in mind. Let's say N is the definite numerical value representing the "several dozen" threshold that I mentioned earlier. And, we are monitoring the following 3 different path segments: 1. www.something.com/a/ 2. www.something.com/b/ 3. www.something.com/c/

Within a given time-frame, if all 3 of the paths above received N-1 hits. That is, not meeting the threshold requirement. While the number of hits might appear to be almost 3 times of N when seen against www.something.com collectively(as that is what the dashboard will show), the individual hits for each path did not meet the threshold in the given time frame and hence, only the aggregated number statistics are shown.

...

The code that I used to intercept the retrofit request and monitor the request time is: (I removed the query params data for security)

val builder = OkHttpClient.Builder()
 .addInterceptor(FirebasePerformanceInterceptor(FirebasePerformance.getInstance()))
  .build()

// Adapted from: http://qaru.site/questions/15007824/how-can-i-get-the-url-and-method-of-retrofit-request-on-onsubscribe-of-rxjava-2-custom-operator
class FirebasePerformanceInterceptor(private val performanceInstance: FirebasePerformance) : Interceptor {
  override fun intercept(chain: Interceptor.Chain): Response {
    val request = chain.request()
    //Get request values
    val url = request.url().url()
    val urlPath = getUrlWithoutQuery(url)

    val requestPayloadSize = request.body()?.contentLength() ?: 0L
    val httpMethod = request.method()

    //Initialize http trace
    val trace = performanceInstance.newHttpMetric(urlPath, httpMethod)
    trace.setRequestPayloadSize(requestPayloadSize)
    trace.start()

    //Proceed
    val response = chain.proceed(chain.request())

    //Get response values
    val responseCode = response.code()

    //Add response values to trace and close it
    trace.setHttpResponseCode(responseCode)
    trace.stop()

    return response
  }
    }

private fun getUrlWithoutQuery(url: URL): URL {
  val uri = URI(url.protocol, url.host, url.path, null)
  return uri.toURL()
}

To test if it's logging correctedly: Follow this Debugging tutorial: You will see something like:

10-24 19:48:21.162 23037 24411 I FirebasePerformance: Logging NetworkRequestMetric - https://your-api-domain.com/cart 0b 147809ms,
Roni Castro
  • 1,968
  • 21
  • 40
  • 2
    very minor: misspelled answer as answear... but maybe that could mean that it's an answer that they swear is correct ;) . Thanks for the writeup, and for the link to the debugging tutorial - super helpful! – m0bl Nov 06 '18 at 22:00
  • The interceptor doesn't seem to work, I cannot see any custom metrics in the dashboard even after days. When using it I don't have the limitation of the "several dozen devices", do I? Also, is the "un categorized" reliable? I mean, is it sure that with thousands of requests the more detailed URLs will show up? Have you found documentation where they state it? Thanks – manusobles Jun 13 '19 at 07:24
  • 1
    @manusoft It worked locally, but some endpoints was never shown in production environment after months of use and more than a million users acessing the app. We did not found out why it has happened, maybe some Proguard configuration, so we gave up using it and started using another paid service that works. We are avoiding Google Services, as they generally do not work very well. – Roni Castro Jun 13 '19 at 16:11
  • @roni-castro thanks for your reply. Sad to hear it's not fully working, disappointing. – manusobles Jun 14 '19 at 09:31
5

Firebase Performance Monitoring now supports creating custom URL patterns that allow you to target more specific URLs. From the docs:

You can create custom URL patterns to monitor specific URL patterns that Firebase isn't capturing with its derived automatic URL pattern matching. For example, you can use a custom URL pattern to troubleshoot a specific URL or to monitor a specific set of URLs over time.

So if you did want to capture something like api.myAppName.in/app/v3/user/*/profile/**, you would now be able to

See the docs for more details.

Melissa Lopez
  • 66
  • 1
  • 2