Skip to content

Commit

Permalink
Improve README
Browse files Browse the repository at this point in the history
* Make Ecto 3 config the default
* Describe how to override config in :telemetry.attach/4
  • Loading branch information
kamilkowalski committed Feb 7, 2021
1 parent 87140ae commit 54b68a9
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,30 +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`.
### Ecto 2

To integrate `SpandexEcto` with pre-`:telemetry` versions of Ecto you need to add `SpandexEcto.EctoLogger` as a logger to your repository.

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
# in application.ex
# If your repo is called `MyApp.Repo`, use `[:my_app, :repo, :query]`
# If your repo is called `Foo.Bar.Baz`, use `[:foo, :bar, :baz, :query]`
:ok = :telemetry.attach("spandex-query-tracer-repo_name", [:my_app, :repo, :query], &SpandexEcto.TelemetryAdapter.handle_event/4, nil)
```
# config/config.exs

> NOTE: **If you are upgrading from Ecto 2**, make sure to **remove** the `loggers`
> entry from your configuration after adding the `:telemetry.attach`.
config :my_app, MyApp.Repo,
loggers: [
{Ecto.LogEntry, :log, [:info]},
{SpandexEcto.EctoLogger, :trace, ["database_name"]}
]
```

0 comments on commit 54b68a9

Please sign in to comment.