forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stop creating new otel interceptor to avoid memory leak (argopro…
…j#15174) Signed-off-by: Alexander Matyushentsev <[email protected]> Signed-off-by: jmilic1 <[email protected]>
- Loading branch information
Showing
5 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package grpc | ||
|
||
import ( | ||
"sync" | ||
|
||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
var ( | ||
otelUnaryInterceptor grpc.UnaryClientInterceptor | ||
otelStreamInterceptor grpc.StreamClientInterceptor | ||
interceptorsInitialized = sync.Once{} | ||
) | ||
|
||
// otel interceptors must be created once to avoid memory leak | ||
// see https://github.com/open-telemetry/opentelemetry-go-contrib/issues/4226 for details | ||
func ensureInitialized() { | ||
interceptorsInitialized.Do(func() { | ||
otelUnaryInterceptor = otelgrpc.UnaryClientInterceptor() | ||
otelStreamInterceptor = otelgrpc.StreamClientInterceptor() | ||
}) | ||
} | ||
|
||
func OTELUnaryClientInterceptor() grpc.UnaryClientInterceptor { | ||
ensureInitialized() | ||
return otelUnaryInterceptor | ||
} | ||
|
||
func OTELStreamClientInterceptor() grpc.StreamClientInterceptor { | ||
ensureInitialized() | ||
return otelStreamInterceptor | ||
} |