opentelemetry_bandit: fix errors due to missing fields

This commit is contained in:
Shadowfacts 2024-04-23 13:06:22 -04:00
parent c2cb6bc86c
commit 5d4782c06b
1 changed files with 7 additions and 7 deletions

View File

@ -52,10 +52,10 @@ defmodule OpentelemetryBandit do
if Map.has_key?(meta, :error) do if Map.has_key?(meta, :error) do
%{ %{
Trace.http_url() => url, Trace.http_url() => url,
Trace.http_method() => meta.method, Trace.http_method() => conn.method,
Trace.net_transport() => :"IP.TCP", Trace.net_transport() => :"IP.TCP",
Trace.http_response_content_length() => measurements.resp_body_bytes, Trace.http_response_content_length() => Map.get(measurements, :resp_body_bytes),
Trace.http_status_code() => meta.status Trace.http_status_code() => conn.status
} }
else else
%{ %{
@ -65,9 +65,9 @@ defmodule OpentelemetryBandit do
Trace.net_peer_name() => conn.host, Trace.net_peer_name() => conn.host,
Trace.net_peer_port() => conn.port, Trace.net_peer_port() => conn.port,
Trace.http_target() => conn.request_path, Trace.http_target() => conn.request_path,
Trace.http_method() => meta.method, Trace.http_method() => conn.method,
Trace.http_status_code() => meta.status, Trace.http_status_code() => conn.status,
Trace.http_response_content_length() => measurements.resp_body_bytes, Trace.http_response_content_length() => Map.get(measurements, :resp_body_bytes),
Trace.net_transport() => :"IP.TCP", Trace.net_transport() => :"IP.TCP",
Trace.http_user_agent() => user_agent(conn) Trace.http_user_agent() => user_agent(conn)
} }
@ -75,7 +75,7 @@ defmodule OpentelemetryBandit do
span_kind = if Map.has_key?(meta, :error), do: :error, else: :server span_kind = if Map.has_key?(meta, :error), do: :error, else: :server
span_id = "HTTP #{meta.method} #{request_path}" |> String.trim() span_id = "HTTP #{conn.method} #{request_path}" |> String.trim()
OpenTelemetry.Tracer.start_span(span_id, %{ OpenTelemetry.Tracer.start_span(span_id, %{
attributes: attributes, attributes: attributes,