Skip to content

Commit 66fb279

Browse files
committed
Filter out empty db.url from span's attributes
1 parent b7e1679 commit 66fb279

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/sentry/opentelemetry/span_processor.ex

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ if Code.ensure_loaded?(OpenTelemetry) do
9696
op: op,
9797
description: description,
9898
origin: span_record.origin,
99-
data: span_record.attributes
99+
data: filter_attributes(span_record.attributes)
100100
}
101101
end
102102

@@ -145,6 +145,8 @@ if Code.ensure_loaded?(OpenTelemetry) do
145145
defp build_span(span_record) do
146146
{op, description} = get_op_description(span_record)
147147

148+
filtered_attributes = filter_attributes(span_record.attributes)
149+
148150
%Span{
149151
op: op,
150152
description: description,
@@ -154,7 +156,7 @@ if Code.ensure_loaded?(OpenTelemetry) do
154156
span_id: span_record.span_id,
155157
parent_span_id: span_record.parent_span_id,
156158
origin: span_record.origin,
157-
data: Map.put(span_record.attributes, "otel.kind", span_record.kind),
159+
data: Map.put(filtered_attributes, "otel.kind", span_record.kind),
158160
status: span_status(span_record)
159161
}
160162
end
@@ -192,5 +194,18 @@ if Code.ensure_loaded?(OpenTelemetry) do
192194
end
193195

194196
defp to_status(_any), do: "unknown_error"
197+
198+
defp filter_attributes(attributes) do
199+
attributes
200+
|> Enum.reject(fn {key, value} ->
201+
case {key, value} do
202+
{"db.url", "ecto:"} -> true
203+
{"db.url", nil} -> true
204+
{"db.url", ""} -> true
205+
_ -> false
206+
end
207+
end)
208+
|> Map.new()
209+
end
195210
end
196211
end

test_integrations/phoenix_app/test/phoenix_app/repo_test.exs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ defmodule PhoenixApp.RepoTest do
2121
assert [transaction] = transactions
2222

2323
assert transaction.transaction_info == %{source: :custom}
24+
2425
assert transaction.contexts.trace.op == "db"
25-
assert String.starts_with?(transaction.contexts.trace.description, "SELECT")
26+
2627
assert transaction.contexts.trace.data["db.system"] == :sqlite
28+
assert transaction.contexts.trace.data["db.type"] == :sql
29+
assert transaction.contexts.trace.data["db.instance"] == "db/test.sqlite3"
30+
assert transaction.contexts.trace.data["db.name"] == "db/test.sqlite3"
31+
32+
assert String.starts_with?(transaction.contexts.trace.description, "SELECT")
33+
assert String.starts_with?(transaction.contexts.trace.data["db.statement"], "SELECT")
34+
35+
refute Map.has_key?(transaction.contexts.trace.data, "db.url")
2736
end
2837
end

0 commit comments

Comments
 (0)