Firebase 性能详解 URL 模式
Firebase Performance Detailed URL Patterns
我无法在 Firebase 性能监控中查看详细的 URL 模式,即使在过去几个月 API 拥有超过 30k 个样本之后也是如此。
它只显示根 API 域,如下所示:
api.myAppName.in/**
而不是像
api.myAppName.in/app/v3/user/*/profile/
控制台只会在 API 上显示一个标签 "uncategorized",如果您悬停此消息
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.
但如前所述,已经几个月了,超过 30k 个样本。
我正在使用改装,如果有帮助的话。
我联系了 Firebase 支持,他们的回答是:
...
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.
...
我用来拦截改造请求和监控请求时间的代码是:(为了安全我删除了查询参数数据)
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()
}
要测试它是否正确记录:请遵循此 Debugging tutorial:
您会看到如下内容:
10-24 19:48:21.162 23037 24411 I FirebasePerformance: Logging NetworkRequestMetric - https://your-api-domain.com/cart 0b 147809ms,
Firebase 性能监控现在支持创建自定义 URL 模式,让您可以针对更具体的 URL。来自文档:
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.
因此,如果您确实想要捕获类似 api.myAppName.in/app/v3/user/*/profile/**
的内容,您现在可以
有关详细信息,请参阅 the docs。
我无法在 Firebase 性能监控中查看详细的 URL 模式,即使在过去几个月 API 拥有超过 30k 个样本之后也是如此。
它只显示根 API 域,如下所示:
api.myAppName.in/**
而不是像
api.myAppName.in/app/v3/user/*/profile/
控制台只会在 API 上显示一个标签 "uncategorized",如果您悬停此消息
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.
但如前所述,已经几个月了,超过 30k 个样本。
我正在使用改装,如果有帮助的话。
我联系了 Firebase 支持,他们的回答是:
...
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.
...
我用来拦截改造请求和监控请求时间的代码是:(为了安全我删除了查询参数数据)
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()
}
要测试它是否正确记录:请遵循此 Debugging tutorial: 您会看到如下内容:
10-24 19:48:21.162 23037 24411 I FirebasePerformance: Logging NetworkRequestMetric - https://your-api-domain.com/cart 0b 147809ms,
Firebase 性能监控现在支持创建自定义 URL 模式,让您可以针对更具体的 URL。来自文档:
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.
因此,如果您确实想要捕获类似 api.myAppName.in/app/v3/user/*/profile/**
的内容,您现在可以
有关详细信息,请参阅 the docs。