Skip to content

Commit

Permalink
fix for comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
  • Loading branch information
fatsheep9146 committed Sep 9, 2022
1 parent 148eded commit 040efe0
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,6 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
var statusCode grpc_codes.Code
var startTime = time.Now()
var attr []attribute.KeyValue

defer func() {
elapsedTime := float64(time.Since(startTime)) / float64(time.Millisecond)
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
cfg.rpcServerDuration.Record(ctx, elapsedTime, attr...)
}()

i := &InterceptorInfo{
UnaryServerInfo: info,
Type: UnaryServer,
Expand Down Expand Up @@ -360,6 +350,13 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {

messageReceived.Event(ctx, 1, req)

var statusCode grpc_codes.Code
defer func(t time.Time) {
elapsedTime := float64(time.Since(t)) / float64(time.Millisecond)
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
cfg.rpcServerDuration.Record(ctx, elapsedTime, attr...)
}(time.Now())

resp, err := handler(ctx, req)
if err != nil {
s, _ := status.FromError(err)
Expand Down Expand Up @@ -428,17 +425,8 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
info *grpc.StreamServerInfo,
handler grpc.StreamHandler,
) error {
var statusCode grpc_codes.Code
var startTime = time.Now()
var attr []attribute.KeyValue
ctx := ss.Context()

defer func() {
elapsedTime := float64(time.Since(startTime)) / float64(time.Millisecond)
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
cfg.rpcServerDuration.Record(ctx, elapsedTime, attr...)
}()

i := &InterceptorInfo{
StreamServerInfo: info,
Type: StreamServer,
Expand Down Expand Up @@ -467,6 +455,13 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
)
defer span.End()

var statusCode grpc_codes.Code
defer func(t time.Time) {
elapsedTime := float64(time.Since(t)) / float64(time.Millisecond)
attr = append(attr, semconv.RPCGRPCStatusCodeKey.Int64(int64(statusCode)))
cfg.rpcServerDuration.Record(ctx, elapsedTime, attr...)
}(time.Now())

err := handler(srv, wrapServerStream(ctx, ss))
if err != nil {
s, _ := status.FromError(err)
Expand Down

0 comments on commit 040efe0

Please sign in to comment.