Skip to content

Commit

Permalink
overwrites the default result value
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdel committed Apr 23, 2023
1 parent b3b4c4c commit 040359a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/open_telemetry_decorator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ defmodule OpenTelemetryDecorator do
require OpenTelemetry.Tracer, as: Tracer

OpenTelemetry.Tracer.with_span unquote(span_name) do
input_params = Attributes.get(Kernel.binding(), unquote(include))
input_params =
Kernel.binding()
|> Attributes.get(unquote(include))
|> Keyword.delete(:result)

try do
result = unquote(body)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule OpenTelemetryDecorator.MixProject do
use Mix.Project

@version "1.3.0"
@version "1.3.1"
@github_page "https://github.com/marcdel/open_telemetry_decorator"

def project do
Expand Down
15 changes: 15 additions & 0 deletions test/open_telemetry_decorator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ defmodule OpenTelemetryDecoratorTest do
assert Map.get(get_span_attributes(attrs), :x) == 1
end

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

@decorate trace("ExampleResult.add", include: [:a, :b, :result])
def add(a, b) do
a + b
end
end

ExampleResult.add(5, 5)
assert_receive {:span, span(name: "ExampleResult.add", attributes: attrs)}
assert Map.get(get_span_attributes(attrs), :result) == 10
end

test "does not include anything unless specified" do
Example.no_include(include_me: "nope")
assert_receive {:span, span(name: "Example.no_include", attributes: attrs)}
Expand Down

0 comments on commit 040359a

Please sign in to comment.