diff --git a/README.md b/README.md index 8bf7a47..53b78d4 100644 --- a/README.md +++ b/README.md @@ -73,12 +73,13 @@ 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 | -| `query_only?` | Whether to omit queue/run_query/decode timings | false | +| 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 | +| `query_only?` | Whether to omit queue/run_query/decode timings | false | +| `resource_fun` | The function to convert a query to span's resource | & &1 | ### Ecto 2 @@ -109,3 +110,6 @@ of almost all of `Ecto.Repo`'s repository functions. Repo.all(query, telemetry_options: [spandex_resource: "users-with-addresses"]) Repo.get!(User, id, telemetry_options: [spandex_resource: "get-user"]) ``` + +Or, you can provide a function to to convert a query to the span's resource to the `resource_fun` option. +This is applied only the query doesn't have the `spandex_resource` telemetry option. diff --git a/lib/spandex_ecto/ecto_logger.ex b/lib/spandex_ecto/ecto_logger.ex index 34f5b19..bee97d7 100644 --- a/lib/spandex_ecto/ecto_logger.ex +++ b/lib/spandex_ecto/ecto_logger.ex @@ -22,6 +22,7 @@ defmodule SpandexEcto.EctoLogger do service = config[:service] || :ecto truncate = config[:truncate] || 5000 query_only? = config[:query_only?] + resource_fun = config[:resource_fun] || & &1 if tracer.current_trace_id() do now = :os.system_time(:nano_seconds) @@ -32,7 +33,7 @@ defmodule SpandexEcto.EctoLogger do |> String.slice(0, truncate) num_rows = num_rows(log_entry) - resource = log_entry[:resource] || query + resource = log_entry[:resource] || resource_fun.(query) queue_time = get_time(log_entry, :queue_time) query_time = get_time(log_entry, :query_time)