From 040359a2069b8f193153294b802388e7ad89c463 Mon Sep 17 00:00:00 2001 From: Marc Delagrammatikas Date: Sun, 23 Apr 2023 15:57:25 -0700 Subject: [PATCH] overwrites the default result value --- lib/open_telemetry_decorator.ex | 5 ++++- mix.exs | 2 +- test/open_telemetry_decorator_test.exs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/open_telemetry_decorator.ex b/lib/open_telemetry_decorator.ex index 01bec22..93fd3b8 100644 --- a/lib/open_telemetry_decorator.ex +++ b/lib/open_telemetry_decorator.ex @@ -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) diff --git a/mix.exs b/mix.exs index bf69033..f9d2de7 100644 --- a/mix.exs +++ b/mix.exs @@ -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 diff --git a/test/open_telemetry_decorator_test.exs b/test/open_telemetry_decorator_test.exs index 0d8855c..c63b46b 100644 --- a/test/open_telemetry_decorator_test.exs +++ b/test/open_telemetry_decorator_test.exs @@ -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)}