Skip to content

Commit

Permalink
chore: wire up otel tracing in client
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps committed Jan 29, 2025
1 parent 8b8d19b commit dcfa21c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 62 deletions.
35 changes: 6 additions & 29 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
"go.uber.org/zap/zapcore"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

var (
Expand Down Expand Up @@ -364,8 +362,12 @@ func run(ctx context.Context, logger *zap.Logger, cfg *config.Config) error {
// starts grpc server
g.Go(grpcServer.Run)

ipch := &inprocgrpc.Channel{}
handlers.ForEach(ipch.RegisterService)
var ipch grpc.ClientConnInterface = &inprocgrpc.Channel{}
handlers.ForEach(ipch.(*inprocgrpc.Channel).RegisterService)

if cfg.Tracing.Enabled {
ipch = grpchan.InterceptClientConn(ipch, otelgrpc.UnaryClientInterceptor(), nil)
}

httpServer, err := cmd.NewHTTPServer(ctx, logger, cfg, ipch, info)
if err != nil {
Expand Down Expand Up @@ -419,28 +421,3 @@ func initMetaStateDir(cfg *config.Config) error {

return ensureDir(cfg.Meta.StateDirectory)
}

// clientConn constructs and configures a client connection to the underlying gRPC server.
func clientConn(ctx context.Context, cfg *config.Config) (*grpc.ClientConn, error) {
opts := []grpc.DialOption{grpc.WithBlock()}
if cfg.Tracing.Enabled {
opts = append(opts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
}
switch cfg.Server.Protocol {
case config.HTTPS:
creds, err := credentials.NewClientTLSFromFile(cfg.Server.CertFile, "")
if err != nil {
return nil, fmt.Errorf("loading TLS credentials: %w", err)
}

opts = append(opts, grpc.WithTransportCredentials(creds))
case config.HTTP:
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

dialCtx, dialCancel := context.WithTimeout(ctx, 5*time.Second)
defer dialCancel()

return grpc.DialContext(dialCtx,
fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.GRPCPort), opts...)
}
7 changes: 3 additions & 4 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ import (
type GRPCServer struct {
*grpc.Server

logger *zap.Logger
cfg *config.Config
ln net.Listener
registrar grpc.ServiceRegistrar
logger *zap.Logger
cfg *config.Config
ln net.Listener

shutdownFuncs []func(context.Context) error
}
Expand Down
29 changes: 0 additions & 29 deletions internal/cmd/grpc_test.go

This file was deleted.

0 comments on commit dcfa21c

Please sign in to comment.