Current section
45 Versions
Jump to
Current section
45 Versions
Compare versions
4
files changed
+7
additions
-60
deletions
| @@ -16,7 +16,7 @@ Add `open_telemetry_decorator` to your list of dependencies in `mix.exs`. We inc | |
| 16 16 | ```elixir |
| 17 17 | def deps do |
| 18 18 | [ |
| 19 | - {:open_telemetry_decorator, "~> 0.5.2"}, |
| 19 | + {:open_telemetry_decorator, "~> 0.5.3"}, |
| 20 20 | {:opentelemetry, "~> 0.4.0"} |
| 21 21 | ] |
| 22 22 | end |
| @@ -30,16 +30,15 @@ https://github.com/opentelemetry-beam/opentelemetry_zipkin | |
| 30 30 | |
| 31 31 | ## Usage |
| 32 32 | |
| 33 | - Add `use OpenTelemetryDecorator` to the module, and decorate any methods you want to trace with `@decorate trace("span name")` or `@decorate simple_trace("span name")`. |
| 33 | + Add `use OpenTelemetryDecorator` to the module, and decorate any methods you want to trace with `@decorate trace("span name")`. |
| 34 34 | |
| 35 | - The `simple_trace` decorator will automatically add your input parameters and the function result to the span attributes. If you omit the span name, one will be generated based on the module, function, and arity. Specifying a name is helpful for `handle_info` type functions where the name/arity would be ambiguous. |
| 35 | + The `trace` decorator will automatically wrap the decorated function in an opentelemetry span with the provided name. |
| 36 36 | |
| 37 37 | ```elixir |
| 38 38 | defmodule MyApp.Worker do |
| 39 39 | use OpenTelemetryDecorator |
| 40 40 | |
| 41 | - @decorate simple_trace() # Generates span name "MyApp.Worker.do_work/2". or... |
| 42 | - @decorate simple_trace("worker.do_work") |
| 41 | + @decorate trace("worker.do_work") |
| 43 42 | def do_work(arg1, arg2) do |
| 44 43 | ...doing work |
| 45 44 | end |
| @@ -24,4 +24,4 @@ | |
| 24 24 | {<<"optional">>,false}, |
| 25 25 | {<<"repository">>,<<"hexpm">>}, |
| 26 26 | {<<"requirement">>,<<"~> 0.5.0">>}]]}. |
| 27 | - {<<"version">>,<<"0.5.2">>}. |
| 27 | + {<<"version">>,<<"0.5.3">>}. |
| @@ -9,7 +9,7 @@ defmodule OpenTelemetryDecorator do | |
| 9 9 | # compensate for anchor id differences between ExDoc and GitHub |
| 10 10 | |> (&Regex.replace(~R{\(\#\K(?=[a-z][a-z0-9-]+\))}, &1, "module-")).() |
| 11 11 | |
| 12 | - use Decorator.Define, trace: 1, trace: 2, simple_trace: 0, simple_trace: 1 |
| 12 | + use Decorator.Define, trace: 1, trace: 2 |
| 13 13 | |
| 14 14 | @doc """ |
| 15 15 | Decorate a function to add an OpenTelemetry trace with a named span. |
| @@ -75,56 +75,4 @@ defmodule OpenTelemetryDecorator do | |
| 75 75 | target = "#{inspect(context.module)}.#{context.name}/#{context.arity} @decorate telemetry" |
| 76 76 | reraise %ArgumentError{message: "#{target} #{e.message}"}, __STACKTRACE__ |
| 77 77 | end |
| 78 | - |
| 79 | - @doc """ |
| 80 | - Decorate a function to add an OpenTelemetry trace with a named span. The input parameters and result are automatically added to the span attributes. |
| 81 | - You can specify a span name or one will be generated based on the module name, function name, and arity. |
| 82 | - |
| 83 | - ```elixir |
| 84 | - defmodule MyApp.Worker do |
| 85 | - use OpenTelemetryDecorator |
| 86 | - |
| 87 | - @decorate simple_trace() |
| 88 | - def do_work(arg1, arg2) do |
| 89 | - total = arg1.count + arg2.count |
| 90 | - {:ok, total} |
| 91 | - end |
| 92 | - |
| 93 | - @decorate simple_trace("worker.do_more_work") |
| 94 | - def handle_call({:do_more_work, args}, _from, state) do |
| 95 | - {:reply, {:ok, args}, state} |
| 96 | - end |
| 97 | - end |
| 98 | - ``` |
| 99 | - """ |
| 100 | - @deprecated "Use trace instead" |
| 101 | - def simple_trace(body, context) do |
| 102 | - context |
| 103 | - |> SpanName.from_context() |
| 104 | - |> simple_trace(body, context) |
| 105 | - end |
| 106 | - |
| 107 | - def simple_trace(span_name, body, context) do |
| 108 | - quote location: :keep do |
| 109 | - require OpenTelemetry.Span |
| 110 | - require OpenTelemetry.Tracer |
| 111 | - |
| 112 | - parent_ctx = OpenTelemetry.Tracer.current_span_ctx() |
| 113 | - |
| 114 | - OpenTelemetry.Tracer.with_span unquote(span_name), %{parent: parent_ctx} do |
| 115 | - span_ctx = OpenTelemetry.Tracer.current_span_ctx() |
| 116 | - OpenTelemetry.Span.set_attributes(span_ctx, Kernel.binding()) |
| 117 | - |
| 118 | - result = unquote(body) |
| 119 | - |
| 120 | - OpenTelemetry.Span.set_attribute(span_ctx, :result, result) |
| 121 | - |
| 122 | - result |
| 123 | - end |
| 124 | - end |
| 125 | - rescue |
| 126 | - e in ArgumentError -> |
| 127 | - target = "#{inspect(context.module)}.#{context.name}/#{context.arity} @decorate telemetry" |
| 128 | - reraise %ArgumentError{message: "#{target} #{e.message}"}, __STACKTRACE__ |
| 129 | - end |
| 130 78 | end |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule OpenTelemetryDecorator.MixProject do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.5.2" |
| 4 | + @version "0.5.3" |
| 5 5 | @github_page "https://github.com/marcdel/open_telemetry_decorator" |
| 6 6 | |
| 7 7 | def project do |