Skip to content

Commit

Permalink
defer time.Since call (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-xyz authored Dec 4, 2024
1 parent f76dcf1 commit b4e73b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2 changes: 1 addition & 1 deletion instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func EndpointMetrics[TIn, TOut any](mp metric.MeterProvider) Middleware[TIn, TOu
counter.Add(ctx, 1, metric.WithAttributes(attrs))
}
if hist, Merr := meter.Float64Histogram("latency"); Merr == nil {
defer hist.Record(ctx, time.Since(start).Seconds(), metric.WithAttributes(attrs))
defer func() { hist.Record(ctx, time.Since(start).Seconds(), metric.WithAttributes(attrs)) }()
}
resp, err := next(ctx, req)
if err != nil {
Expand Down

0 comments on commit b4e73b1

Please sign in to comment.