Worker registered name not showing in observer

Hi…

I am registering two workers for my application supervision tree:

defmodule SamlyHowto.Application do
  use Application

  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
    import Supervisor.Spec

    # Define workers and child supervisors to be supervised
    children = [
      # Start the endpoint when the application starts
      supervisor(SamlyHowtoWeb.Endpoint, []),
      # Start your own worker by calling: SamlyHowto.Worker.start_link(arg1, arg2, arg3)
      # worker(SamlyHowto.Worker, [arg1, arg2, arg3]),
      worker(Samly.Provider, [], [id: Fed1]),
      worker(Samly.Provider, [], [id: Fed2]),
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: SamlyHowto.Supervisor]
    Supervisor.start_link(children, opts)
  end

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  def config_change(changed, _new, removed) do
    SamlyHowtoWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end

Samly.Provider defines their start_link function like this:

def start_link(gs_opts \\ []) do
    GenServer.start_link(__MODULE__, [], gs_opts)
end

As per the docs, I thought they should have been named Fed1 and Fed2… I have also tried the following (adding name):

  worker(Samly.Provider, [], [id: Fed1, name: Fed1]),
  worker(Samly.Provider, [], [id: Fed2, name: Fed2])

The examples on this page suggests that “name” should do the job:

But here there is no mention of “name” being an option here:

https://hexdocs.pm/elixir/Supervisor.Spec.html#worker/3

When I run observer.start() the registered name doesn’t appear (however I can see the numbered processes) there OR even when I run Process.registered() from IEX there is no mention of the name, but the app launches ok…

[:cowboy_clock, :erl_prim_loader, SamlyHowto.PubSub.Supervisor,
 :ssl_connection_sup, Logger.WatcherSupervisor, :user_drv,
 SamlyHowtoWeb.Endpoint.LongPoll.Supervisor, :ssl_admin_sup,
 SamlyHowtoWeb.Endpoint.Server, :ssl_sup, SamlyHowtoWeb.Endpoint.Config,
 :httpd_sup, :pg2, :phoenix_live_reload_file_monitor, :elixir_config,
 SamlyHowto.PubSub, :elixir_code_server, Hex.Supervisor, :ssl_pem_cache,
 :hex_fetcher, :ssl_manager, SamlyHowtoWeb.Endpoint, :inet_db,
 :ssl_listen_tracker_sup, Hex.Registry.Server, :kernel_safe_sup, Hex.State,
 :runtime_tools_sup, :global_group, :rex, :httpc_sup, :httpc_hex, :kernel_sup,
 IEx.Supervisor, :global_name_server, :dtls_udp_sup, :httpc_profile_sup,
 SamlyHowto.Supervisor, :httpc_manager, :file_server_2, :dtls_connection_sup,
 :httpc_handler_sup, :ftp_sup, Phoenix.Supervisor, :esaml_ets_table_owner,
 :tls_connection_sup, Gettext.ExtractorAgent, :standard_error, :inets_sup,
 Mix.ProjectStack, ...]

What I am doing wrong?

Thanks,
Nathan

Here to answer my own question… just got mixed up with arguments and opts with the worker/3() call…

children = [
  # Start the endpoint when the application starts
  supervisor(SamlyHowtoWeb.Endpoint, []),
  # Start your own worker by calling: SamlyHowto.Worker.start_link(arg1, arg2, arg3)
  # worker(SamlyHowto.Worker, [arg1, arg2, arg3]),
  worker(Samly.Provider, [[name: Fed1]], [id: Fed1]),
  worker(Samly.Provider, [[name: Fed2]], [id: Fed2]),
]
2 Likes

I’m wondering how to achieve this with child spec, which replaces the deprecated Supervisor.Spec module. I’d like my process passed to a supervisor as a child spec to appear with a nice human readable name in the observer “Applications” tab rather than just seeing a pid.

1 Like

Ditto Ditto