EctoQueryExplorer
Collect and analyze Ecto query telemetry. Find which code produces which queries, how often, and how long they take.
[!WARNING] Experimental. Use at your own risk.
Installation
Add dependency:
{:ecto_query_explorer, "~> 0.1"}Add a SQLite repo:
defmodule MyApp.EctoQueryExplorerRepo do use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.SQLite3 endConfigure:
# Enable stacktraces on your repo config :my_app, MyApp.Repo, stacktrace: true # Configure the SQLite repo config :my_app, MyApp.EctoQueryExplorerRepo, database: "/tmp/ecto-query-explorer.sqlite3" # Configure EctoQueryExplorer config :ecto_query_explorer, otp_app: :my_app, repo: MyApp.EctoQueryExplorerRepo, ets_table_name: :ecto_query_explorer_data, samples_to_keep: 5, source_ecto_repos: [MyApp.Repo]Add to supervision tree:
children = [ EctoQueryExplorer, MyApp.EctoQueryExplorerRepo ]Run migrations:
# In a migration file def up, do: EctoQueryExplorer.Migration0.up() def down, do: EctoQueryExplorer.Migration0.down()
Usage
# Dump collected data to SQLite
EctoQueryExplorer.Data.dump2sqlite()
# Find queries by pattern
EctoQueryExplorer.Queries.filter_by_query("SELECT%users%")
# Find queries by origin
EctoQueryExplorer.Queries.filter_by_mfa(MyApp.Accounts, :get_user, 1)
# Get top queries by execution count
EctoQueryExplorer.Queries.top_queries(10)
See module docs for more: EctoQueryExplorer, EctoQueryExplorer.Queries, EctoQueryExplorer.Data.
Releasing
mix bump patch # or minor, or major
git push origin main --tagsLicense
MIT. See LICENSE.