You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API SHOULD provide some way to pass state to the callback. OpenTelemetry API authors MAY decide what is the idiomatic approach (e.g. it could be an additional parameter to the callback function, or captured by the lambda closure, or something else).
For async counters creation, please change:
the callback functions to add a void * state parameter,
the create observable counter methods to pass a void * state parameter
so this gets easier to use:
long counter_foo;
long counter_bar;
long counter_baz;
void generic_callback(void *state,
opentelemetry::metrics::ObserverResult<long> &obs) {
long *counter = static_cast<long *>(state);
obs.Observe(*counter);
}
void register_my_counter(const char *name, long *counter) {
void *state = counter;
g_otel_meter->CreateLongObservableCounter(name, generic_callback, state, "",
"");
}
register_my_counter("foo", &counter_foo);
register_my_counter("bar", &counter_bar);
register_my_counter("baz", &counter_baz);
Without it, the user code would have to define a different callback function for each observable counter,
which is not only inconvenient, but assumes the list of counters is static and known at compile time (it's not).
Regards.
The text was updated successfully, but these errors were encountered:
Thanks for raising the issue. I am moving it to Beta Release milestone as there is alternative solution (though this require multiple callback functions). Alpha release is very close now.
Greetings.
From the spec:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-counter-creation
For async counters creation, please change:
void * state
parameter,void * state
parameterso this gets easier to use:
Without it, the user code would have to define a different callback function for each observable counter,
which is not only inconvenient, but assumes the list of counters is static and known at compile time (it's not).
Regards.
The text was updated successfully, but these errors were encountered: