diff --git a/README.md b/README.md index 5187bec..2208e0e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Hex pm](http://img.shields.io/hexpm/v/spandex_ecto.svg?style=flat)](https://hex.pm/packages/spandex_ecto) [![SourceLevel](https://sourcelevel.io/github/spandex-project/spandex_ecto.svg)](https://sourcelevel.io/github/spandex-project/spandex_ecto) -Tools for integrating Ecto with Spandex +Tools for integrating Ecto with Spandex. ## Limitations @@ -30,35 +30,46 @@ end ## Configuration +Configure `SpandexEcto` globally in your application config: + ```elixir +# config/config.exs + config :spandex_ecto, SpandexEcto.EctoLogger, service: :ecto, # Optional tracer: MyApp.Tracer, # Required ``` -### For Ecto 2 +Then attach it to your repository's telemetry events: ```elixir -# Be aware that this is a *compile* time configuration. As such, if you change this you -# may need to `mix compile --force` and/or `mix deps.compile --force ecto` -config :my_app, MyApp.Repo, - loggers: [{Ecto.LogEntry, :log, [:info]}, {SpandexEcto.EctoLogger, :trace, ["database_name"]}] - +# lib/my_app/application.ex + +:telemetry.attach( + "spandex-query-tracer", + # this should match your repo's telemetry prefix + [:my_app, :repo, :query], + &SpandexEcto.TelemetryAdapter.handle_event/4, + # this config will override the global config + tracer: MyApp.OtherTracer +) ``` -### For Ecto 3 +> NOTE: **If you are upgrading from Ecto 2**, make sure to **remove** the `loggers` +> entry from your configuration after adding `:telemetry.attach/4`. -```elixir -# in application.ex -:telemetry.attach("spandex-query-tracer", [:my_app, :repo_name, :query], &SpandexEcto.TelemetryAdapter.handle_event/4, nil) -``` +### Ecto 2 -> NOTE: **If you are upgrading from Ecto 2**, make sure to **remove** the `loggers` -> entry from your configuration after adding the `:telemetry.attach`. +To integrate `SpandexEcto` with pre-`:telemetry` versions of Ecto you need to add `SpandexEcto.EctoLogger` as a logger to your repository. -If your repo is not named like `MyApp.Repo`, you'll need to set `:telemetry_prefix` in your repo config: +Be aware that this is a *compile* time configuration. As such, if you change this you may need to `mix compile --force` and/or `mix deps.compile --force ecto`. ```elixir -config :my_app, MyApp.Something.RepoName, - telemetry_prefix: [:my_app, :repo_name] +# config/config.exs + +config :my_app, MyApp.Repo, + loggers: [ + {Ecto.LogEntry, :log, [:info]}, + {SpandexEcto.EctoLogger, :trace, ["database_name"]} + ] ```