-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling otelgrpc.UnaryClientInterceptor
repeatedly creates multiple Int64Histogram
resulting in a memory leak
#4226
Calling otelgrpc.UnaryClientInterceptor
repeatedly creates multiple Int64Histogram
resulting in a memory leak
#4226
Comments
I encountered the same issue using the When using the router := mux.NewRouter()
router.Use(otelhttp.NewMiddleware("")) This results in the same memory leak. I've worked around the issue for now by using a no-op |
If only one middleware/Handler should be created for the lifetime of the application it feels like the sync.Once should be done within this library. |
I'll take a look at this. |
See external fix in googleapis/google-api-go-client#2329 |
I don't think we can do sync.Once, since the interceptors/stats handlers/etc. can be created with different MeterProviders, and we would want once instrument for each MeterProvider. I think this needs to be solved within the SDK itself. My current attempt to fix it: open-telemetry/opentelemetry-go#4820. Feedback is welcome. |
This will be fixed in the next otel-go release, since open-telemetry/opentelemetry-go#4820 merged. |
When moving from 0.47.0 to 0.49.0, we now see an extremely similar leak with We still have our patch in place for
We're going to move ahead with the same workaround we used for |
I can't seem to reopen this issue - should I open a new one ? |
Yes, please since it's not the same components. |
Description
Apologies, I'm not overly familiar with the Metrics side of OpenTelemetry - I'm also slightly unsure if the bug lays within this repository or in the otel API/SDK for Go itself.
We have a use case where we create and destroy gRPC clients throughout the long lifetime of our application. When we create new gRPC clients, we provide
otelgrpc.UnaryClientInterceptor()
as an interceptor. We've noticed slow memory leaks in our application and profiling reveals a large amount of the heap allocated bygo.opentelemetry.io/otel/internal/global.(*meter).Int64Histogram
. Looking into the implementation, it appears that whilst repeatedly callingMeterProvider.Meter
with the same name returns the sameMeter
, repeatedly callingMeter.Int64Histogram
with the same name creates a newInt64Histogram
each time. All of these are tracked internally in theinstruments
slice ofglobal.meter
and this is where the memory leak is sitting.Our interim solution has been to use a
sync.OnceValue
to only create the interceptors one during the lifetime of the application and to share these across the clients. It would be helpful to either have it documented that you should only create a single set of interceptors throughout the application lifetime, or to have the underlying issue resolved.Environment
otelgrpc
version: v0.42.0Steps To Reproduce
UnaryClientInterceptor()
.Int64Histogram
instruments created byUnaryClientInterceptor()
Expected behavior
The
Int64Histogram
to be reused or for a warning to be included in documentation regarding callingUnaryClientInterceptor
repeatedly.The text was updated successfully, but these errors were encountered: