Skip to content

Commit c84fa63

Browse files
fcevadobryannaegele
authored andcommitted
Adjust code review changes
1 parent 0bdd43b commit c84fa63

File tree

2 files changed

+20
-79
lines changed

2 files changed

+20
-79
lines changed

instrumentation/opentelemetry_ecto/lib/opentelemetry_ecto.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule OpentelemetryEcto do
3636
defaults to the concatenation of the event name with periods, e.g.
3737
`"blog.repo.query"`. This will always be followed with a colon and the
3838
source (the table name for SQL adapters).
39-
* `:attributes` - additional attributes to include in the span. If there
39+
* `:additional_attributes` - additional attributes to include in the span. If there
4040
are conflits with default provided attributes, the ones provided with
4141
this config will have precedence.
4242
"""
@@ -77,7 +77,7 @@ defmodule OpentelemetryEcto do
7777
end <> if source != nil, do: ":#{source}", else: ""
7878

7979
time_unit = Keyword.get(config, :time_unit, :microsecond)
80-
config_attributes = Keyword.get(config, :attributes, %{})
80+
additional_attributes = Keyword.get(config, :additional_attributes, %{})
8181

8282
db_type =
8383
case type do
@@ -106,7 +106,7 @@ defmodule OpentelemetryEcto do
106106
acc
107107
end)
108108
|> Map.merge(base_attributes)
109-
|> Map.merge(config_attributes)
109+
|> Map.merge(additional_attributes)
110110

111111
parent_context = OpentelemetryProcessPropagator.fetch_parent_ctx(1, :"$callers")
112112

instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs

Lines changed: 17 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,12 @@ defmodule OpentelemetryEctoTest do
6161
} = :otel_attributes.map(attributes)
6262
end
6363

64-
test "include config attributes" do
65-
attach_handler(
66-
attributes: %{"config.attribute": "special value", "db.instance": "my_instance_config"}
67-
)
68-
64+
test "include additionaL_attributes" do
65+
attach_handler(additional_attributes: %{"config.attribute": "special value", "db.instance": "my_instance"})
6966
Repo.all(User)
7067

7168
assert_receive {:span, span(attributes: attributes)}
72-
73-
assert %{"config.attribute": "special value", "db.instance": "my_instance_config"} =
74-
:otel_attributes.map(attributes)
69+
assert %{"config.attribute": "special value", "db.instance": "my_instance"} = :otel_attributes.map(attributes)
7570
end
7671

7772
test "changes the time unit" do
@@ -124,7 +119,7 @@ defmodule OpentelemetryEctoTest do
124119
attach_handler()
125120

126121
try do
127-
Repo.all(from(u in "users", select: u.non_existant_field))
122+
Repo.all(from u in "users", select: u.non_existant_field)
128123
rescue
129124
_ -> :ok
130125
end
@@ -150,24 +145,9 @@ defmodule OpentelemetryEctoTest do
150145
end
151146

152147
assert_receive {:span, span(span_id: root_span_id, name: "parent span")}
153-
154-
assert_receive {:span,
155-
span(
156-
parent_span_id: ^root_span_id,
157-
name: "opentelemetry_ecto.test_repo.query:users"
158-
)}
159-
160-
assert_receive {:span,
161-
span(
162-
parent_span_id: ^root_span_id,
163-
name: "opentelemetry_ecto.test_repo.query:posts"
164-
)}
165-
166-
assert_receive {:span,
167-
span(
168-
parent_span_id: ^root_span_id,
169-
name: "opentelemetry_ecto.test_repo.query:comments"
170-
)}
148+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:users")}
149+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:posts")}
150+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:comments")}
171151
end
172152

173153
test "preloads in parallel are tied to the parent span" do
@@ -182,24 +162,9 @@ defmodule OpentelemetryEctoTest do
182162
end
183163

184164
assert_receive {:span, span(span_id: root_span_id, name: "parent span")}
185-
186-
assert_receive {:span,
187-
span(
188-
parent_span_id: ^root_span_id,
189-
name: "opentelemetry_ecto.test_repo.query:users"
190-
)}
191-
192-
assert_receive {:span,
193-
span(
194-
parent_span_id: ^root_span_id,
195-
name: "opentelemetry_ecto.test_repo.query:posts"
196-
)}
197-
198-
assert_receive {:span,
199-
span(
200-
parent_span_id: ^root_span_id,
201-
name: "opentelemetry_ecto.test_repo.query:comments"
202-
)}
165+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:users")}
166+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:posts")}
167+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:comments")}
203168
end
204169

205170
test "nested query preloads are tied to the parent span" do
@@ -210,45 +175,21 @@ defmodule OpentelemetryEctoTest do
210175
attach_handler()
211176

212177
Tracer.with_span "parent span" do
213-
users_query = from(u in User, preload: [:posts, :comments])
214-
comments_query = from(c in Comment, preload: [user: ^users_query])
178+
users_query = from u in User, preload: [:posts, :comments]
179+
comments_query = from c in Comment, preload: [user: ^users_query]
215180
Repo.all(Query.from(User, preload: [:posts, comments: ^comments_query]))
216181
end
217182

218183
assert_receive {:span, span(span_id: root_span_id, name: "parent span")}
219184
# root query
220-
assert_receive {:span,
221-
span(
222-
parent_span_id: ^root_span_id,
223-
name: "opentelemetry_ecto.test_repo.query:users"
224-
)}
225-
185+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:users")}
226186
# comments preload
227-
assert_receive {:span,
228-
span(
229-
parent_span_id: ^root_span_id,
230-
name: "opentelemetry_ecto.test_repo.query:comments"
231-
)}
232-
187+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:comments")}
233188
# users preload
234-
assert_receive {:span,
235-
span(
236-
parent_span_id: ^root_span_id,
237-
name: "opentelemetry_ecto.test_repo.query:users"
238-
)}
239-
189+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:users")}
240190
# preloads of user
241-
assert_receive {:span,
242-
span(
243-
parent_span_id: ^root_span_id,
244-
name: "opentelemetry_ecto.test_repo.query:posts"
245-
)}
246-
247-
assert_receive {:span,
248-
span(
249-
parent_span_id: ^root_span_id,
250-
name: "opentelemetry_ecto.test_repo.query:comments"
251-
)}
191+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:posts")}
192+
assert_receive {:span, span(parent_span_id: ^root_span_id, name: "opentelemetry_ecto.test_repo.query:comments")}
252193
end
253194

254195
def attach_handler(config \\ []) do

0 commit comments

Comments
 (0)