-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to configure EctoLogger through :telemetry.attach/4 #21
Allow to configure EctoLogger through :telemetry.attach/4 #21
Conversation
Sorry this took so long to respond to! 😅 The only thing I can see is that we should add a note to the docs that demonstrates that this is possible and what the default is if you just set the config to |
The missing documentation is exactly why it's still a draft 😄 I'll update it and open a full PR. |
And no worries - if it wasn't upvoted and I didn't remind you then it wasn't that big of a problem I guess. In our umbrella we've ended up using one tracer extracted to a monitoring app which all other umbrella apps depend on. I think the change is worth introducing anyway - global configuration of libraries isn't a good pattern in my opinion as it's often limiting, and the community is shifting away from it in favor of runtime config or the |
For complex umbrella apps, having a global config for the :spandex_ecto library can be limiting - particularly when a different tracer is to be used depending on the repo. This change allows to pass configuration to the underlying EctoLogger module, like the `:tracer` option, through the `config` argument in `:telemetry.attach/4`.
* Make Ecto 3 config the default * Describe how to override config in :telemetry.attach/4
26c5ddb
to
54b68a9
Compare
I've changed the README so that it treats Ecto >=3 as the default - latest Ecto 2 release was in April 2019 and I don't think many people will configure I mentioned tests in my PR description but I now see there are none - I started adding some but it's a lot of work and is beyond the scope of this PR. I can open a new one that implements tests once I finish. |
I realized config options weren't documented anywhere, and also that this change allows specifying the database service name per repo - I've extended the docs. At our company |
Thanks for taking the time to work so hard on this! I didn't forget about it and I'm going to try to get it polished up and merged this weekend if I can find the time for it. |
No worries, let me know if I can help with the polishing - after all I'm Polish! |
Sorry, couldn't help myself. |
Hello guys, would really love to see this change merged, as I've being doing something similar in my fork. This obviously looks more polished than mine. |
+1 - Also running into this issue! Thanks @kamilkowalski. |
@GregMefford - What still needs to be polished? Happy to work on this. |
@kamilkowalski See my Configuration section suggestions below: ConfigurationConfigure # config/config.exs
config :spandex_ecto, SpandexEcto.EctoLogger,
service: :ecto, # Optional
tracer: MyApp.Tracer, # Required Then attach it to your repository's telemetry events: # lib/my_app/application.ex
:ok = :telemetry.attach(
"spandex-query-tracer",
# this should match your repo's telemetry prefix
[:my_app, :repo, :query],
&SpandexEcto.TelemetryAdapter.handle_event/4,
nil
) Or override the global config (useful for projects with multiple Ecto repos): # lib/my_app/other_repo.ex
defmodule MyApp.OtherRepo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
end # lib/my_app/config.exs
config :my_app, MyApp.OtherRepo
telemetry_prefix: [:my_app, :other_repo],
# other configs # lib/my_app/application.ex
:ok = :telemetry.attach(
"spandex-query-tracer-other-repo",
[:my_app, :other_repo, :query],
&SpandexEcto.TelemetryAdapter.handle_event/4,
# this config will override the global config
service: :other_db,
tracer: MyApp.OtherRepoTracer # maybe this tracer adds custom metadata/tags
)
|
@ggiill thanks for your suggestions - I've added matching |
Sorry this sat idle for so long! I think it's a nice improvement, and I'm glad it was possible to do this in a non-breaking way! |
For complex umbrella apps, having a global config for the
:spandex_ecto
library can be limiting - particularly when a different tracer is to be used depending on the repo.This change allows passing configuration to the underlying EctoLogger module, like the
:tracer
option, through theconfig
argument in:telemetry.attach/4
.Thanks to this change, the tracer could be configured when attaching SpandexEcto to telemetry events:
It's backward compatible and shouldn't cause problems, the
config
argument was unused before.Let me know what you think - I'd need to update docs and add some tests.