diff --git a/tracing.go b/tracing.go index b0f1d9c..f9c16c1 100644 --- a/tracing.go +++ b/tracing.go @@ -82,10 +82,14 @@ func WithOtelTracer(tracer trace.Tracer) ConfigureSpanStartFunc { } } -type TracedFunc[T any] func(context.Context, string, ...any) T +type TracedFunc[T any] func(context.Context, string, ...any) TracedFuncResult[T] +type TracedFuncResult[T any] struct { + Result T + Err error +} -func RunTraced[T any](t *Telemetry, op string, fn func(context.Context, ...any) T) TracedFunc[T] { - return func(ctx context.Context, name string, args ...any) T { +func RunTraced[T any](t *Telemetry, op string, fn func(context.Context, ...any) TracedFuncResult[T]) TracedFunc[T] { + return func(ctx context.Context, name string, args ...any) TracedFuncResult[T] { span := t.StartSpan(ctx, op, name) defer span.End() ctx = span.Context()