Skip to content

Commit

Permalink
Update gRPC interceptor to perform foating point division when calcul…
Browse files Browse the repository at this point in the history
…ating elapsed time
  • Loading branch information
Sovietaced committed Nov 10, 2023
1 parent 007d252 commit 4b3e369
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,11 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
grpcStatusCodeAttr := statusCodeAttr(s.Code())
span.SetAttributes(grpcStatusCodeAttr)

elapsedTime := time.Since(before).Milliseconds()
// Use floating point division here for higher precision (instead of Millisecond method).
elapsedTime := float64(time.Since(before)) / float64(time.Millisecond)

metricAttrs = append(metricAttrs, grpcStatusCodeAttr)
cfg.rpcDuration.Record(ctx, float64(elapsedTime), metric.WithAttributes(metricAttrs...))
cfg.rpcDuration.Record(ctx, elapsedTime, metric.WithAttributes(metricAttrs...))

return resp, err
}
Expand Down

0 comments on commit 4b3e369

Please sign in to comment.