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 1cc732b commit 26c5ddb
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 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,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"]}
]
```

0 comments on commit 26c5ddb

Please sign in to comment.