flutterfire
flutterfire copied to clipboard
[firebase_performance] [question] Which metrics are automatically collected when using firebase performance?
Hi all,
Asking here because I couldn't find any official documentation about this.
Does the Flutter version of firebase_performance automatically collect any metrics? Or I need to implement custom metrics in order to get insights in the dashboard?
Thanks in advance.
@cleberhenriques You may check this section of plugin readme to see if it helps to answer your question.
Hi @darshankawar, thanks for the quick response.
Yes, it kinda answers my question, but at the same time, it raises more questions.
So, does it means that if I don't want to implement any custom metric, it will start collecting data automatically just by adding the dependency into the project?
Related to this part of the documentation:
Although this includes most network requests for your app, some might not be reported.
Is there any example of a specific reason that some network requests might not be reported?
Following the documentation, is states:
You must also configure firebase performance monitoring for each platform project: Android and iOS (see the example folder or https://codelabs.developers.google.com/codelabs/flutter-firebase/#4 for step by step details).
This codelab link only shows how to create a flutter project and add a dependency to cloud_firestore & set the minimum sdk version on Android platform. This makes me think that the plugin readme is out-of-date or wrong.
So, assuming that I already have other firebase product integrated with my app (e.g FirebaseAnalytics) do I need to configure anything on platform projects?
Thanks in advance.
Cannot see any performance data in firebase console, don't know what are the default metrics.
I agree - there's no HTTP traffic captured other than what Crashlytics generates (we're using Dio as our HTTP client, and nothing is getting captured from that), and for screen render times, there is only a "FlutterViewController" even though our app has multiple "screens" by using Flutter's routes. The documentation seems incorrect, or at least needs more qualification on what is collected by default. The linked documentation on how to configure it per-platform is also now a dead link.
HTTP requests made from Dart are as far as I'm aware not automatically captured by Performance Monitoring. If you're using Dio as mentioned above then your best bet would be to register an interceptor on your dio
instance and from there build your Performance Monitoring metrics;
dio.interceptors.add(InterceptorsWrapper(
onRequest:(options, handler){
// Do something before request is sent
return handler.next(options); //continue
},
onResponse:(response,handler) {
// Do something with response data
return handler.next(response); // continue
},
onError: (DioError e, handler) {
// Do something with response error
return handler.next(e); //continue
}
));
Could you point me to where the docs are that suggest this happens automatically and I'll get it updated
If you're using Dio as mentioned above then your best bet would be to register an interceptor on your
dio
instance and from there build your Performance Monitoring metrics;
Indeed this is what we are doing now, just through a third-party library that provides the implementation of the interceptor. Obviously if we want more than what that provides, that's not an issue that this team needs to concern itself with, and from what I can tell, the Performance plugin itself allows us to send what we want (assuming that the interface supports it).
Could you point me to where the docs are that suggest this happens automatically and I'll get it updated
I assume this comment is in reference to the bug I filed (#5888) which suggested as much - the communication I quoted was from an email from a Google Cloud Customer Engineer. The documentation indicates it automatically collects:
I understand these docs were written in the context of native apps only, and does not necessarily take into account Flutter. But if the goal of the Flutter plugin is to replicate what these do for native apps, then I do believe there is a feature-gap currently.
I also cannot get any http request metrics in Firebase console I've made a custom interceptor for it
class _PerformanceInterceptor implements InterceptorContract {
Map<String, HttpMetric> _metrics = {};
HttpMethod _mapMethod(Method method) {
switch (method) {
case Method.HEAD:
return HttpMethod.Head;
case Method.GET:
return HttpMethod.Get;
case Method.POST:
return HttpMethod.Post;
case Method.PUT:
return HttpMethod.Put;
case Method.PATCH:
return HttpMethod.Patch;
case Method.DELETE:
return HttpMethod.Delete;
}
}
@override
Future<RequestData> interceptRequest({
required RequestData data,
}) async {
final url = data.url;
final HttpMetric metric = FirebasePerformance.instance.newHttpMetric(
url,
_mapMethod(data.method),
);
_metrics[url] = metric;
await metric.start();
return data;
}
@override
Future<ResponseData> interceptResponse({
required ResponseData data,
}) async {
final metric = _metrics[data.url];
if (metric != null) {
metric
..responsePayloadSize = data.contentLength
..responseContentType = data.headers?['content-type']
..requestPayloadSize = data.contentLength
..httpResponseCode = data.statusCode;
await metric.stop();
}
_metrics.remove(data.url);
return data;
}
}
I debugged this code and I am totally sure that it works correctly. Metrics start and stop as they're supposed too. But when I go to firebase console (even a few days after I made any requests) the network tab is empty. Even though other metrics work and are displayed there
I've installed firebase_performance: ^0.7.1+4
and can also report that the screen render times are not showing up in the Firebase Console.
The documentation @
https://pub.dev/packages/firebase_performance
states: automatic network request traces and screen traces will not always be collected for mobile apps.
However, it's not clear to me what exactly it means when they say will not always
. In my experience nothing is showing up, except for in iOS a very generic FlutterViewController
screen listing, and for Android, another generic MainActivity
screen.
Has anyone successfully been able to log and get detailed screen traces in FlutterFire ?
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
esto sigue malo
This issue has been opened more than a year ago and is still a problem. Do we already know what's causing the issue and was someone be able to workaround?
/cc @Salakar for further insights.
this
hi @darshankawar could you please update the link you shared to cleberhenriques above? it seems the link is no longer relevant since the docs for FlutterFire have already been migrated to firebase.com I guess. Thank you very much
I also cannot get any http request metrics in Firebase console I've made a custom interceptor for it
class _PerformanceInterceptor implements InterceptorContract { Map<String, HttpMetric> _metrics = {}; HttpMethod _mapMethod(Method method) { switch (method) { case Method.HEAD: return HttpMethod.Head; case Method.GET: return HttpMethod.Get; case Method.POST: return HttpMethod.Post; case Method.PUT: return HttpMethod.Put; case Method.PATCH: return HttpMethod.Patch; case Method.DELETE: return HttpMethod.Delete; } } @override Future<RequestData> interceptRequest({ required RequestData data, }) async { final url = data.url; final HttpMetric metric = FirebasePerformance.instance.newHttpMetric( url, _mapMethod(data.method), ); _metrics[url] = metric; await metric.start(); return data; } @override Future<ResponseData> interceptResponse({ required ResponseData data, }) async { final metric = _metrics[data.url]; if (metric != null) { metric ..responsePayloadSize = data.contentLength ..responseContentType = data.headers?['content-type'] ..requestPayloadSize = data.contentLength ..httpResponseCode = data.statusCode; await metric.stop(); } _metrics.remove(data.url); return data; } }
I debugged this code and I am totally sure that it works correctly. Metrics start and stop as they're supposed too. But when I go to firebase console (even a few days after I made any requests) the network tab is empty. Even though other metrics work and are displayed there
is this custom URL working now ?
Hello, in the latest version of performance we see the metrics on custom URL properly (example here: https://github.com/firebase/flutterfire/tree/master/packages/firebase_performance/firebase_performance/example), do you still have the issue?
Hey @cleberhenriques. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@cleberhenriques if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.