diff --git a/CHANGELOG.md b/CHANGELOG.md index fa28f384..0d9e0a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - Deeply nested spans are handled now when building up traces in `SpanProcessor` ([#924](https://github.com/getsentry/sentry-elixir/pull/924)) +#### Various improvements + +- Span's attributes no longer include `db.url: "ecto:"` entries as they are now filtered out ([#925](https://github.com/getsentry/sentry-elixir/pull/925)) + ## 11.0.1 #### Various improvements diff --git a/lib/sentry/opentelemetry/span_processor.ex b/lib/sentry/opentelemetry/span_processor.ex index af16ac02..11bca198 100644 --- a/lib/sentry/opentelemetry/span_processor.ex +++ b/lib/sentry/opentelemetry/span_processor.ex @@ -96,7 +96,7 @@ if Code.ensure_loaded?(OpenTelemetry) do op: op, description: description, origin: span_record.origin, - data: span_record.attributes + data: filter_attributes(span_record.attributes) } end @@ -145,6 +145,8 @@ if Code.ensure_loaded?(OpenTelemetry) do defp build_span(span_record) do {op, description} = get_op_description(span_record) + filtered_attributes = filter_attributes(span_record.attributes) + %Span{ op: op, description: description, @@ -154,7 +156,7 @@ if Code.ensure_loaded?(OpenTelemetry) do span_id: span_record.span_id, parent_span_id: span_record.parent_span_id, origin: span_record.origin, - data: Map.put(span_record.attributes, "otel.kind", span_record.kind), + data: Map.put(filtered_attributes, "otel.kind", span_record.kind), status: span_status(span_record) } end @@ -192,5 +194,18 @@ if Code.ensure_loaded?(OpenTelemetry) do end defp to_status(_any), do: "unknown_error" + + defp filter_attributes(attributes) do + attributes + |> Enum.reject(fn {key, value} -> + case {key, value} do + {"db.url", "ecto:"} -> true + {"db.url", nil} -> true + {"db.url", ""} -> true + _ -> false + end + end) + |> Map.new() + end end end diff --git a/test_integrations/phoenix_app/test/phoenix_app/repo_test.exs b/test_integrations/phoenix_app/test/phoenix_app/repo_test.exs index 095fbbe0..3ed65913 100644 --- a/test_integrations/phoenix_app/test/phoenix_app/repo_test.exs +++ b/test_integrations/phoenix_app/test/phoenix_app/repo_test.exs @@ -21,8 +21,17 @@ defmodule PhoenixApp.RepoTest do assert [transaction] = transactions assert transaction.transaction_info == %{source: :custom} + assert transaction.contexts.trace.op == "db" - assert String.starts_with?(transaction.contexts.trace.description, "SELECT") + assert transaction.contexts.trace.data["db.system"] == :sqlite + assert transaction.contexts.trace.data["db.type"] == :sql + assert transaction.contexts.trace.data["db.instance"] == "db/test.sqlite3" + assert transaction.contexts.trace.data["db.name"] == "db/test.sqlite3" + + assert String.starts_with?(transaction.contexts.trace.description, "SELECT") + assert String.starts_with?(transaction.contexts.trace.data["db.statement"], "SELECT") + + refute Map.has_key?(transaction.contexts.trace.data, "db.url") end end