open-telemetry / open-telemetry/opentelemetry-cpp
When using CreateInt64ObservableCounter I get "Error during observe.The metric storage is invalid"
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 632
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 75
Description
Describe your environment
opentelemetry-cpp: 1.8.1
gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-4)
Fedora release 37
Steps to reproduce
Using a simple OStreamMetricExporter and observable counter meter I find if the counter fall out of scope before running it errors in debug or segfaults in release.
I assume I am using it incorrectly, but I would assume when the counter goes out of scope it should clean up it's resource correctly.
int main()
{
create_exporter();
auto meterProvider = metrics_api::Provider::GetMeterProvider();
auto meter = meterProvider->GetMeter("test", "");
{
auto counter = meter->CreateInt64ObservableCounter("counter");
counter->AddCallback(&get_counter, nullptr);
}
std::this_thread::sleep_for(std::chrono::seconds(10));
return 0;
}
What is the expected behavior?
Not to see a Error message or segfault
What is the actual behavior?
In debug build
[Error] File: opentelemetry-cpp/1.8.1/sdk/src/metrics/state/observable_registry.cc:55[ObservableRegistry::Observe] - Error during observe.The metric storage is invalid
In Release build it segfaults
Additional notes
The life times and ownership of opentelemetry-cpp object is not clear from the documentation
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with sdk/src/metrics/state/observable_registry.cc:55 and reproduce the provided observable-counter example using opentelemetry-cpp 1.8.1, including both debug and release builds. Trace what happens after the counter leaves scope; done means the exporter continues without the invalid-storage error or a segmentation fault, with ownership and lifetime expectations clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100