Skip to content

Commit

Permalink
grpc.StatsHandler should record RPC durations in ms instead o fns
Browse files Browse the repository at this point in the history
  • Loading branch information
Sovietaced committed Nov 10, 2023
1 parent b4b06bc commit d36f189
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)

### Fixed

- The `grpc.StatsHandler` now records RPC durations in ms instead of ns. (#4547)

## [1.21.0/0.46.0/0.15.0/0.1.0] - 2023-11-10

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ func (c *config) handleRPC(ctx context.Context, rs stats.RPCStats) {
span.End()

metricAttrs = append(metricAttrs, rpcStatusAttr)
c.rpcDuration.Record(wctx, float64(rs.EndTime.Sub(rs.BeginTime)), metric.WithAttributes(metricAttrs...))

// Use floating point division here for higher precision (instead of Millisecond method).
elapsedTime := float64(rs.EndTime.Sub(rs.BeginTime)) / float64(time.Millisecond)

c.rpcDuration.Record(wctx, elapsedTime, metric.WithAttributes(metricAttrs...))
c.rpcRequestsPerRPC.Record(wctx, gctx.messagesReceived, metric.WithAttributes(metricAttrs...))
c.rpcResponsesPerRPC.Record(wctx, gctx.messagesSent, metric.WithAttributes(metricAttrs...))

Expand Down

0 comments on commit d36f189

Please sign in to comment.