changed CHANGELOG.md
 
@@ -1,5 1,10 @@
1
1
## CHANGELOG
2
2
3
### `v1.25.2`
4
5
Fixes
6
* Fix edge case in new `Ecto` table name parsing. [#340](https://github.com/newrelic/elixir_agent/pull/340)
7
3
8
### `v1.25.1`
4
9
5
10
Fixes
changed VERSION
 
@@ -1 1 @@
1
- 1.25.1
1
1.25.2
changed hex_metadata.config
 
@@ -158,4 158,4 @@
158
158
{<<"optional">>,true},
159
159
{<<"repository">>,<<"hexpm">>},
160
160
{<<"requirement">>,<<">= 0.11.0">>}]]}.
161
- {<<"version">>,<<"1.25.1">>}.
161
{<<"version">>,<<"1.25.2">>}.
changed lib/new_relic/telemetry/ecto/handler.ex
 
@@ -29,7 29,7 @@ defmodule NewRelic.Telemetry.Ecto.Handler do
29
29
id = {:ecto_sql_query, make_ref()}
30
30
parent_id = Process.get(:nr_current_span) || :root
31
31
32
- with {datastore, {table, operation}} <- Metadata.parse(metadata) do
32
with {datastore, {operation, table}} <- Metadata.parse(metadata) do
33
33
metric_name = "Datastore/statement/#{datastore}/#{table}/#{operation}"
34
34
secondary_name = "#{inspect(repo)} #{hostname}:#{port}/#{database}"
changed lib/new_relic/telemetry/ecto/metadata.ex
 
@@ -2,30 2,19 @@ defmodule NewRelic.Telemetry.Ecto.Metadata do
2
2
@moduledoc false
3
3
4
4
def parse(%{result: {:ok, %{__struct__: Postgrex.Cursor}}}), do: :ignore
5
def parse(%{result: {:ok, %{__struct__: MyXQL.Cursor}}}), do: :ignore
5
6
6
- def parse(%{
7
- query: query,
8
- result: {_ok_or_error, %{__struct__: struct}}
9
- })
7
def parse(%{query: query, result: {_ok_err, %{__struct__: struct}}})
10
8
when struct in [Postgrex.Result, Postgrex.Error] do
11
9
{"Postgres", parse_query(query)}
12
10
end
13
11
14
- def parse(%{result: {:ok, %{__struct__: MyXQL.Cursor}}}), do: :ignore
15
-
16
- def parse(%{
17
- query: query,
18
- result: {_ok_or_error, %{__struct__: struct}}
19
- })
12
def parse(%{query: query, result: {_ok_err, %{__struct__: struct}}})
20
13
when struct in [MyXQL.Result, MyXQL.Error] do
21
14
{"MySQL", parse_query(query)}
22
15
end
23
16
24
- def parse(%{
25
- query: query,
26
- repo: repo,
27
- result: {_ok_or_error, %{__struct__: _result_struct}}
28
- }) do
17
def parse(%{query: query, repo: repo, result: {_ok_err, %{__struct__: _struct}}}) do
29
18
[adaapter | _] = repo.__adapter__() |> Module.split() |> Enum.reverse()
30
19
{adaapter, parse_query(query)}
31
20
end
 
@@ -33,21 22,18 @@ defmodule NewRelic.Telemetry.Ecto.Metadata do
33
22
def parse(%{result: {:ok, _}}), do: :ignore
34
23
def parse(%{result: {:error, _}}), do: :ignore
35
24
36
- defp parse_query(query) do
37
- {operation, table} =
38
- case query do
39
- "SELECT" <> _ -> {"select", table_name(:select, query)}
40
- "INSERT" <> _ -> {"insert", table_name(:insert, query)}
41
- "UPDATE" <> _ -> {"update", table_name(:update, query)}
42
- "DELETE" <> _ -> {"delete", table_name(:delete, query)}
43
- "CREATE TABLE" <> _ -> {"create", table_name(:create, query)}
44
- "begin" -> {"begin", "other"}
45
- "commit" -> {"commit", "other"}
46
- "rollback" -> {"rollback", "other"}
47
- _ -> {"other", "other"}
48
- end
49
-
50
- {table, operation}
25
def parse_query(query) do
26
case query do
27
"SELECT" <> _ -> parse_query(:select, query)
28
"INSERT" <> _ -> parse_query(:insert, query)
29
"UPDATE" <> _ -> parse_query(:update, query)
30
"DELETE" <> _ -> parse_query(:delete, query)
31
"CREATE TABLE" <> _ -> parse_query(:create, query)
32
"begin" -> {:begin, :other}
33
"commit" -> {:commit, :other}
34
"rollback" -> {:rollback, :other}
35
_ -> {:other, :other}
36
end
51
37
end
52
38
53
39
# Table name escaping
 
@@ -64,8 50,10 @@ defmodule NewRelic.Telemetry.Ecto.Metadata do
64
50
delete: ~r/FROM (?<table>\S )/,
65
51
create: ~r/CREATE TABLE( IF NOT EXISTS)? (?<table>\S )/
66
52
}
67
- defp table_name(query_type, query) do
68
- Regex.named_captures(@capture[query_type], query)["table"]
69
- |> String.replace(@esc, "")
53
def parse_query(operation, query) do
54
case Regex.named_captures(@capture[operation], query) do
55
%{"table" => table} -> {operation, String.replace(table, @esc, "")}
56
_ -> {:other, :other}
57
end
70
58
end
71
59
end