Cannot start observer: (UndefinedFunctionError) function :observer.start/0 is undefined

If I start the Elixir repl with iex, I can start the observer by :observer.start(). So far, so good.
If a create an app with mix new myapp and start it with iex -S mix, attempting to start the observer results in the following error:

** (UndefinedFunctionError) function :observer.start/0 is undefined (module :observer is not available)
    :observer.start()
    iex:2: (file)

I used to be able to start the observer within a running mix project using previous versions of Erlang and Elixir (I’m now using 25.3.2.2/1.15.0). What happened? Am I missing anything?

Thanks.

7 Likes

This looks like an issue caused by code path pruning introduced in Elixir 1.15.

if you have an application or dependency that does not specify its dependencies on Erlang and Elixir application, it may no longer compile successfully in Elixir v1.15

The fix is to add :observer and :wx to your list of :extra_applications in mix.exs.

It’s a bit strange that we need to opt-in to something in a mix project that’s already available by default in vanilla iex, though.

10 Likes

Done, but :observer.open() results in the following error:

{:error,
 {:undef,
  [
    {:observer_backend, :sys_info, [], []},
    {:observer_sys_wx, :init, 1, [file: ~c"observer_sys_wx.erl", line: 50]},
    {:wx_object, :init_it, 6, [file: ~c"wx_object.erl", line: 404]},
    {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 240]}
  ]}}

Any idea why?

Should be :observer.start().

1 Like

I mistyped the command, I actually used :observer.start() and got the error message…

It looks like you need :observer, :wx, and :runtime_tools in your :extra_applications

21 Likes

saved me hehe, I wonder why after upgrading to 1.15 :observer.start` is undefined now it work

Correct. I also submitted a bug report upstream.

7 Likes

Seems that not only :observer is an issue.
After upgrading to elixir 1.15 and rebuilding project dialyzer stopped working as well.

mix dialyzer now gives this:

Error loading poison, dependency list may be incomplete.
 {~c"no such file or directory", ~c"poison.app"}
Error loading table, dependency list may be incomplete.
 {~c"no such file or directory", ~c"table.app"}
Error loading myxql, dependency list may be incomplete.
 {~c"no such file or directory", ~c"myxql.app"}
Error loading tds, dependency list may be incomplete.
 {~c"no such file or directory", ~c"tds.app"}
Error loading bandit, dependency list may be incomplete.
 {~c"no such file or directory", ~c"bandit.app"}
Error loading ecto_psql_extras, dependency list may be incomplete.
 {~c"no such file or directory", ~c"ecto_psql_extras.app"}
Error loading ecto_mysql_extras, dependency list may be incomplete.
 {~c"no such file or directory", ~c"ecto_mysql_extras.app"}
Error loading ecto_sqlite3_extras, dependency list may be incomplete.
 {~c"no such file or directory", ~c"ecto_sqlite3_extras.app"}
[:arangox, :asn1, :bandit, :benchee, :broadway, :broadway_kafka, :brod, :castore, :certifi, :compiler, :core, :cowboy, :cowboy_telemetry, :cowlib, :crc32cer, :crypto, :db_connection, :decimal, :deep_merge, :ecto, :ecto_mysql_extras, :ecto_psql_extras, :ecto_sql, :ecto_sqlite3, :ecto_sqlite3_extras, :eex, :elixir, :ex_json_schema, :ex_raconteur, :expo, :exqlite, :faker, :fastglobal, :gen_stage, :gettext, :gun, :hackney, :hammox, :hpax, :httpoison, :idna, :jason, :joken, :jose, :json_logic, :kafka_protocol, :kernel, :logger, :metrics, :mime, ...]
Looking up modules in dialyxir_erlang-26.0.2_elixir-1.15.2_deps-dev.plt
** (UndefinedFunctionError) function :dialyzer_plt.plt_kind/1 is undefined (module :dialyzer_plt is not available)
    (dialyzer 5.1) :dialyzer_plt.plt_kind(~c"/*******project_path/_build/dev/dialyxir_erlang-26.0.2_elixir-1.15.2_deps-dev.plt")
    (dialyzer 5.1) dialyzer.erl:294: :dialyzer.plt_info/1
    (dialyxir 1.3.0) lib/dialyxir/plt.ex:243: Dialyxir.Plt.plt_files/1
    (dialyxir 1.3.0) lib/dialyxir/plt.ex:16: Dialyxir.Plt.find_plts/3
    (dialyxir 1.3.0) lib/mix/tasks/dialyzer.ex:254: Mix.Tasks.Dialyzer.check_plt/1
    (dialyxir 1.3.0) lib/mix/tasks/dialyzer.ex:174: Mix.Tasks.Dialyzer.run/1
    (mix 1.15.2) lib/mix/task.ex:447: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.15.2) lib/mix/cli.ex:92: Mix.CLI.run_task/2

After downgrading back to Elixir 1.14, everything works like a charm.

Checking PLT...
[:arangox, :asn1, :benchee, :broadway, :broadway_kafka, :brod, :castore, :certifi, :compiler, :core, :cowboy, :cowboy_telemetry, :cowlib, :crc32cer, :crypto, :db_connection, :decimal, :deep_merge, :ecto, :ecto_sql, :ecto_sqlite3, :eex, :elixir, :ex_json_schema, :ex_raconteur, :expo, :exqlite, :faker, :fastglobal, :gen_stage, :gettext, :hackney, :hammox, :hpax, :httpoison, :idna, :jason, :joken, :jose, :json_logic, :kafka_protocol, :kernel, :logger, :metrics, :mime, :mimerl, :mint, :mox, :nanoid, :nimble_options, ...]
Looking up modules in dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Looking up modules in dialyxir_erlang-26.0_elixir-1.14.5.plt
Looking up modules in dialyxir_erlang-26.0.plt
Finding applications for dialyxir_erlang-26.0.plt
Finding modules for dialyxir_erlang-26.0.plt
Creating dialyxir_erlang-26.0.plt
Looking up modules in dialyxir_erlang-26.0.plt
Removing 3 modules from dialyxir_erlang-26.0.plt
Checking 18 modules in dialyxir_erlang-26.0.plt
Adding 190 modules to dialyxir_erlang-26.0.plt
done in 0m7.59s
Finding applications for dialyxir_erlang-26.0_elixir-1.14.5.plt
Finding modules for dialyxir_erlang-26.0_elixir-1.14.5.plt
Copying dialyxir_erlang-26.0.plt to dialyxir_erlang-26.0_elixir-1.14.5.plt
Looking up modules in dialyxir_erlang-26.0_elixir-1.14.5.plt
Checking 208 modules in dialyxir_erlang-26.0_elixir-1.14.5.plt
Adding 253 modules to dialyxir_erlang-26.0_elixir-1.14.5.plt
done in 0m7.08s
Finding applications for dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Finding modules for dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Copying dialyxir_erlang-26.0_elixir-1.14.5.plt to dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Looking up modules in dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Checking 461 modules in dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
Adding 2046 modules to dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt
done in 0m36.32s
No :ignore_warnings opt specified in mix.exs. Using default: .dialyzer_ignore.exs.

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/dialyxir_erlang-26.0_elixir-1.14.5_deps-dev.plt',
  files: ['/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/lib/ex_raconteur/ebin/Elixir.ExRaconteur.Struct.CollectorStep.beam',
   '/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/lib/ex_raconteur/ebin/Elixir.ExRaconteur.Topic.BroadwayConsumer.State.beam',
   '/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/lib/spec/ebin/Elixir.ExRaconteur.Spec.Struct.Consumer.beam',
   '/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/lib/ex_raconteur_web/ebin/Elixir.ExRaconteurWeb.Endpoint.beam',
   '/Users/konstantinzolotarev/Coding/squillo/ex_raconteur_umbrella/_build/dev/lib/ex_raconteur/ebin/Elixir.ExRaconteur.Explainer.beam',
   ...],
  warnings: [:unknown]
]
Total errors: 3, Skipped: 0, Unnecessary Skips: 9
done in 0m3.45s
lib/ex_raconteur/file_service/adapter/behaviour.ex:11:unknown_type
Unknown type: Core.child_spec/0.
________________________________________________________________________________
lib/ex_raconteur/file_service/adapter/behaviour.ex:11:unknown_type
Unknown type: FileService.t/0.
________________________________________________________________________________
lib/mix/tasks/arango.create.collections.ex:1:callback_info_missing
Callback info about the Mix.Task behaviour is not available.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2
2 Likes

That’s a Dialyxir issue and there are open PRs under consideration!

4 Likes

After adding :observer, :wx and :runtime_tools to :extra_application I get:

[notice] Application runtime_tools exited: :stopped
** (Mix) Could not start application observer: could not find application file: observer.app

Which OS are you using? Certain operating systems break Erlang into several packages, you need to make sure those packages are installed.

That would be Ubuntu 22.04

Some guy called Jose Valim said the same thing on stack overflow eight years ago

1 Like

Will adding :observer and :wx be problematic for production releases where we are not installing the underlying wx libraries as part of our docker image?

I am having a similar problem, I am using Sonoma 14.1.1 (m1), erlang 25.3.2.7, the issues boils in my case down to wxwidget compilation with erlang. I have not been able to compile erlang passing the --enable-wx --with-wx-config option.

it keep failing with the next:

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [../priv/aarch64-apple-darwin23.1.0/erl_gl.so] Error 1

it was an issue in the build for Mac with that erlang version, take a Look at the
issue

tks @benstepp it works for me,
i am using Windows 11, Elixir 1.16.2 and Erlang 26.2.1

There’s a hacky way to start the observer application, even if it’s not part of your extra_applications.

The only requirement is to have the wx and observer modules compiled somewhere in your system.

Load an IEx session that knows about wx/observer. It’s a plain iex call in my case, e.g. not iex -S mix.

Having the IEx session open, figure out where the compiled modules are:

iex-without-mix> :code.get_path()

[
  #...
 ~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/wx-2.3.1/ebin",
 ~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/observer-2.15.1/ebin",
  #...
]

Go back to the iex -S mix session and add those paths:

iex-with-mix> :code.add_path  ~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/wx-2.3.1/ebin"
true
iex-with-mix> :code.add_path  ~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/observer-2.15.1/ebin"
true

Now we can start the observer application:

iex-with-mix> Application.start(:wx)
:ok
iex-with-mix> Application.start(:observer)
:ok
iex-with-mix> :observer.start

A fragile automation with ~/.iex.exs file:

:code.add_path(~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/wx-2.3.1/ebin")
:code.add_path(~c"/Users/username/.asdf/installs/erlang/26.1.1/lib/observer-2.15.1/ebin")
Application.start(:wx)
Application.start(:observer)

Having the above lines in the ~/.iex.exs file, allows a freshly started iex -S mix session to launch the observer with just the :observer.start() command.

Did you try the options listed here: Observer in iex -S mix - #5 by axelson?

2 Likes