-
Notifications
You must be signed in to change notification settings - Fork 12
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
chore: fix setting tracing subscriber #723
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation mentions:
Note: Libraries should NOT call set_global_default()! That will cause conflicts when executables try to set them later.
It seems like we might want to use with_default
inside each function to prevent causing crashes if other shared libraries are also using tracing
.
We have a similar pending task for fixing the tokio runtime. That's currently blocked by the reqwest_middleware
not allowing a custom tokio runtime to be set.
WDYT?
Hey, thanks for the review! It's a good point that if another Rust lib imported in NodeJS sets I don't think switching to So I see two possible solutions:
Resolving this would be quite important, because it's a valuable debugging tool to observe released binaries. |
(Btw I had a quick look and our version of |
If mangle is used in the same way as it normally is (i.e. mangle a function name to be unique), I'm not sure how it would prevent the issue. The static memory location of the default logger would still be reused, right? |
The safest bet might be to log a warning when we can't set a default logger? Then we can at least get debug logs to work for now, without causing crashes. We can find a permanent solution in a follow-up task. |
Right, mangling is only relevant if the other shared lib was a C lib, but another Rust shared lib will have the same mangled name and can use that to look up the address of the static that holds the global logger? I'm unsure of the details of how this works exactly, but I'm curious to learn more. |
0da8b2b
to
0f405d2
Compare
Ok, done in 0f405d2 |
Previously we were only setting a default tracing subscriber for the current thread in
edr_napi
which precluded logs from other threads being collected.With this change, the subscriber is set globally for all threads so that we can get tracing output when running JS tests, e.g. from
hardhat-tests
:RUST_LOG=debug pnpm test
.