Skip to content

Commit 1f73b4a

Browse files
committed
fix: completed metric
1 parent 441ac40 commit 1f73b4a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

go.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/Ju0x/humanhash"
1212
"go.opentelemetry.io/otel"
1313
"go.opentelemetry.io/otel/attribute"
14+
"go.opentelemetry.io/otel/codes"
1415
"go.opentelemetry.io/otel/metric"
1516
semconv "go.opentelemetry.io/otel/semconv/v1.30.0"
1617
"go.opentelemetry.io/otel/trace"
@@ -180,7 +181,13 @@ func Go(fn Func, opts ...Option) <-chan error {
180181
if span.IsRecording() {
181182
l = l.With(zap.String("trace_id", span.SpanContext().TraceID().String()))
182183
}
183-
defer span.End()
184+
defer func() {
185+
if err != nil {
186+
span.RecordError(err)
187+
span.SetStatus(codes.Error, err.Error())
188+
}
189+
span.End()
190+
}()
184191
}
185192
l.Log(o.level, "starting gofuncy routine",
186193
zap.Duration("delay", time.Since(delay).Round(time.Millisecond)),
@@ -198,8 +205,7 @@ func Go(fn Func, opts ...Option) <-chan error {
198205
defer o.runningCounter.Add(ctx, -1, attrs)
199206
}
200207
if o.completedCounter != nil {
201-
o.completedCounter.Add(ctx, 1, attrs)
202-
defer o.runningCounter.Add(ctx, -1, attrs, metric.WithAttributes(
208+
defer o.runningCounter.Add(ctx, 1, attrs, metric.WithAttributes(
203209
attribute.Bool("error", err != nil),
204210
))
205211
}

0 commit comments

Comments
 (0)