-
Notifications
You must be signed in to change notification settings - Fork 821
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
Consider auto-enabling or warning if non-enabled context manager is used #1405
Comments
@dyladan With which version you reproduced the issue ? (both node and ot) |
Latest ot (0.10.2) Multiple node versions including the latest of both 12 and 14. The AsyncLocalStorageContextManager does not have this bug, but the version of node available in our target environment is running a version of node 12 that is not late enough to be able to use it. |
I can't reproduce with the following test (node v14.7.0, master branch): it('should not loose the context (async/await)', done => {
const scope1 = '1' as any;
contextManager.with(scope1, async () => {
assert.strictEqual(contextManager.active(), scope1);
await (async () => {})()
assert.strictEqual(contextManager.active(), scope1);
return done();
});
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);
}); And i believe this is tested with this test EDIT: I didnt mention it but i reproduce with your exact code though |
Following your example, another simple reproduction: const { AsyncHooksContextManager } = require("@opentelemetry/context-async-hooks");
const contextManager = new AsyncHooksContextManager();
const scope1 = '1';
contextManager.with(scope1, async () => {
console.log(contextManager.active()) // 1
await (async () => { })()
console.log(contextManager.active()) // Context { _currentContext: Map(0) {} }
}); |
I don't know what is different about it in the test environment vs in the reproduction. |
Fixed with one line: const { AsyncHooksContextManager } = require("@opentelemetry/context-async-hooks");
const contextManager = new AsyncHooksContextManager();
contextManager.enable()
const scope1 = '1';
contextManager.with(scope1, async () => {
console.log(contextManager.active())
await (async () => { })()
console.log(contextManager.active())
}); I feel silly now |
Ahah no worries i already spent few hours trying to debug issue when i wasn't enabling the it. Wondering if we could warn at some point that it is used without being enabled |
Is there some reason we don't automatically enable? |
@dyladan At the root i believe we wanted to choose whent to enable it (because the performance hit only is there after the enable), but i believe it don't make much sense with our current internal usage. Would be a breaking change though so we might want to take a decision before GA |
I think if the user creates an async hooks context manager, the expectation that async hooks is enabled is a reasonable one. |
Sounds related: #758 FWIW the |
Maybe instead we should remove enable/disable from the interface and always auto-enable? |
Closing this for the following reasons:
|
When a user creates an
AsyncHooksContextManager
, it is easy to forget to callenable
, which can cause issues when used with promises. We should consider enabling the context manager automatically, or at least warning if a context manager is used without a call toenable
.See an example of this confusion in the original issue description below
I have a simple use case which loses context when using
AsyncHooksContextManager
:output:
Seems very similar to #752 and #1101
I thought this case should have been solved by #1099
/cc @vmarchaud
The text was updated successfully, but these errors were encountered: