Would adding a new `Ecto.Query.comment/1` helper work?
MySchema
|> comment("My comment")
|> Repo.all()
This would basically generate "SELECT * FROM my_schema /* My comment */"
Then if we wanted to update all queries, we could override Ecto.Repo.prepare_query/3.
@impl true
def prepare_query(_operation, query, opts) do
comment_data = SQLCommenter.to_string(%{service: "my-service", parent_span_id: get_current_span_id()})
comment(query, ^comment_data)
end
I know you mentioned ecto prepares the queries, but could we put dynamic data in them if we set the adapter's prepare option to unnamed? Being able to add sql comments would be really helpful for integrations with observability tools like datadog and cyral.
If this is ok, then I think we'd need to figure out if we'd probably need to design the API for multiple comments and figure out if we'd append or prepend them to the sql statement. Maybe there would be an option like
comment("My comment", placement: :prepend)
comment("My comment", placement: :append)
I'm curious what you think of this.