Skip to content

Commit b5c5144

Browse files
committed
include pids by default in spans
1 parent dbf07fc commit b5c5144

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/open_telemetry_decorator.ex

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ defmodule OpenTelemetryDecorator do
6565
|> Keyword.take(unquote(include))
6666
|> O11y.set_attributes(namespace: prefix)
6767

68+
O11y.set_attributes(pid: self())
69+
6870
try do
6971
result = unquote(body)
7072

test/open_telemetry_decorator_test.exs

+19-9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ defmodule OpenTelemetryDecoratorTest do
8989

9090
@decorate with_span("Example.with_link", links: [:_span_link])
9191
def with_link(_span_link), do: :ok
92+
93+
@decorate with_span("Example.with_pid", include: [:_self])
94+
def with_pid, do: :ok
95+
end
96+
97+
test "pids" do
98+
expected_pid = inspect(self())
99+
100+
Example.with_pid()
101+
102+
span = assert_span("Example.with_pid")
103+
assert span.attributes == %{"pid" => expected_pid}
92104
end
93105

94106
test "does not modify inputs or function result" do
@@ -188,7 +200,7 @@ defmodule OpenTelemetryDecoratorTest do
188200
assert %{"app.x" => 1, "app.y" => 1} = span.attributes
189201
end
190202

191-
test "does not write input parameters not in the include" do
203+
test "does not write input parameters not in the include (except pid)" do
192204
defmodule InputExample do
193205
use OpenTelemetryDecorator
194206

@@ -202,7 +214,7 @@ defmodule OpenTelemetryDecoratorTest do
202214
assert {:ok, 3} = InputExample.inputs(1, 2)
203215

204216
span = assert_span("inputs")
205-
assert span.attributes == %{"app.x" => 1}
217+
assert span.attributes == %{"app.x" => 1, "pid" => inspect(self())}
206218
end
207219

208220
test "overwrites the default result value" do
@@ -225,7 +237,7 @@ defmodule OpenTelemetryDecoratorTest do
225237
Example.no_include(include_me: "nope")
226238

227239
span = assert_span("Example.no_include")
228-
assert %{} == span.attributes
240+
assert span.attributes == %{"pid" => inspect(self())}
229241
end
230242

231243
test "records an exception event" do
@@ -271,7 +283,7 @@ defmodule OpenTelemetryDecoratorTest do
271283
catch
272284
:exit, :normal ->
273285
span = assert_span("Example.with_exit")
274-
assert span.attributes == %{"app.exit" => :normal}
286+
assert %{"app.exit" => :normal} = span.attributes
275287
end
276288
end
277289

@@ -294,7 +306,7 @@ defmodule OpenTelemetryDecoratorTest do
294306
catch
295307
:exit, :shutdown ->
296308
span = assert_span("Example.with_exit")
297-
assert span.attributes == %{"app.exit" => :shutdown}
309+
assert %{"app.exit" => :shutdown} = span.attributes
298310
end
299311
end
300312

@@ -318,10 +330,8 @@ defmodule OpenTelemetryDecoratorTest do
318330
:exit, {:shutdown, _reason} ->
319331
span = assert_span("Example.with_exit")
320332

321-
assert span.attributes == %{
322-
"app.exit" => :shutdown,
323-
"app.shutdown_reason.just" => :chillin
324-
}
333+
assert %{"app.exit" => :shutdown, "app.shutdown_reason.just" => :chillin} =
334+
span.attributes
325335
end
326336
end
327337

0 commit comments

Comments
 (0)