Skip to content

Commit

Permalink
Merge pull request #5 from NFIBrokerage/conform-headers
Browse files Browse the repository at this point in the history
Use b3 headers
  • Loading branch information
bjornrud authored May 6, 2020
2 parents f158ad7 + 1d823ce commit 4d3ee04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
11 changes: 4 additions & 7 deletions lib/hummingbird.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ defmodule Hummingbird do
Ships the conn to honeycomb.io to allow distributed tracing.
Assumes requests that come in populate two different headers:
request-from-trace-id
and
request-from-span-id
x-b3-traceid and x-b3-spanid
"""

use Plug.Builder
Expand All @@ -21,8 +19,7 @@ defmodule Hummingbird do
end

@doc """
In this case, is an impure dispatching of conn information to the elixir
honeycomb client
An impure dispatching of conn information to the elixir honeycomb client
"""
def call(conn, opts) do
conn =
Expand Down Expand Up @@ -104,7 +101,7 @@ defmodule Hummingbird do
if is_nil(conn.assigns[:span_id]) do
# wasn't set previously so check header
conn
|> get_req_header("request-from-span-id")
|> get_req_header("x-b3-spanid")
|> List.first()
else
conn.assigns[:span_id]
Expand All @@ -118,7 +115,7 @@ defmodule Hummingbird do
def determine_trace_id(conn) do
if is_nil(conn.assigns[:trace_id]) do
conn
|> get_req_header("request-from-trace-id")
|> get_req_header("x-b3-traceid")
|> List.first() || UUID.uuid4()
else
# fallback to this being an internal responsibility to assign a trace id
Expand Down
20 changes: 10 additions & 10 deletions test/hummingbird_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule HummingbirdTest do
]
end

describe "given no request-from-trace-id header," do
describe "given no x-b3-traceid header," do
setup do
[
conn_without_header: conn(:get, "/foo")
Expand All @@ -25,7 +25,7 @@ defmodule HummingbirdTest do
end
end

describe "given no request-from-span-id header," do
describe "given no x-b3-spanid header," do
setup do
[
conn_without_header: conn(:get, "/foo")
Expand All @@ -43,15 +43,15 @@ defmodule HummingbirdTest do
end
end

describe "given a conn with request-from-trace-id header," do
describe "given a conn with x-b3-traceid header," do
setup do
expected_id = UUID.uuid4()

[
expected_id: expected_id,
conn_with_header:
conn(:get, "/foo")
|> put_req_header("request-from-trace-id", expected_id)
|> put_req_header("x-b3-traceid", expected_id)
]
end

Expand All @@ -64,7 +64,7 @@ defmodule HummingbirdTest do
end
end

describe "given a conn with nil trace id and no request-from-trace-id header," do
describe "given a conn with nil trace id and no x-b3-traceid header," do
setup do
expected_id = UUID.uuid4()

Expand All @@ -84,15 +84,15 @@ defmodule HummingbirdTest do
end
end

describe "given a conn with request-from-span-id header," do
describe "given a conn with x-b3-spanid header," do
setup do
expected_id = UUID.uuid4()

[
expected_id: expected_id,
conn_with_header:
conn(:get, "/foo")
|> put_req_header("request-from-span-id", expected_id)
|> put_req_header("x-b3-spanid", expected_id)
]
end

Expand All @@ -106,7 +106,7 @@ defmodule HummingbirdTest do
end
end

describe "given a conn with no request-from-span-id header," do
describe "given a conn with no x-b3-spanid header," do
setup do
[
conn_without_header: conn(:get, "/foo")
Expand Down Expand Up @@ -136,8 +136,8 @@ defmodule HummingbirdTest do
|> assign(:span_id, expected_parent_id)
|> assign(:trace_id, expected_trace_id)
|> assign(:parent_id, UUID.uuid4())
|> put_req_header("request-from-span-id", UUID.uuid4())
|> put_req_header("request-from-trace-id", UUID.uuid4())
|> put_req_header("x-b3-spanid", UUID.uuid4())
|> put_req_header("x-b3-traceid", UUID.uuid4())
]
end

Expand Down

0 comments on commit 4d3ee04

Please sign in to comment.