Getting caller in Ecto :telemetry events

Problem: I am trying to identify where a bunch of root spans e.g. myapp.repo.query:users come from (which essentially map to a SELECT * from "users" AS u0 WHERE (u0."id" = $1)).

This could e.g. be the MFA of the caller, that could appear as the db.operation.name.

One could do this explicitly, but this requires to pass the MFA in every call site.

Any ideas here? Anyone solved this before?

1 Like

Hi, @aloukissas!

Seems like, that could be achieved by setting stacktrace: true in the Repo config. (Look up “stacktrace” keyword on this page Ecto.Repo — Ecto v3.12.4)

Then in the telemetry events in metadata there will be the stacktrace from where we could extract the caller’s MFA.

OpentelemetryEcto currently doesn’t provide with any option to support that integration. So will need to patch this

1 Like