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
This only affects the JavaScript OpenTelemetry library
I'm trying to integrate OpenTelemetry into our library, which provides a client for the Cerbos gRPC/HTTP API.
We successfully incorporated tracing and span context propagation. Now I am trying to add metrics, and have run into difficulty.
Our approach so far has been to provide a CerbosInstrumentation class that implements the Instrumentation interface. Rather than patching require/imports, its enable method installs a hook into our client classes that allows us to instrument the gRPC/HTTP calls.
If I try to do the same with a meter field set to metrics.getMeter(), it doesn't work at all, which is really confusing.
On investigation, it seems that
we construct the instrumentation instance before setting up the SDK with the tracer and meter providers; then
trace.getTracer() gives us a proxy tracer that gets updated with the real instance once the NodeSDK sets the global tracer provider; but
metrics.getMeter() gives us a no-op meter that doesn't get updated once the NodeSDK sets the global meter provider.
I don't really understand how our instrumentation class is supposed to use the global meter provider given this behaviour. I'll probably try lazily initialisation so that we only create the histograms we need at the time we first want to record a metric, but this is a bit of a pain to implement compared to the tracer, and will only work if we assume the global meter provider doesn't change after the first time we attempt to record a metric (which is probably a reasonable assumption in the case of our library, but I don't know that it would be true for all libraries).
Would it make sense for @opentelemetry/api to provide a proxy meter implementation that behaves the same as the tracer one? If not, how should we handle this as library authors?
The text was updated successfully, but these errors were encountered:
Unfortunately, introducing a proxy meter would introduce a lot of complexity. For Metrics, multiple levels need to be proxied (MeterProvider, Meter, Instruments, batch observable Callbacks), whereas for tracing, only two need to be proxied (TracerProvider and Tracer). See also #3622
You can, however, re-create the instruments that you're using by overriding and implementing the _updateMetricInstruments() methods of the instrumentation (see the code from the http instrumentation). This is called when a new MeterProvider is set, which happens automatically when instrumentation is registered (via registerInstrumentations(), this has to be called after the SDK is initialized, though).
I'm trying to integrate OpenTelemetry into our library, which provides a client for the Cerbos gRPC/HTTP API.
We successfully incorporated tracing and span context propagation. Now I am trying to add metrics, and have run into difficulty.
Our approach so far has been to provide a
CerbosInstrumentation
class that implements theInstrumentation
interface. Rather than patchingrequire
/import
s, itsenable
method installs a hook into our client classes that allows us to instrument the gRPC/HTTP calls.Our instrumentation class has a
tracer
field that is set totrace.getTracer()
in the constructor. This works fine.If I try to do the same with a
meter
field set tometrics.getMeter()
, it doesn't work at all, which is really confusing.On investigation, it seems that
trace.getTracer()
gives us a proxy tracer that gets updated with the real instance once theNodeSDK
sets the global tracer provider; butmetrics.getMeter()
gives us a no-op meter that doesn't get updated once theNodeSDK
sets the global meter provider.I don't really understand how our instrumentation class is supposed to use the global meter provider given this behaviour. I'll probably try lazily initialisation so that we only create the histograms we need at the time we first want to record a metric, but this is a bit of a pain to implement compared to the tracer, and will only work if we assume the global meter provider doesn't change after the first time we attempt to record a metric (which is probably a reasonable assumption in the case of our library, but I don't know that it would be true for all libraries).
Would it make sense for
@opentelemetry/api
to provide a proxy meter implementation that behaves the same as the tracer one? If not, how should we handle this as library authors?The text was updated successfully, but these errors were encountered: