Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interceptor order to make sure tracing is set up first #4422

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-disconnected-traces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix disconnected traces

We fixed a problem where the appctx logger was using a new traceid instead of picking up the one from the trace parent.

https://github.com/cs3org/reva/pull/4422
44 changes: 23 additions & 21 deletions pkg/rgrpc/rgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,24 @@ func (s *Server) getInterceptors(unprotected []string) ([]grpc.ServerOption, err
return nil, errors.Wrap(err, "rgrpc: error creating unary auth interceptor")
}

unaryInterceptors := []grpc.UnaryServerInterceptor{authUnary}
for _, t := range unaryTriples {
unaryInterceptors = append(unaryInterceptors, t.Interceptor)
s.log.Info().Msgf("rgrpc: chaining grpc unary interceptor %s with priority %d", t.Name, t.Priority)
}

unaryInterceptors = append(unaryInterceptors,
unaryInterceptors := []grpc.UnaryServerInterceptor{
otelgrpc.UnaryServerInterceptor(
otelgrpc.WithTracerProvider(s.tracerProvider),
otelgrpc.WithPropagators(rtrace.Propagator)),
)

unaryInterceptors = append([]grpc.UnaryServerInterceptor{
otelgrpc.WithPropagators(rtrace.Propagator),
),
appctx.NewUnary(s.log, s.tracerProvider),
token.NewUnary(),
useragent.NewUnary(),
log.NewUnary(),
recovery.NewUnary(),
}, unaryInterceptors...)
authUnary,
}

for _, t := range unaryTriples {
unaryInterceptors = append(unaryInterceptors, t.Interceptor)
s.log.Info().Msgf("rgrpc: chaining grpc unary interceptor %s with priority %d", t.Name, t.Priority)
}

unaryChain := grpc_middleware.ChainUnaryServer(unaryInterceptors...)

streamTriples := []*streamInterceptorTriple{}
Expand Down Expand Up @@ -372,20 +371,23 @@ func (s *Server) getInterceptors(unprotected []string) ([]grpc.ServerOption, err
return nil, errors.Wrap(err, "rgrpc: error creating stream auth interceptor")
}

streamInterceptors := []grpc.StreamServerInterceptor{authStream}
for _, t := range streamTriples {
streamInterceptors = append(streamInterceptors, t.Interceptor)
s.log.Info().Msgf("rgrpc: chaining grpc streaming interceptor %s with priority %d", t.Name, t.Priority)
}

streamInterceptors = append([]grpc.StreamServerInterceptor{
authStream,
streamInterceptors := []grpc.StreamServerInterceptor{
otelgrpc.StreamServerInterceptor(
otelgrpc.WithTracerProvider(s.tracerProvider),
otelgrpc.WithPropagators(rtrace.Propagator),
),
appctx.NewStream(s.log, s.tracerProvider),
token.NewStream(),
useragent.NewStream(),
log.NewStream(),
recovery.NewStream(),
}, streamInterceptors...)
authStream,
}

for _, t := range streamTriples {
streamInterceptors = append(streamInterceptors, t.Interceptor)
s.log.Info().Msgf("rgrpc: chaining grpc streaming interceptor %s with priority %d", t.Name, t.Priority)
}
streamChain := grpc_middleware.ChainStreamServer(streamInterceptors...)

opts := []grpc.ServerOption{
Expand Down
Loading