Skip to content

Commit

Permalink
does not write input parameters not in the include
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdel committed May 5, 2024
1 parent 4f37453 commit 0a148f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/open_telemetry_decorator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ defmodule OpenTelemetryDecorator do
input_params =
Kernel.binding()
|> Keyword.delete(:result)
|> Keyword.take(unquote(include))
|> O11y.set_attributes(namespace: prefix)

try do
Expand All @@ -72,8 +73,8 @@ defmodule OpenTelemetryDecorator do

Kernel.binding()
|> Keyword.put(:result, result)
|> Keyword.take(unquote(include))
|> Keyword.merge(input_params)
|> Keyword.take(unquote(include))
|> O11y.set_attributes(namespace: prefix)

result
Expand Down
19 changes: 18 additions & 1 deletion test/open_telemetry_decorator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule OpenTelemetryDecoratorTest do
end
end

@decorate with_span("Example.parse_params", include: [[:params, "id"]])
@decorate with_span("Example.parse_params", include: [:params])
def parse_params(params) do
%{"id" => id} = params

Expand Down Expand Up @@ -173,6 +173,23 @@ defmodule OpenTelemetryDecoratorTest do
assert %{"app.x" => 1, "app.y" => 1} = span.attributes
end

test "does not write input parameters not in the include " do
defmodule InputExample do
use OpenTelemetryDecorator

@decorate with_span("inputs", include: [:x])
def inputs(x, y) do
z = x + y
{:ok, z}
end
end

assert {:ok, 3} = InputExample.inputs(1, 2)

span = assert_span("inputs")
assert span.attributes == %{"app.x" => 1}
end

test "overwrites the default result value" do
defmodule ExampleResult do
use OpenTelemetryDecorator
Expand Down

0 comments on commit 0a148f3

Please sign in to comment.