Skip to content

Commit

Permalink
telemetry: disable telemetry by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Feb 3, 2024
1 parent 7aab543 commit b0d9d25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/hanyuu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())
}
Expand Down
8 changes: 8 additions & 0 deletions telemetry/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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...)
}

0 comments on commit b0d9d25

Please sign in to comment.