Skip to content

Commit

Permalink
use simpler telemetry_option structure and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ruoss committed Nov 19, 2021
1 parent 0e77612 commit 1d15091
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ You can override the global configuration by passing overrides to `:telemetry.at

The following configuration options are supported:

|Option|Description|Default|
|-|-|-|
|`tracer`|Tracer instance to use for reporting traces (*required*)||
|`service`|Service name for Ecto traces|`ecto`|
|`truncate`|Maximum length of a query (excess will be truncated)|5000|
| Option | Description | Default |
| ---------- | -------------------------------------------------------- | ------- |
| `tracer` | Tracer instance to use for reporting traces (_required_) | |
| `service` | Service name for Ecto traces | `ecto` |
| `truncate` | Maximum length of a query (excess will be truncated) | 5000 |

### 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`.
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/config.exs
Expand All @@ -97,3 +97,17 @@ config :my_app, MyApp.Repo,
{SpandexEcto.EctoLogger, :trace, ["database_name"]}
]
```

## Customizing Span Resources

By default, SpandexEcto uses the query as name for the span's resource. In
order get a better feeling for the context of your spans, you can label your
span's resources using the option [`:telemetry_options`](https://hexdocs.pm/ecto/Ecto.Repo.html#module-shared-options)
of almost all of `Ecto.Repo`'s repository functions.

### Examples

```elixir
Repo.all(query, telemetry_options: [spandex_resource: "users-with-addresses"])
Repo.get!(User, id, telemetry_options: [spandex_resource: "get-user"])
```
2 changes: 1 addition & 1 deletion lib/spandex_ecto/telemetry_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule SpandexEcto.TelemetryAdapter do
decode_time: Map.get(measurements, :decode_time, 0),
queue_time: Map.get(measurements, :queue_time, 0),
result: wrap_result(metadata.result),
resource: get_in(metadata, [:options, :spandex, :resource])
resource: get_in(metadata, [:options, :spandex_resource])
}

EctoLogger.trace(log_entry, "#{repo_name}_database", config)
Expand Down

0 comments on commit 1d15091

Please sign in to comment.