trace<T> function
- @Deprecated('This method will be removed in 0.19.0. Use [traceContext] instead.')
Records a span of the given name
for the given function with a given
api.Tracer and marks the span as errored if an exception occurs.
Implementation
@Deprecated(
'This method will be removed in 0.19.0. Use [traceContext] instead.')
Future<T> trace<T>(String name, Future<T> Function() fn,
{api.Context? context, api.Tracer? tracer}) async {
context ??= api.globalContextManager.active;
tracer ??= _tracerProvider.getTracer('opentelemetry-dart');
final span = tracer.startSpan(name, context: context);
try {
return await api.contextWithSpan(context, span).execute(fn);
} catch (e, s) {
span
..setStatus(api.StatusCode.error, e.toString())
..recordException(e, stackTrace: s);
rethrow;
} finally {
span.end();
}
}