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
telemetry implementation for Ecto 3 #68
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule ScoutApm.Instruments.EctoTelemetry do | ||
@doc """ | ||
Attaches an event handler for Ecto queries. | ||
|
||
Takes a fully namespaced Ecto.Repo module as the only argument. Example: | ||
|
||
ScoutApm.Instruments.EctoTelemetry.attach(MyApp.Repo) | ||
""" | ||
def attach(repo_module) do | ||
query_event = repo_module | ||
|> Module.split() | ||
|> Enum.map(& &1 |> Macro.underscore() |> String.to_atom()) | ||
|> Kernel.++([:query]) | ||
|
||
Telemetry.attach("scout-ecto-query-handler", query_event, ScoutApm.Instruments.EctoTelemetry, :handle_event, nil) | ||
end | ||
|
||
def handle_event([_app, _repo, :query], _value, metadata, _config) do | ||
ScoutApm.Instruments.EctoLogger.record(metadata) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay code reuse. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ defmodule ScoutApm.Mixfile do | |
{:hackney, "~> 1.0"}, | ||
|
||
{:approximate_histogram, "~>0.1.1"}, | ||
{:telemetry, "~> 0.2.0"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to cause problems installing the agent on older versions of the Phoenix stack? For instance, we had to do the 0.0.0 thing for poison and just guard against functions not being present at runtime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added fd7b299 to handle that |
||
|
||
######################### | ||
# Dev & Testing Deps | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that
scout-ecto-query-handler
string mean anything? Can we instrument multiple repos with this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
scout-ecto-query-handler
does need to be unique. https://hexdocs.pm/telemetry/0.2.0/Telemetry.html#attach_many/5 is available, though we could also make the string ID unique by including the repo information in it which would allow multiple calls toEctoTelemetry.attach
?