-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Wrap :proc_lib label functionality #13394
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
Wrap :proc_lib label functionality #13394
Conversation
@mtrudel 👀 |
Generally speaking, we only add a new Erlang/OTP feature to Elixir once it is the minimum support Erlang/OTP 27 version. However, given this is implemented simply as a process dictionary, I think we can implement the set_label natively in Elixir, which is the most important one: So my suggestion:
|
Minor concern that this being in the pdict is really an implementation detail on OTP's part; nothing in the corresponding workup mandates that it can be accessed / changed via the pdict, or says anything about the key name. Maybe if we mark it with a TODO to update it to the public |
Sounds good to me. We should also add a test, that runs only on Erlang/OTP 27+, that we can read the value with |
If we're implementing Also, would it make sense to do this for now? if function_exported?(:proc_lib, :set_label, 1) do
apply(:proc_lib, :set_label, [label])
else
# Use Process.put/2
end |
Because get_label uses a feature in Erlang/OTP 26.2+ for reading a particular key of the process dictionary instead of copying the whole dictionary. |
I wouldn't say so. Conditionals mean it will require more complicated testing to guarantee both branches work as expected. I prefer a temporary non-branching code. |
Support setting a process label, compatible with Erlang/OTP 27+ `:proc_lib.get_label/1`, which efficiently fetches the label without retrieving the entire process dictionary. Setting a label allows it to be displayed in tools like Observer when the underlying OTP version supports that.
d7030d3
to
1a8936d
Compare
Co-authored-by: Danila Fediashchin <danilagamma@gmail.com>
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.
Looks good to me.
Last question is: put_label/1
or set_label/1
? We use set_
prefix in a single place in Elixir, which is Node.set_cookie
. Storing in the process dictionary itself is called Process.put
.
Co-authored-by: Nathan Long <him@nathanmlong.com>
🤔 If we use I would lean toward |
I’m for |
Note: we are still deciding if it should be |
Co-authored-by: Jean Klingler <sabiwara@gmail.com>
Co-authored-by: Jean Klingler <sabiwara@gmail.com>
FWIW, "put label" to me sounds more like usages in maps, keywords, application env, and the process dictionary - putting a value at a key. Whereas "set label" sounds like "the process can have exactly one label", which is the case. That's not a very strong point because the function signature and docs would immediately make that clear, but it does seem to me like a stronger point than "we don't use the word 'set' very much". |
Yes, that was the last topic of our discussion. There is effectively no collection here, so |
I revised the doc string based on @josevalim's helpful comment here. I'd like to revise it again to clarify where the label may be seen "in crash logs"; it doesn't show up in the exception in my Phoenix application logs. Can anybody explain to me so that we can explain it here? |
It is not going to show until we change Elixir to handle it, but it will be changed before v1.17 is out. |
I think we did? Or is there more to be done? #13396 |
Does that show up only for regular processes but also GenServer? What about our own, such as Task and DynamicSupervisor? |
Oh you're right, these have separate formatters. Sorry still unfamiliar with the logger codebase. |
💚 💙 💜 💛 ❤️ |
Yay! I just published https://nathanmlong.com/2024/03/beam-process-labels/ discussing this |
I'll be adding support for this to Bandit and Thousand Island shortly! |
I'm open to reworking this completely, but I wanted to propose making the OTP 27.0
:proc_lib.set_label/1
functionality easy to use.I think we can make a lot of observability and error reporting clearer if we can start using these labels in a lot of places.
Example of effect: mtrudel/bandit#319