-
Notifications
You must be signed in to change notification settings - Fork 150
Description
We recently noticed that ecto telemetry events emitted for postgres errors contains the full executed query including the actual values passed to queries or the actual values conflicting with constraints for example.
Here is a screenshot of an example:

This is a problem because we don't want to leak sensitive data such as personally identifying information to whatever system consumes these events.
Describe the solution you'd like
I think a builtin way to transform events, which allows library users to implement data scrubbing, would be a good addition to telemetry_ecto.
Our current workaround looks like this, we have our own module that attaches an event handler for repo events. The module has an event handler that forwards all events to OpentelemetryEcto.handle_event but scrubs errors of sensitive data.
defmodule MyApp.OpentelemetryEcto do
def setup(event_prefix, config \\ []) do
event = event_prefix ++ [:query]
:telemetry.attach({__MODULE__, event}, event, &__MODULE__.handle_event/4, config)
end
def handle_event(event, measurements, %{result: {:error, error}} = data, config) do
error = scrub_error(error)
OpentelemetryEcto.handle_event(event, measurements, %{data | result: {:error, error}}, config)
end
def handle_event(event, measurements, data, config) do
OpentelemetryEcto.handle_event(event, measurements, data, config)
end
defp scrub_error(%Postgrex.Error{} = error) do
...
end
end
Ideally OpentelemetryEcto provides a way to specify a module or function that will be called for all handled events to transform them.
The most basic way to achieve this could be OpentelemetryEcto.setup([:my_app, :repo], transform: fn _even -> ... end).
Describe alternatives you've considered
The workaround above works fine, but I believe it's worth having a builtin and documented way of doing this.
What do you think? I'd be happy to contribute a MR.