runWithTrace<T> method
Future<T?>
runWithTrace<T>({
- required String name,
- required String operation,
- required FutureOr<
T?> fn(- AnalyticsTrace? parentTrace
- AnalyticsTrace? parentTrace,
Runs a function with a trace. This is useful for wrapping functions that
need to be traced. It can also be part of a nested trace, using the parentTrace
parameter.
Implementation
Future<T?> runWithTrace<T>({
required String name,
required String operation,
required FutureOr<T?> Function(AnalyticsTrace? parentTrace) fn,
AnalyticsTrace? parentTrace,
}) async {
final trace = parentTrace != null
? await parentTrace.startChild(name, operation)
: await startTrace(name, operation);
try {
final value = fn(trace);
if (value is Future) {
return await value;
}
return value;
} catch (ex, stackTrace) {
reportError(ex, stackTrace: stackTrace);
rethrow;
} finally {
await trace.stop();
}
}