Skip to content

Commit

Permalink
This PR removes obsolete attributes from spans
Browse files Browse the repository at this point in the history
These are already replaced by either `http.status_code` or
`net.peer.name` so we are not losing anything.

Signed-off-by: Maciej Szlosarczyk maciej@mindvalley.com
  • Loading branch information
maciej-szlosarczyk committed Jan 15, 2025
1 parent fdbe3b8 commit 7d1848c
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 23 deletions.
6 changes: 1 addition & 5 deletions lib/mv_opentelemetry/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ defmodule MvOpentelemetry.Finch do
ctx = OpentelemetryTelemetry.set_current_telemetry_span(opts[:tracer_id], meta)

if status do
Span.set_attributes(ctx, %{
# Remove this field after some time in favour of Trace.http_status_code()
:"http.status" => status,
Trace.http_status_code() => status
})
Span.set_attributes(ctx, %{Trace.http_status_code() => status})
end

if error do
Expand Down
8 changes: 1 addition & 7 deletions lib/mv_opentelemetry/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ defmodule MvOpentelemetry.Plug do

attributes = [
{Trace.http_client_ip(), client_ip},
# Remove this field after some time in favour of Trace.net_peer_name()
{:"http.host", conn.host},
{Trace.net_peer_name(), conn.host},
{Trace.http_method(), conn.method},
{Trace.http_scheme(), "#{conn.scheme}"},
Expand Down Expand Up @@ -110,11 +108,7 @@ defmodule MvOpentelemetry.Plug do
def handle_stop_event(_, _, %{conn: conn} = meta, opts) do
ctx = OpentelemetryTelemetry.set_current_telemetry_span(opts[:tracer_id], meta)

Span.set_attributes(ctx, %{
# Remove this field after some time in favour of Trace.http_status_code()
:"http.status" => conn.status,
Trace.http_status_code() => conn.status
})
Span.set_attributes(ctx, %{Trace.http_status_code() => conn.status})

if conn.status >= 400 do
Span.set_status(ctx, OpenTelemetry.status(:error, ""))
Expand Down
6 changes: 1 addition & 5 deletions lib/mv_opentelemetry/tesla.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ defmodule MvOpentelemetry.Tesla do
ctx = OpentelemetryTelemetry.set_current_telemetry_span(opts[:tracer_id], meta)

if status do
Span.set_attributes(ctx, %{
# Remove this field after some time in favour of Trace.http_status_code()
:"http.status" => status,
Trace.http_status_code() => status
})
Span.set_attributes(ctx, %{Trace.http_status_code() => status})
end

if error do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule MvOpentelemetry.MixProject do
def project do
[
app: :mv_opentelemetry,
version: "1.14.0",
version: "2.0.0",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: Mix.compilers(),
Expand Down
2 changes: 0 additions & 2 deletions test/mv_opentelemetry/finch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ defmodule MvOpentelemetry.FinchTest do
assert :client == span(span_record, :kind)

assert {:"http.status_code", 200} in attributes
assert {:"http.status", 200} in attributes
assert {:"http.host", "localhost"} in attributes
assert {:"net.peer.name", "localhost"} in attributes
assert {:"http.method", "GET"} in attributes
assert {:"http.target", "/"} in attributes
Expand Down
3 changes: 0 additions & 3 deletions test/mv_opentelemetry/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ defmodule MvOpentelemetry.PlugTest do
{:attributes, _, _, _, attributes} = span(span_record, :attributes)
keys = Enum.map(attributes, fn {k, _v} -> k end)

assert {:"http.status", 200} in attributes
assert {:"http.status_code", 200} in attributes
assert {:"http.method", "GET"} in attributes
assert {:"http.flavor", ""} in attributes
assert {:"http.host", "www.example.com"} in attributes
assert {:"net.peer.name", "www.example.com"} in attributes
assert {:"http.target", "/"} in attributes
assert {"service.component", "test.harness"} in attributes
Expand Down Expand Up @@ -77,7 +75,6 @@ defmodule MvOpentelemetry.PlugTest do
{:attributes, _, _, _, attributes} = span(span_record, :attributes)
keys = Enum.map(attributes, fn {k, _v} -> k end)

assert {:"http.status", 200} in attributes
assert {:"http.status_code", 200} in attributes
assert {:"http.method", "GET"} in attributes
assert {:"http.flavor", ""} in attributes
Expand Down

0 comments on commit 7d1848c

Please sign in to comment.