Skip to content
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

Lots of Telemetry Warnings #61

Closed
andyl opened this issue Jan 6, 2024 · 6 comments · Fixed by #62 or #63
Closed

Lots of Telemetry Warnings #61

andyl opened this issue Jan 6, 2024 · 6 comments · Fixed by #62 or #63

Comments

@andyl
Copy link
Contributor

andyl commented Jan 6, 2024

When I compile or run Tableau, I get many Telemetry Warnings

image

I get the same behavior on Elixir 1.15 and 1.16

I believe the warnings come from a library schematic in the telemetry_wrap function of schematic.ex.

Here's my workaround to remove the telemetry warnings:

image

Does anyone else see these warnings?

Are the telemetry metrics in Schematic necessary?

Is there a way to suppress the telemetry warnings without altering the Schematic code?

@mhanberg
Copy link
Collaborator

mhanberg commented Jan 6, 2024

It happens because schematic is being run at compile time, but the telemetry application hasn't started yet.

I haven't looked closely into how to fix it yet.

@andyl
Copy link
Contributor Author

andyl commented Jan 6, 2024

Gotcha. If you're up for it, I could submit PR to schematic to disable telemetry at compile time, and/or to allow application config to optionally disable schematic telemetry at run time. If you'd rather defer, no problem - lmk.

@mhanberg
Copy link
Collaborator

mhanberg commented Jan 7, 2024

I think it makes more sense to figure out how to start the telemetry application before the modules compile, or (which i think i'll do anyway) rewrite the parts that use schematic at compile time to use it at runtime.

@mhanberg mhanberg closed this as completed Jan 7, 2024
@andyl
Copy link
Contributor Author

andyl commented Jan 7, 2024

Sounds good. Just FYI here is the predicate code I used in my fork:

defmodule Schematic.TelemetryCfg do
  @moduledoc """
  Manage telemetry settings for Schematic.

  This module performs two functions:

  1. check to see if the current execution environment is `run-time` or
    `compile-time` (we want to disable telemetry at compile time).

  2. check to see if the application config has disabled telemetry

  ## Example

  In `config/config.exs`:

  ```elixir
    config :schematic, :config, disable_telemetry: true
  \```
  """

  @disable_telemetry_predicate Application.compile_env(:schematic, :config)[:disable_telemetry]

  @doc """
  Predicate used to determine if telemetry should be enabled in `Schematic`.

  To optionally disable schematic telemetry in your application, enter the following into your `config/config.exs` file:

  ```elixir
    config :schematic, :config, disable_telemetry: true
  \```
   """
  def enable_telemetry? do
    running?() && telemetry_allowed?()
  end

  defp telemetry_disabled? do
    @disable_telemetry_predicate
  end

  defp telemetry_allowed? do
    !telemetry_disabled?()
  end

  # from https://elixirforum.com/t/is-it-possible-to-detect-if-code-is-executing-at-compile-time/57728

  def compiling? do
    # TODO: When we depend on Elixir v1.11+ only, remove function_exported and elixir_compiler_pid
    process_alive?(:can_await_module_compilation?) ||
      process_alive?(:elixir_compiler_pid)
  end

  defp process_alive?(:can_await_module_compilation?) do
    Code.ensure_loaded?(Code) &&
      function_exported?(Code, :can_await_module_compilation?, 0) &&
      apply(Code, :can_await_module_compilation?, [])
  end

  defp process_alive?(name) do
    case Process.get(name) do
      nil -> false
      pid when is_pid(pid) -> true
    end
  end

  defp running? do
    ! compiling?()
  end
end

@mhanberg
Copy link
Collaborator

mhanberg commented Jan 7, 2024

a partial fix i believe is released with 0.14.2

@mhanberg
Copy link
Collaborator

mhanberg commented Jan 7, 2024

This should be completely fixed with 0.14.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants