Skip to content

Commit

Permalink
Add net.peer.name attribute (#97) (#99)
Browse files Browse the repository at this point in the history
* Add net.peer.name attribute (#97)

* bump for release

Co-authored-by: Ho-Yon Mak <ho-yon.mak@multiverse.io>
  • Loading branch information
cpiemontese and hoyon authored Jan 24, 2023
1 parent 359e3b0 commit 4e7ebdf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/telepoison.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ defmodule Telepoison do
span_name = Keyword.get_lazy(opts, :ot_span_name, fn -> compute_default_span_name(request) end)

resource_route = get_resource_route(opts, request)
%URI{host: host} = request.url |> process_request_url() |> URI.parse()

attributes =
[
{"http.method", request.method |> Atom.to_string() |> String.upcase()},
{"http.url", request.url}
{"http.url", request.url},
{"net.peer.name", host}
] ++
Keyword.get(opts, :ot_attributes, []) ++
if resource_route != nil,
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Telepoison.MixProject do
use Mix.Project

@source_url "https://github.com/primait/telepoison"
@version "1.1.1"
@version "1.1.2"

def project do
[
Expand Down
3 changes: 2 additions & 1 deletion test/telepoison_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ defmodule TelepoisonTest do
assert_receive {:span, span(attributes: attributes_record)}
attributes = elem(attributes_record, 4)

assert ["http.method", "http.status_code", "http.url"] ==
assert ["http.method", "http.status_code", "http.url", "net.peer.name"] ==
attributes |> Map.keys() |> Enum.sort()

assert {"http.method", "GET"} in attributes
assert {"net.peer.name", "localhost"} in attributes
end

test "traceparent header is injected when no headers" do
Expand Down

0 comments on commit 4e7ebdf

Please sign in to comment.