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

No output if callback function ObserverResultT does not match ObservableInstrument primitive . #2694

Open
aaaugustine29 opened this issue Jun 5, 2024 · 2 comments
Assignees
Labels
bug Something isn't working Stale triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@aaaugustine29
Copy link

There is an "issue" to where if the primitive used in the instrument is not the same as the primitive used in the observer result template, when observe is called, there is no output. I was unable to trace exactly where there should be an exception or something similar. You can reproduce the error using the lines below. Please notice that the instrument is of type double, while the observer result is of type long (int64).

for instance, if we have the instrument:
static auto ramObs = meter2->CreateDoubleObservableGauge("RAM", "Free RAM", "MB");

And the in the callback function, we have the line:
opentelemetry::nostd::get<opentelemetry::nostd::shared_ptr<opentelemetry::metrics::ObserverResultT>>(observer_result)->Observe(value_, labels);

Then there is no output. My thought would be to have a comparison between the instrument primitive and the observer result primitive, but I cannot find a way to do so without changing any function signatures since the instrument has no knowledge of the workings of the callback function.

I'm happy to try and resolve this myself but can't seem to find a way that does not majorly change any of the existing code to where portability and compatibility would be maintained. Thanks in advance!

@aaaugustine29 aaaugustine29 added the bug Something isn't working label Jun 5, 2024
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jun 5, 2024
@marcalff marcalff self-assigned this Jun 12, 2024
@marcalff
Copy link
Member

And the in the callback function, we have the line: opentelemetry::nostd::get<opentelemetry::nostd::shared_ptropentelemetry::metrics::ObserverResultT>(observer_result)->Observe(value_, labels);

There is no such thing as a opentelemetry::nostd::shared_ptr<opentelemetry::metrics::ObserverResultT>

ObserverResultT is a template, and it is used with:

  • either ObserverResultT<int64_t>
  • or ObserverResultT<double>

In the measurement callback, the code gets a variant:

using ObserverResult = nostd::variant<nostd::shared_ptr<ObserverResultT<int64_t>>,
                                      nostd::shared_ptr<ObserverResultT<double>>>;

so when calling opentelemetry::nostd::get<xxx>, the callback only gets:

  • a pointer on a double result if the instrument is of type double
  • a pointer on an int result if the instrument is of type int.

Make sure to test for holds_alternative before calling get, or use get_if.
This will detect mismatch between the instrument type and the callback logic.

A callback function MUST match the instrument type.
Consider defining different callback functions for different types, and register the proper callback with an instrument.

If it helps, the caller can also provide arbitrary state in the state parameter when registering the callback.
The callback can then use the state passed to it to guide the logic.

If the problem still persists, please paste the relevant code from the instrumentation registration and the callback implementation, to clarify exactly what was attempted.

@marcalff marcalff added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 25, 2024
Copy link

This issue was marked as stale due to lack of activity.

@github-actions github-actions bot added the Stale label Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

No branches or pull requests

2 participants