flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_performance] [question] Which metrics are automatically collected when using firebase performance?

Open cleberhenriques opened this issue 4 years ago • 15 comments

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 avatar Dec 14 '20 13:12 cleberhenriques

@cleberhenriques You may check this section of plugin readme to see if it helps to answer your question.

darshankawar avatar Dec 15 '20 09:12 darshankawar

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.

cleberhenriques avatar Dec 15 '20 11:12 cleberhenriques

Cannot see any performance data in firebase console, don't know what are the default metrics.

LiangHuangBC avatar Jan 19 '21 19:01 LiangHuangBC

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.

danallen88 avatar Apr 16 '21 12:04 danallen88

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

Salakar avatar Apr 22 '21 16:04 Salakar

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.

danallen88 avatar Apr 22 '21 17:04 danallen88

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

caseyryan avatar Aug 02 '21 06:08 caseyryan

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)

adamsfru avatar Dec 01 '21 04:12 adamsfru

esto sigue malo

aostoic avatar Mar 01 '22 18:03 aostoic

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?

SimonVillage avatar Mar 12 '22 05:03 SimonVillage

/cc @Salakar for further insights.

darshankawar avatar Jun 29 '22 08:06 darshankawar

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

AgungLaksana avatar Jul 29 '22 08:07 AgungLaksana

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 ?

AgungLaksana avatar Jul 29 '22 09:07 AgungLaksana

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?

Lyokone avatar Sep 12 '22 07:09 Lyokone

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!

google-oss-bot avatar Sep 21 '22 01:09 google-oss-bot

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.

google-oss-bot avatar Sep 30 '22 01:09 google-oss-bot