Skip to content

Commit

Permalink
fix: minor code fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
liufuyang committed Oct 26, 2023
1 parent 0fecb46 commit cff17fa
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,26 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
}

before := time.Now()
var grpcStatusCode grpc_codes.Code

resp, err := handler(ctx, req)

s, _ := status.FromError(err)
if err != nil {
s, _ := status.FromError(err)
grpcStatusCode = s.Code()
statusCode, msg := serverStatus(s)
span.SetStatus(statusCode, msg)
span.SetAttributes(statusCodeAttr(grpcStatusCode))
if cfg.SentEvent {
messageSent.Event(ctx, 1, s.Proto())
}
} else {
grpcStatusCode = grpc_codes.OK
span.SetAttributes(statusCodeAttr(grpcStatusCode))
if cfg.SentEvent {
messageSent.Event(ctx, 1, resp)
}
}
grpcStatusCodeAttr := statusCodeAttr(s.Code())
span.SetAttributes(grpcStatusCodeAttr)

elapsedTime := time.Since(before).Milliseconds()
attr = append(attr, statusCodeAttr(grpcStatusCode))
attr = append(attr, grpcStatusCodeAttr)
cfg.rpcServerDuration.Record(ctx, elapsedTime, metric.WithAttributes(attr...))

return resp, err
Expand Down

0 comments on commit cff17fa

Please sign in to comment.