Attaching a telemetry handler for a dynamic repo

32 views
Skip to first unread message

Austin Ziegler

unread,
Dec 13, 2023, 12:59:51 AM12/13/23
to elixi...@googlegroups.com
We're (finally) looking at adding telemetry to our application, and we have recently added a necessary, but somewhat pathological case of dynamic repos (for Ecto.Adapters.SQLite3).

All of the examples for attaching telemetry handlers assume a static repo with no examples of attaching a handler for a dynamic repo, much less an *unnamed* (`name:  nil`) dynamic repo.

Are there recommendations or examples that I am missing, or does Ecto need such examples?

Greg Rychlewski

unread,
Dec 13, 2023, 4:17:52 PM12/13/23
to elixir-ecto
The telemetry event will always give you the dynamic repository used for the query. 

If you do MainRepo.put_dynamic_repo(SecondaryRepo) then telemetry will show SeconaryRepo.

If you do {:ok, pid} = MainRepo.start_link(config); MainRepo.put_dynamic_repo(pid) then telemetry will show MainRepo

Austin Ziegler

unread,
Dec 13, 2023, 5:02:37 PM12/13/23
to elixi...@googlegroups.com
But what if I use the returned pid directly? (I’m not, but it may be more durable than the method we are using now if we cross process boundaries.)

Should I set a custom prefix, or will it always be [:my_app, :repo] because of the use Ecto.Repo?

Like I said, I’m less concerned about the metadata than how to register for those events in the first place, given the unnamed nature of these dynamic repos.

-a

On Dec 13, 2023, at 16:17, Greg Rychlewski <greg.ry...@gmail.com> wrote:

The telemetry event will always give you the dynamic repository used for the query. 
--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/710295b3-155d-4bf9-a6ee-2e5cece01e3dn%40googlegroups.com.

Greg Rychlewski

unread,
Dec 17, 2023, 11:41:48 AM12/17/23
to elixir-ecto
Sorry I'm not sure I understand your question.

Whenever you start a repository, no matter if it is unnamed or named, it will be registered for telemetry. And the name won't show up in the telemetry metadata, only the repository module. So if you start the same repository multiple times each of them will be registered for telemetry and all of them will have the same repo metadata.

Reply all
Reply to author
Forward
0 new messages