【发布时间】: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