Skip to content
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

Support for gauge/callback shutdown in python #4120

Open
LancelotGD opened this issue Aug 13, 2024 · 0 comments
Open

Support for gauge/callback shutdown in python #4120

LancelotGD opened this issue Aug 13, 2024 · 0 comments

Comments

@LancelotGD
Copy link

LancelotGD commented Aug 13, 2024

Is your feature request related to a problem?

Discussed in cpp api:#1836, #2232
Current python implementation do not support close callback or gauge from api endpoint. While Java version has suppoerted this feature:

//create gauge
ObservableDoubleGauge gauge = gaugeBuilder
                    .setDescription("gauge example")
                    .buildWithCallback(result -> result.record(valueHolder, attr));

//remove gauge
guage.close()

When I register a corresponding gauge to the SDK, my application needs to run for a long time and may register multiple different instruments. I use local caches like Guava and Caffeine to store objects used to process metrics. When these objects reach a certain size, they are evicted from memory. However, when I report a metric with the same name again, it prompts that a duplicate instrument has been created, causing the report to fail. The original callback monitoring the valueHolder is no longer accessible by the API due to the object being released, leading to a memory leak issue.

In python, it outputs warning:

[WARNING][None][/otel-auto-instrumentation-python/opentelemetry/sdk/metrics/_internal/__init__.py:274][create_observable_gauge()][msg] An instrument with name avg-metric-python, type ObservableGauge, unit 1 and description gauge reporter: avg-metric-python has been created already.

I notice that the validation of duplicate metric is different in java and python, and seems that python api doesn't supply a interface like "unregister_callback", .

Describe the solution you'd like

solution 1:
Can use close() interface to close instrument.
solution2:
Allow to re-link the new observed value to the previous created instrument

Describe alternatives you've considered

Actually, register instrument process in both meter and measurement_consumer module.

Additional Context

No response

Would you like to implement a fix?

None

@lzchen lzchen added sdk Affects the SDK package. metrics and removed sdk Affects the SDK package. labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants