From b0d9d2544376cca33b21b9edf3574322b9e25753 Mon Sep 17 00:00:00 2001 From: Wessie Date: Fri, 2 Feb 2024 23:54:17 +0000 Subject: [PATCH] telemetry: disable telemetry by default --- cmd/hanyuu/main.go | 2 +- rpc/client.go | 8 +++----- telemetry/otel.go | 8 ++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/hanyuu/main.go b/cmd/hanyuu/main.go index 087a2e7c..a7a4918c 100644 --- a/cmd/hanyuu/main.go +++ b/cmd/hanyuu/main.go @@ -187,7 +187,7 @@ func main() { // setup configuration file as top-level flag flag.StringVar(&configFile, "config", "hanyuu.toml", "filepath to configuration file") flag.StringVar(&logLevel, "loglevel", "info", "loglevel to use") - flag.BoolVar(&useTelemetry, "telemetry", true, "to enable telemetry") + flag.BoolVar(&useTelemetry, "telemetry", false, "to enable telemetry") // add all our top-level flags as important flags to subcommands flag.VisitAll(func(f *flag.Flag) { diff --git a/rpc/client.go b/rpc/client.go index d5d16680..8f94632b 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -5,13 +5,14 @@ import ( radio "github.com/R-a-dio/valkyrie" "github.com/R-a-dio/valkyrie/util/eventstream" - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" grpc "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" emptypb "google.golang.org/protobuf/types/known/emptypb" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" ) +var GrpcDial = grpc.Dial + func PrepareConn(addr string) *grpc.ClientConn { if len(addr) == 0 { panic("invalid address passed to PrepareConn: empty string") @@ -21,10 +22,7 @@ func PrepareConn(addr string) *grpc.ClientConn { addr = "localhost" + addr } - conn, err := grpc.Dial(addr, - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithStatsHandler(otelgrpc.NewClientHandler()), - ) + conn, err := GrpcDial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { panic("failed to setup grpc client: " + err.Error()) } diff --git a/telemetry/otel.go b/telemetry/otel.go index 2e727980..b9dc0b32 100644 --- a/telemetry/otel.go +++ b/telemetry/otel.go @@ -53,6 +53,7 @@ func Init(ctx context.Context, service string) (*trace.TracerProvider, error) { mariadb.DatabaseConnectFunc = DatabaseConnect website.NewRouter = NewRouter rpc.NewGrpcServer = NewGrpcServer + rpc.GrpcDial = GrpcDial return tp, err } @@ -77,3 +78,10 @@ func NewGrpcServer(opts ...grpc.ServerOption) *grpc.Server { opts = append(opts, grpc.StatsHandler(otelgrpc.NewServerHandler())) return grpc.NewServer(opts...) } + +func GrpcDial(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { + opts = append(opts, + grpc.WithStatsHandler(otelgrpc.NewClientHandler()), + ) + return grpc.Dial(addr, opts...) +}