Naar console

Monitor HTTP/S network requests

An HTTP/S network request trace is a report that captures the time between when your app issues a request to a service endpoint and when the response from that endpoint is complete. For any endpoint to which your app makes a request, Performance Monitoring captures several metrics:

  • Response time — Time between when the request is made and when the response is fully received

  • Payload size — Byte size of the network payload downloaded and uploaded by the app

  • Success rate — Percentage of successful responses compared to total responses (to measure network or server failures)

Performance Monitoring automatically collects metrics for network requests that use the following networking libraries:

This out-of-the-box monitoring includes most network requests for your app. However, some requests might not be reported or you might use a different library to make network requests. In these cases, you can use the Performance Monitoring API to manually instrument custom network requests.

Data aggregation under URL patterns

Firebase Performance Monitoring automatically aggregates data for similar network requests to help you understand trends in your network request performance.

For each request, Firebase checks if the network request's URL matches a URL pattern. If the request URL matches a URL pattern, Firebase automatically aggregates the request's data under the URL pattern. Firebase displays URL patterns and their aggregated data in the Network tab in Performance section of the Firebase console.

What's a URL pattern?

A URL pattern contains a domain plus a pattern that can match a URL path, for instance: example.com/*/animals/**.

  • URL patterns can contain the following path segments:

    • plain text — matches an exact string
    • * — matches any string in a single path segment
    • ** — matches an arbitrary path suffix
  • URL patterns can be either:

For example: Any of the following URL requests could match the URL pattern example.com/*/animals/**.

  • example.com/singapore/animals
  • example.com/australia/animals/spiders
  • example.com/australia/animals/marsupials/koala.png

Firebase maps each request to only one URL pattern. If you've configured any custom URL patterns, Firebase attempts to match request URLs to those patterns first. If Firebase finds no matching custom URL pattern, then it matches a request URL to the most representative automatic URL pattern. Learn more about automatic and custom URL patterns in the following sections.

Automatic URL patterns

Without any configuration by you, Performance Monitoring attempts to reflect your app's latest usage behavior by matching your app's requests to automatic URL patterns.

How does automatic URL pattern matching work?

Firebase matches each request to the most representative automatic URL pattern that it has derived from requests sent by your app. Note, though, that Firebase attempts to match request URLs to any configured custom URL patterns first.

The following is a basic example for how Firebase attempts to match requests to the most representative automatic URL pattern for your app.

  1. Your app sends many requests to URLs like:

    • example.com/germany/animals/bears
    • example.com/germany/animals/birds
    • example.com/germany/cars

    Firebase determines that example.com/germany/** is a common request pattern for your app and adds it as an automatic URL pattern in your project.

    For any new matching requests to this URL pattern, Firebase aggregates the requests' data under the automatic URL pattern example.com/germany/**.

  2. After one week, the majority of your app's requests are to example.com/germany/animals/bears and example.com/germany/animals/birds. So, Firebase derives a more representative URL pattern of example.com/germany/animals/**.

    For any new matching requests to this new URL pattern, Firebase aggregates the requests' data only under the new URL pattern. Firebase continues to aggregate data for requests to example.com/germany/cars under example.com/germany/**.

  3. However, over the next several weeks, your app's requests to example.com/germany/animals/bears and example.com/germany/animals/birds decrease substantially. Firebase determines that example.com/germany/animals/** is not representative of your app's latest usage behavior, so Firebase starts matching these two requests back to example.com/germany/**.

    Firebase does not aggregate any further request data under example.com/germany/animals/** because it's no longer the most representative automatic URL pattern.

Because automatic URL pattern matching is dynamic, be aware of the following:

  • Matches and aggregated data from previous requests aren't affected by new URL patterns. Firebase does not retroactively re-aggregate request data.

  • Only future requests are affected by new URL patterns. Firebase maps each new request to the most representative automatic URL pattern. Note, though, that Firebase attempts to match request URLs to any configured custom URL patterns first.

View automatic URL patterns and their data

The Performance section of the console lists automatic URL patterns in the Network > All tab. You might see URL patterns with an Uncategorized label. These are "broad" automatic URL patterns under which Firebase can aggregate data for requests that don't match to any more specific URL pattern.

When the data retention period ends for the data aggregated under a URL pattern, Firebase deletes that data from the URL pattern. If all the data aggregated under an automatic URL pattern expires, then Firebase deletes that URL pattern from the Firebase console.

Custom URL patterns

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.

How does custom URL pattern matching work?

Firebase attempts to match request URLs to any configured custom URL patterns before falling back to automatic URL pattern matching. For any matching requests to a custom URL pattern, Firebase aggregates the requests' data under the custom URL pattern.

If a request's URL matches more than one custom URL pattern, Firebase maps the request to the most specific custom URL pattern only, according to the following specificity order: plain text > * > ** from left to right in the path. For example, a request to example.com/books/dog matches two custom URL patterns:

  • example.com/books/*
  • example.com/*/dog

However, the pattern example.com/books/* is the most specific matching URL pattern because the leftmost segment books in example.com/books/* takes precedence over the leftmost segment * in example.com/*/dog.

When you create a new custom URL pattern, be aware of the following:

  • Matches and aggregated data from previous requests aren't affected by creating a new custom URL pattern. Firebase does not retroactively re-aggregate request data.

  • Only future requests are affected by creating a new custom URL pattern. You might need to wait up to 12 hours for Performance Monitoring to collect and aggregate data under a new custom URL pattern.

Create a custom URL pattern

Create a custom URL pattern from the Performance section of the console in the Network tab. A project member must be an Owner or Editor to create a new custom URL pattern; however, all project members can view custom URL patterns and their aggregated data.

To create a custom URL pattern, start with a domain, then use the following path segment syntax to create a pattern that can match URL paths.

  • plain text — matches an exact string
  • * — matches any string in a single path segment
  • ** — matches an arbitrary path suffix

The following table describes some potential custom URL pattern matching.

To match... Create a custom URL pattern like... Example matches to this URL pattern
An exact URL example.com/foo/baz example.com/foo/baz
Any single path segment (*) example.com/*/baz example.com/foo/baz
example.com/bar/baz
example.com/*/*/baz example.com/foo/bar/baz
example.com/bah/qux/baz
example.com/foo/* example.com/foo/baz
example.com/foo/bar

Note: This pattern will not match example.com/foo.

An arbitrary path suffix (**) example.com/foo/** example.com/foo
example.com/foo/baz
example.com/foo/baz/more/segments
subdomain.example.com/foo.bar/** subdomain.example.com/foo.bar
subdomain.example.com/foo.bar/baz
subdomain.example.com/foo.bar/baz/more/segments

View custom URL patterns and their data

The Performance section of the console lists custom URL patterns that have aggregated data in both the Network > All tab and the Network > Custom tab. If a custom URL pattern doesn't have any aggregated data, then it only appears in the Network > Custom tab.

When the data retention period ends for the data aggregated under a URL pattern, Firebase deletes that data from the URL pattern. If all the data aggregated under a custom URL pattern expires, then Firebase does not delete the custom URL pattern from the Firebase console. Instead, Firebase continues to list "empty" custom URL patterns in the Network > Custom tab.

Remove a custom URL pattern

Unlike an automatic URL pattern, you can remove custom URL patterns from your project.

  1. From the Performance section of the console, go to the Network > Custom tab.

  2. Hover over the row of the custom URL pattern that you want to remove.

  3. Click delete at the far right of the row, then confirm the removal in the dialog.

When you remove a custom URL pattern, be aware of the following:

  • Any future requests are mapped to the next most specific matching custom URL pattern. If Firebase finds no matching custom URL patterns, then it falls back to automatic URL pattern matching.

  • Matches and aggregated data from previous requests aren't affected by removing a custom URL pattern.

    You can still access a removed custom URL pattern and its aggregated data in the Network > All tab until the end of the applicable data retention period. When all the aggregated data under the removed custom URL pattern expires, Firebase deletes the custom URL pattern.

  • The Network > Custom tab does not list any removed custom URL patterns.

Add monitoring for custom network requests

To manually instrument custom network requests in Performance Monitoring, add code similar to the following:

Java

HttpMetric metric =
        FirebasePerformance.getInstance().newHttpMetric("https://www.google.com",
                FirebasePerformance.HttpMethod.GET);
final URL url = new URL("https://www.google.com");
metric.start();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");
try {
    DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
    outputStream.write(data);
} catch (IOException ignored) {
}
metric.setRequestPayloadSize(data.length);
metric.setHttpResponseCode(conn.getResponseCode());
printStreamContent(conn.getInputStream());

conn.disconnect();
metric.stop();

Kotlin

val metric = FirebasePerformance.getInstance().newHttpMetric("https://www.google.com",
        FirebasePerformance.HttpMethod.GET)
val url = URL("https://www.google.com")
metric.start()
val conn = url.openConnection() as HttpURLConnection
conn.doOutput = true
conn.setRequestProperty("Content-Type", "application/json")
try {
    val outputStream = DataOutputStream(conn.outputStream)
    outputStream.write(data)
} catch (ignored: IOException) {
}

metric.setRequestPayloadSize(data.size.toLong())
metric.setHttpResponseCode(conn.responseCode)
printStreamContent(conn.inputStream)

conn.disconnect()
metric.stop()

The HTTP/S network requests that you specifically capture in this way appear in the Firebase console along with the network requests that Performance Monitoring captures automatically.

Monitor network request traces in the console

  1. In the Firebase console, go to the Performance dashboard.

  2. Click the Network tab, then you can:

    • View a quick report of the collected data for all your network requests.

    • Click a specific endpoint to review the endpoint's data in more detail.

    • Use the Filteradd button in the top-left of the dashboard to perform basic filtering of the data by attribute.

  3. If you click a specific endpoint, the console displays an overview of the collected data on metric cards.

    • Use the options in the top-right of the dashboard to:

      • View the various data as aggregated, over time, or for each version of your app.
      • View the success rate of an endpoint as aggregated, over time, or for each version of your app.
    • Use the Filteradd button in the top-left of the dashboard to perform basic filtering of the data by attribute.

  4. For any metric, click View more to review more in-depth information about the collected data and to use richer analysis features. For example, you can filter and segment the data by attribute and view the data in the context of an app-usage session.

Next Steps