Gathering performance metrics for calls to Cloud Functions from Flutter

206

There is currently no way to programmatically get the URL for an HTTP callable type function. You can compose it by what you know about the function (the three variables are deployment region, project ID, name), or you can simply copy it from the Firebase console Functions dashboard and hard code it into your app.

Share:
206
bygrace
Author by

bygrace

I mostly work in JavaScript, CSS, C#, and SQL. Currently focused on Angular with RxJs.

Updated on December 14, 2022

Comments

  • bygrace
    bygrace over 1 year

    I am attempting to use Firebase Performance monitoring with Firebase Cloud Functions. When I run the following code I get the error URL host is null or invalid. Clearly that is because I am passing in a function name rather than a URL with a host.

    import 'package:flutter/widgets.dart';
    import 'package:cloud_functions/cloud_functions.dart';
    import 'package:firebase_performance/firebase_performance.dart';
    
    /// Handles tracking metrics while calling cloud functions.
    class MetricCloudFunction {
      Future<HttpsCallableResult> call(String functionName, [dynamic parameters]) async {
        final HttpMetric metric = FirebasePerformance.instance
            .newHttpMetric(functionName, HttpMethod.Get);
        final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
          functionName: functionName,
        );
    
        await metric.start();
        HttpsCallableResult response;
    
        try {
          response = await callable.call(parameters);
        } catch(e) {
          debugPrint('failed: ${e.toString()}');
        } finally {
          await metric.stop();
        }
    
        return response;
      }
    }
    
    

    Is there some way to get the URL of the callable function so that I can create the metric for it? If not, is there another way that I can create an HTTP metric for it?