gpt4 book ai didi

android - Firebase 性能详细 URL 模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:24:25 25 4
gpt4 key购买 nike

我无法在 Firebase Performance Monitoring 中查看详细的 URL 模式,即使 API 在过去几个月中有超过 30k 个样本也是如此。

它只是像这样显示根 API 域:

api.myAppName.in/**

而不是类似的东西

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

如果您将鼠标悬停在该消息上,控制台只会在 API 上显示“未分类”标签

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.

...

我用来拦截 retrofit 请求并监控请求时间的代码是:(为了安全我删除了查询参数数据)

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,

关于android - Firebase 性能详细 URL 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48901584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com