diff --git a/README.md b/README.md index 1006def..aa1e380 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,14 @@ Add `open_telemetry_decorator` to your list of dependencies in `mix.exs`. We inc ```elixir def deps do [ - {:opentelemetry, "~> 1.4"}, - {:opentelemetry_exporter, "~> 1.7"}, + {:opentelemetry, "~> 1.5"}, + {:opentelemetry_exporter, "~> 1.8"}, {:open_telemetry_decorator, "~> 1.5"} ] end ``` -Then follow the directions for the exporter of your choice to send traces to to zipkin, honeycomb, etc. +Then follow the directions for the exporter of your choice to send traces to zipkin, honeycomb, etc. https://github.com/open-telemetry/opentelemetry-erlang/tree/main/apps/opentelemetry_zipkin ### Honeycomb Example @@ -78,7 +78,7 @@ defmodule MyApp.Worker do def do_work(arg1, arg2) do O11y.set_attributes(arg1: arg1, arg2: arg2) # ...doing work - Attributes.set_attribute(:output, "something") + O11y.set_attribute(:output, "something") end end ``` diff --git a/mix.lock b/mix.lock index fc431cd..1fe741d 100644 --- a/mix.lock +++ b/mix.lock @@ -19,7 +19,7 @@ "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, - "o11y": {:hex, :o11y, "0.2.9", "604ca6b51fb3edfec2e791486f5fd10096c021a4c3dffad65b95e1119740c6a9", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:opentelemetry_api, "~> 1.4", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "642bed8a46c9529abc8dd6a781b2b1694708fb4aaf0eab2f1ec436a840131d26"}, + "o11y": {:hex, :o11y, "0.2.10", "bce4ab17881c4fd0bb4d7a2c8aa78273693a5f036d8f94eeb1fc6af61c750f4d", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:opentelemetry_api, "~> 1.4", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "75e3f6e8905c02b921a66836857060203e7e5bf4a98e09cd7d0e9bbde07db1f9"}, "opentelemetry": {:hex, :opentelemetry, "1.5.0", "7dda6551edfc3050ea4b0b40c0d2570423d6372b97e9c60793263ef62c53c3c2", [:rebar3], [{:opentelemetry_api, "~> 1.4", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "cdf4f51d17b592fc592b9a75f86a6f808c23044ba7cf7b9534debbcc5c23b0ee"}, "opentelemetry_api": {:hex, :opentelemetry_api, "1.4.0", "63ca1742f92f00059298f478048dfb826f4b20d49534493d6919a0db39b6db04", [:mix, :rebar3], [], "hexpm", "3dfbbfaa2c2ed3121c5c483162836c4f9027def469c41578af5ef32589fcfc58"}, "opentelemetry_exporter": {:hex, :opentelemetry_exporter, "1.8.0", "5d546123230771ef4174e37bedfd77e3374913304cd6ea3ca82a2add49cd5d56", [:rebar3], [{:grpcbox, ">= 0.0.0", [hex: :grpcbox, repo: "hexpm", optional: false]}, {:opentelemetry, "~> 1.5.0", [hex: :opentelemetry, repo: "hexpm", optional: false]}, {:opentelemetry_api, "~> 1.4.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:tls_certificate_check, "~> 1.18", [hex: :tls_certificate_check, repo: "hexpm", optional: false]}], "hexpm", "a1f9f271f8d3b02b81462a6bfef7075fd8457fdb06adff5d2537df5e2264d9af"}, diff --git a/test/open_telemetry_decorator_test.exs b/test/open_telemetry_decorator_test.exs index 152a11f..3c5194c 100644 --- a/test/open_telemetry_decorator_test.exs +++ b/test/open_telemetry_decorator_test.exs @@ -94,6 +94,51 @@ defmodule OpenTelemetryDecoratorTest do def with_pid, do: :ok end + defmodule BehaviorExample do + defmodule VCS do + @type sha :: binary() + @callback push(sha()) :: :ok + end + + defmodule Git do + defmacro __using__(_opts) do + quote do + use OpenTelemetryDecorator + + @behaviour VCS + + @decorate with_span("Git.push") + def push(sha) do + O11y.set_attributes(vcs: :git, git_sha: sha) + :ok + end + + defoverridable VCS + end + end + end + + defmodule Github do + use Git + use OpenTelemetryDecorator + + @decorate with_span("Github.push") + def push(sha) do + O11y.set_attributes(host: :github, github_sha: sha) + super(sha) + end + end + end + + test "traces when super is called in a decorated function" do + BehaviorExample.Github.push("abc123") + + git_span = assert_span("Git.push") |> dbg() + assert %{"vcs" => :git, "git_sha" => "abc123"} = git_span.attributes + github_span = assert_span("Github.push") |> dbg() + assert %{"vcs" => :git, "git_sha" => "abc123", "host" => :github, "github_sha" => "abc123"} = github_span.attributes + end + test "pids" do expected_pid = inspect(self())