Skip to content

OpenTelemetry metrics create a memory leak when using ephemeral redis clients #3424

@rokn

Description

@rokn

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

Expected Behavior

When closing a redis client the open telemetry should stop observing it. Another option is to provide a way to unregister the listener

Current Behavior

Currently when instrumenting a redis client there is no way to stop observing it using the otel metrics. This also creates a hanging pointer to the redis client instance which can create memory leaks if the application creates many redis client instances.

Possible Solution

  1. Automatically stop observing the client when it's closed / destroyed in any way. (Prefferred option)
  2. Provide a way for manual stoping of the instrumentation

Steps to Reproduce

https://gist.github.com/rokn/8939cf0be0a70f873801f030218709a3
The gist provided is a minimal example which can demonstrate the issue.

  1. Run the above gist
  2. check localhost:8080/metrics curl localhost:8080/metrics | grep db_client_connections_usage

It has metrics for both clients.
3. Wait 10 secs

After the clients are closed the connections are 0 as expected but the metrics are still there(and the clients that provide those metrics)

Context (Environment)

We are creating many redis connections (1000+) and are sometimes closing them and need to cleanly discard these instances from memory and the metrics they "provide"

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions