Skip to content

Commit 673d4b0

Browse files
authored
fix(auth): remove singleton and restore normal usage of otelgrpc.clientHandler (#13522)
refs: googleapis/google-api-go-client#2321 refs: googleapis/google-api-go-client#2329 refs: open-telemetry/opentelemetry-go-contrib#4226
1 parent 6f86983 commit 673d4b0

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

auth/grpctransport/grpctransport.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"log/slog"
2525
"net/http"
2626
"os"
27-
"sync"
2827

2928
"cloud.google.com/go/auth"
3029
"cloud.google.com/go/auth/credentials"
@@ -36,7 +35,6 @@ import (
3635
"google.golang.org/grpc"
3736
grpccreds "google.golang.org/grpc/credentials"
3837
grpcinsecure "google.golang.org/grpc/credentials/insecure"
39-
"google.golang.org/grpc/stats"
4038
)
4139

4240
const (
@@ -54,27 +52,6 @@ var (
5452
timeoutDialerOption grpc.DialOption
5553
)
5654

57-
// otelStatsHandler is a singleton otelgrpc.clientHandler to be used across
58-
// all dial connections to avoid the memory leak documented in
59-
// https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4226
60-
//
61-
// TODO: When this module depends on a version of otelgrpc containing the fix,
62-
// replace this singleton with inline usage for simplicity.
63-
// The fix should be in https://github.com/open-telemetry/opentelemetry-go/pull/5797.
64-
var (
65-
initOtelStatsHandlerOnce sync.Once
66-
otelStatsHandler stats.Handler
67-
)
68-
69-
// otelGRPCStatsHandler returns singleton otelStatsHandler for reuse across all
70-
// dial connections.
71-
func otelGRPCStatsHandler() stats.Handler {
72-
initOtelStatsHandlerOnce.Do(func() {
73-
otelStatsHandler = otelgrpc.NewClientHandler()
74-
})
75-
return otelStatsHandler
76-
}
77-
7855
// ClientCertProvider is a function that returns a TLS client certificate to be
7956
// used when opening TLS connections. It follows the same semantics as
8057
// [crypto/tls.Config.GetClientCertificate].
@@ -444,5 +421,5 @@ func addOpenTelemetryStatsHandler(dialOpts []grpc.DialOption, opts *Options) []g
444421
if opts.DisableTelemetry {
445422
return dialOpts
446423
}
447-
return append(dialOpts, grpc.WithStatsHandler(otelGRPCStatsHandler()))
424+
return append(dialOpts, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
448425
}

0 commit comments

Comments
 (0)