Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finch: Sets the trace status to error on any 5xx response #258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ defmodule OpentelemetryFinch do
kind: :client
})

if status >= 500 && status < 600 do
OpenTelemetry.Span.set_status(s, OpenTelemetry.status(:error))
end

if meta.result |> elem(0) == :error do
OpenTelemetry.Span.set_status(
s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule OpentelemetryFinchTest do
} = :otel_attributes.map(attributes)
end

test "records span on requests failed", %{bypass: _} do
test "records span on requests failed" do
OpentelemetryFinch.setup()

_conn = start_supervised!({Finch, name: HttpFinch})
Expand All @@ -75,5 +75,33 @@ defmodule OpentelemetryFinchTest do
} = :otel_attributes.map(attributes)
end

# https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
# > For HTTP status codes in the 5xx range, as well as any other code the client failed to interpret, span status MUST be set to Error.
test "records span on 500 error from server", %{bypass: bypass} do
Bypass.expect(bypass, fn conn -> Plug.Conn.resp(conn, 500, "Internal Server Error") end)

OpentelemetryFinch.setup()

_conn = start_supervised!({Finch, name: HttpFinch})

{:ok, _} = Finch.build(:get, endpoint_url(bypass.port)) |> Finch.request(HttpFinch)

assert_receive {:span,
span(
name: "HTTP GET",
kind: :client,
status: {:status, :error, ""},
attributes: attributes
)}

assert %{
"net.peer.name": "localhost",
"http.method": "GET",
"http.target": "/",
"http.scheme": :http,
"http.status_code": 500
} = :otel_attributes.map(attributes)
end

defp endpoint_url(port), do: "http://localhost:#{port}/"
end
Loading