【问题标题】:Gathering performance metrics for calls to Cloud Functions from Flutter从 Flutter 收集调用 Cloud Functions 的性能指标
【发布时间】:2020-02-17 22:23:28
【问题描述】:

我正在尝试将 Firebase 性能监控与 Firebase Cloud Functions 结合使用。当我运行以下代码时,我收到错误URL host is null or invalid。很明显,这是因为我传入的是函数名,而不是带有主机的 URL。

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;
  }
}

有没有办法获取可调用函数的 URL,以便我可以为其创建指标?如果没有,是否有另一种方法可以为其创建 HTTP 指标?

【问题讨论】:

    标签: flutter google-cloud-functions firebase-performance


    【解决方案1】:

    目前无法以编程方式获取 HTTP 可调用类型函数的 URL。您可以根据您对函数的了解(三个变量是部署区域、项目 ID、名称)来编写它,或者您可以简单地从 Firebase 控制台函数仪表板复制它并将其硬编码到您的应用中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2017-08-13
      • 1970-01-01
      • 2023-04-07
      • 2023-03-11
      • 2011-10-30
      • 1970-01-01
      相关资源
      最近更新 更多