Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Performance Detailed URL Patterns

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.

like image 900
Ishaan Garg Avatar asked Feb 21 '18 08:02

Ishaan Garg


2 Answers

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,
like image 84
Roni Castro Avatar answered Oct 14 '22 22:10

Roni Castro


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.

like image 31
Melissa Lopez Avatar answered Oct 14 '22 23:10

Melissa Lopez