-
Notifications
You must be signed in to change notification settings - Fork 838
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
bug(metrics-sdk): destructing ObservableResultImpl
breaks collecting metrics value
#3293
Comments
Most of our SDK class methods are not safe to be called without a proper receiver being set, e.g. const { getTracer } = tracerProvider;
getTracer('my-tracer'); // throws TypeError I believe this is a common pattern in the language. Is this callback style widely adopted? |
I'm not sure actually, we use it internally at my company for some case but not everytime |
I'd recommend avoiding extracting methods from a class instance, as we can not guarantee class methods are safe to be called without a receiver. Does this sound reasonable to you? |
Yeah it is but i'm not sure how we should document this, i don't think end user will not think this is a bug from otel |
I didn’t know you could destruct class instance like this 🤔 |
We can explicitly declare the However, this requires manual maintenance on the type of those methods, as tsc can not generate it for us (for now). |
you can't always as demonstrated In JS I think it is somewhat common to destructure callback arguments like that. I've definitely done it and seen it done. I don't think there are many places in our API where we would have to solve this problem |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Metrics SDK: 0.32.0
yield:
Because destructing set the
this
context ofobserve
to the one in the callback instead of theObservableResultImpl
.The fix is quite straightforward:
I'm not sure what we should do here as i don't expect end user to understand why this doesnt work, but at the same time not a lot of people will hit this. WDYT ?
cc @legendecas since you worked on the metrics sdk you might have an opinion on this ?
The text was updated successfully, but these errors were encountered: