From 84df985ed3f0e9f76034d1badc72da4621589c5f Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 17 Aug 2023 17:59:26 +0200 Subject: [PATCH 1/9] Typing --- .../include/otel_metrics.hrl | 2 +- .../src/otel_counter.erl | 4 ++-- .../src/otel_histogram.erl | 4 ++-- .../src/otel_instrument.erl | 4 ++-- .../src/otel_meter.erl | 14 +++++++------- .../src/otel_meter_default.erl | 4 ++-- .../src/otel_meter_server.erl | 4 ++-- apps/opentelemetry_experimental/src/otel_view.erl | 3 +-- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/opentelemetry_api_experimental/include/otel_metrics.hrl b/apps/opentelemetry_api_experimental/include/otel_metrics.hrl index f7f1c813..6aa967e1 100644 --- a/apps/opentelemetry_api_experimental/include/otel_metrics.hrl +++ b/apps/opentelemetry_api_experimental/include/otel_metrics.hrl @@ -6,7 +6,7 @@ unit :: otel_instrument:unit() | undefined, temporality :: otel_instrument:temporality(), callback :: otel_instrument:callback() | undefined, - callback_args :: term() | undefined}). + callback_args :: otel_instrument:callback_args() | undefined}). -define(TEMPORALITY_DELTA, temporality_delta). -define(TEMPORALITY_CUMULATIVE, temporality_cumulative). diff --git a/apps/opentelemetry_api_experimental/src/otel_counter.erl b/apps/opentelemetry_api_experimental/src/otel_counter.erl index 730eb639..3c0e9728 100644 --- a/apps/opentelemetry_api_experimental/src/otel_counter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_counter.erl @@ -32,10 +32,10 @@ create(Meter, Name, Opts) -> otel_meter:create_counter(Meter, Name, Opts). --spec add(otel_meter:t(), otel_instrument:name(), number(), opentelemetry:attributes_map()) -> ok. +-spec add(otel_meter:t(), otel_instrument:name(), pos_integer() |float(), opentelemetry:attributes_map()) -> ok. add(Meter, Name, Number, Attributes) -> otel_meter:record(Meter, Name, Number, Attributes). --spec add(otel_instrument:t(), number(), opentelemetry:attributes_map()) -> ok. +-spec add(otel_instrument:t(), pos_integer() |float(), opentelemetry:attributes_map()) -> ok. add(Instrument=#instrument{module=Module}, Number, Attributes) -> Module:record(Instrument, Number, Attributes). diff --git a/apps/opentelemetry_api_experimental/src/otel_histogram.erl b/apps/opentelemetry_api_experimental/src/otel_histogram.erl index ffd2707a..f82a55ea 100644 --- a/apps/opentelemetry_api_experimental/src/otel_histogram.erl +++ b/apps/opentelemetry_api_experimental/src/otel_histogram.erl @@ -33,10 +33,10 @@ create(Meter, Name, Opts) -> otel_meter:create_histogram(Meter, Name, Opts). --spec record(otel_meter:t(), otel_instrument:name(), number(), opentelemetry:attributes_map()) -> ok. +-spec record(otel_meter:t(), otel_instrument:name(), pos_integer() | float(), opentelemetry:attributes_map()) -> ok. record(Meter, Name, Number, Attributes) -> otel_meter:record(Meter, Name, Number, Attributes). --spec record(otel_instrument:t(), number(), opentelemetry:attributes_map()) -> ok. +-spec record(otel_instrument:t(), pos_integer() | float(), opentelemetry:attributes_map()) -> ok. record(Instrument=#instrument{module=Module}, Number, Attributes) -> Module:record(Instrument, Number, Attributes). diff --git a/apps/opentelemetry_api_experimental/src/otel_instrument.erl b/apps/opentelemetry_api_experimental/src/otel_instrument.erl index 3b3a38d1..97f02f90 100644 --- a/apps/opentelemetry_api_experimental/src/otel_instrument.erl +++ b/apps/opentelemetry_api_experimental/src/otel_instrument.erl @@ -51,7 +51,7 @@ callback_args/0, callback_result/0]). --spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit()) -> t(). +-spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit() | undefined) -> t(). new(Module, Meter, Kind, Name, Description, Unit) -> #instrument{module = Module, meter = Meter, @@ -61,7 +61,7 @@ new(Module, Meter, Kind, Name, Description, Unit) -> kind = Kind, unit = Unit}. --spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit(), callback(), term()) -> t(). +-spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit() | undefined, callback(), callback_args()) -> t(). new(Module, Meter, Kind, Name, Description, Unit, Callback, CallbackArgs) -> #instrument{module = Module, meter = Meter, diff --git a/apps/opentelemetry_api_experimental/src/otel_meter.erl b/apps/opentelemetry_api_experimental/src/otel_meter.erl index 3b463eb7..3277f3a7 100644 --- a/apps/opentelemetry_api_experimental/src/otel_meter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_meter.erl @@ -47,14 +47,14 @@ Name :: otel_instrument:name(), Kind :: otel_instrument:kind(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(), + CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). -callback register_callback(Meter, Instruments, Callback, CallbackArgs) -> ok when Meter :: t(), Instruments :: otel_instrument:t(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(). + CallbackArgs :: otel_instrument:callback_args(). -type opts() :: #{description => otel_instrument:description(), unit => otel_instrument:unit()}. @@ -89,7 +89,7 @@ create_histogram(Meter, Name, Opts) -> Meter :: t(), Name :: otel_instrument:name(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(), + CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Callback, CallbackArgs, Opts). @@ -98,7 +98,7 @@ create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> Meter :: t(), Name :: otel_instrument:name(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(), + CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) -> instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Callback, CallbackArgs, Opts). @@ -107,7 +107,7 @@ create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) -> Meter :: t(), Name :: otel_instrument:name(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(), + CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_updowncounter(Meter, Name, Callback, CallbackArgs, Opts) -> instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Callback, CallbackArgs, Opts). @@ -137,7 +137,7 @@ lookup_instrument(Meter={Module, _}, Name) -> Name :: otel_instrument:name(), Kind :: otel_instrument:kind(), Callback :: otel_instrument:callback(), - CallbackArgs :: term(), + CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) -> Module:create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts). @@ -146,7 +146,7 @@ instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) -> Meter :: t(), Instruments :: [otel_instrument:t()], Callback :: otel_instrument:callback(), - CallbackArgs :: term(). + CallbackArgs :: otel_instrument:callback_args(). register_callback(Meter={Module, _}, Instruments, Callback, CallbackArgs) -> Module:register_callback(Meter, Instruments, Callback, CallbackArgs). diff --git a/apps/opentelemetry_experimental/src/otel_meter_default.erl b/apps/opentelemetry_experimental/src/otel_meter_default.erl index e5d3cf07..6668d5af 100644 --- a/apps/opentelemetry_experimental/src/otel_meter_default.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_default.erl @@ -31,7 +31,7 @@ -include_lib("opentelemetry_api_experimental/include/otel_metrics.hrl"). -include("otel_metrics.hrl"). --spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), #{description => unicode:unicode_binary()}) -> otel_instrument:t(). +-spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), otel_meter:opts()) -> otel_instrument:t(). create_instrument(Meter, Name, Kind, Opts) -> Instrument=#instrument{meter={_, #meter{provider=Provider}}} = otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined), @@ -48,7 +48,7 @@ lookup_instrument(Meter={_, #meter{instruments_tab=Tab}}, Name) -> undefined end. --spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), otel_instrument:callback(), otel_instrument:callback_args(), #{description => unicode:unicode_binary()}) -> otel_instrument:t(). +-spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), otel_instrument:callback(), otel_instrument:callback_args(), otel_meter:opts()) -> otel_instrument:t(). create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) -> Instrument=#instrument{meter={_, #meter{provider=Provider}}} = otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined), diff --git a/apps/opentelemetry_experimental/src/otel_meter_server.erl b/apps/opentelemetry_experimental/src/otel_meter_server.erl index a4b4754b..9f23a278 100644 --- a/apps/opentelemetry_experimental/src/otel_meter_server.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_server.erl @@ -124,11 +124,11 @@ add_metric_reader(ReaderId, ReaderPid, DefaultAggregationMapping, Temporality) - add_metric_reader(Provider, ReaderId, ReaderPid, DefaultAggregationMapping, Temporality) -> gen_server:call(Provider, {add_metric_reader, ReaderId, ReaderPid, DefaultAggregationMapping, Temporality}). --spec register_callback([otel_instrument:t()], otel_instrument:callback(), term()) -> boolean(). +-spec register_callback([otel_instrument:t()], otel_instrument:callback(), otel_instrument:callback_args()) -> boolean(). register_callback(Instruments, Callback, CallbackArgs) -> register_callback(?GLOBAL_METER_PROVIDER_REG_NAME, Instruments, Callback, CallbackArgs). --spec register_callback(atom(), [otel_instrument:t()], otel_instrument:callback(), term()) -> boolean(). +-spec register_callback(atom(), [otel_instrument:t()], otel_instrument:callback(), otel_instrument:callback_args()) -> boolean(). register_callback(Provider, Instruments, Callback, CallbackArgs) -> gen_server:call(Provider, {register_callback, Instruments, Callback, CallbackArgs}). diff --git a/apps/opentelemetry_experimental/src/otel_view.erl b/apps/opentelemetry_experimental/src/otel_view.erl index c380c419..bd4f8cf0 100644 --- a/apps/opentelemetry_experimental/src/otel_view.erl +++ b/apps/opentelemetry_experimental/src/otel_view.erl @@ -74,8 +74,7 @@ new(Name, Criteria, Config) -> View#view{name=Name}. -dialyzer({nowarn_function,match_instrument_to_views/2}). --spec match_instrument_to_views(otel_instrument:t(), [otel_view:t()]) -> - [{otel_view:t() | undefined, #view_aggregation{}}]. +-spec match_instrument_to_views(otel_instrument:t(), [t()]) -> [{t() | undefined, #view_aggregation{}}]. match_instrument_to_views(Instrument=#instrument{name=InstrumentName, meter=Meter, description=Description}, Views) -> From d81dd4edaa784b09a8546ebac45f68e496ab30cf Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 17 Aug 2023 17:54:35 +0200 Subject: [PATCH 2/9] Easier way for creating observable instrumenters without callback --- .../lib/open_telemetry/meter.ex | 7 +- .../lib/open_telemetry/observable_counter.ex | 10 ++ .../lib/open_telemetry/observable_gauge.ex | 10 ++ .../observable_updown_counter.ex | 10 ++ .../lib/open_telemetry/updown_counter.ex | 1 - .../src/otel_meter.erl | 24 ++++ .../src/otel_observable_counter.erl | 5 +- .../src/otel_observable_gauge.erl | 5 +- .../src/otel_observable_updowncounter.erl | 5 +- .../test/otel_metrics_test.exs | 104 ++++++++++++++---- .../test/otel_metrics_SUITE.erl | 11 +- 11 files changed, 159 insertions(+), 33 deletions(-) diff --git a/apps/opentelemetry_api_experimental/lib/open_telemetry/meter.ex b/apps/opentelemetry_api_experimental/lib/open_telemetry/meter.ex index bbc01796..07c32426 100644 --- a/apps/opentelemetry_api_experimental/lib/open_telemetry/meter.ex +++ b/apps/opentelemetry_api_experimental/lib/open_telemetry/meter.ex @@ -19,6 +19,11 @@ defmodule OpenTelemetryAPIExperimental.Meter do end defmacro register_callback(instruments, callback, callback_args) do - :otel_meter.register_callback(:opentelemetry_experimental.get_meter(__MODULE__), instruments, callback, callback_args) + :otel_meter.register_callback( + :opentelemetry_experimental.get_meter(__MODULE__), + instruments, + callback, + callback_args + ) end end diff --git a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_counter.ex b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_counter.ex index 62f56312..2e4efc29 100644 --- a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_counter.ex +++ b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_counter.ex @@ -3,6 +3,16 @@ defmodule OpenTelemetryAPIExperimental.ObservableCounter do """ + defmacro create(name, opts) do + quote bind_quoted: [name: name, opts: opts] do + :otel_meter.create_observable_counter( + :opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)), + name, + opts + ) + end + end + defmacro create(name, callback, callback_args, opts) do quote bind_quoted: [ name: name, diff --git a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_gauge.ex b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_gauge.ex index d98ba509..5284606c 100644 --- a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_gauge.ex +++ b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_gauge.ex @@ -3,6 +3,16 @@ defmodule OpenTelemetryAPIExperimental.ObservableGauge do """ + defmacro create(name, opts) do + quote bind_quoted: [name: name, opts: opts] do + :otel_meter.create_observable_gauge( + :opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)), + name, + opts + ) + end + end + defmacro create(name, callback, callback_args, opts) do quote bind_quoted: [ name: name, diff --git a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_updown_counter.ex b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_updown_counter.ex index 67695f28..fd52a535 100644 --- a/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_updown_counter.ex +++ b/apps/opentelemetry_api_experimental/lib/open_telemetry/observable_updown_counter.ex @@ -3,6 +3,16 @@ defmodule OpenTelemetryAPIExperimental.ObservableUpDownCounter do """ + defmacro create(name, opts) do + quote bind_quoted: [name: name, opts: opts] do + :otel_meter.create_observable_updowncounter( + :opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)), + name, + opts + ) + end + end + defmacro create(name, callback, callback_args, opts) do quote bind_quoted: [ name: name, diff --git a/apps/opentelemetry_api_experimental/lib/open_telemetry/updown_counter.ex b/apps/opentelemetry_api_experimental/lib/open_telemetry/updown_counter.ex index d5d1ea5c..6b424668 100644 --- a/apps/opentelemetry_api_experimental/lib/open_telemetry/updown_counter.ex +++ b/apps/opentelemetry_api_experimental/lib/open_telemetry/updown_counter.ex @@ -13,7 +13,6 @@ defmodule OpenTelemetryAPIExperimental.UpDownCounter do end end - defmacro add(name, number, attributes) do quote bind_quoted: [name: name, number: number, attributes: attributes] do :otel_updown_counter.add( diff --git a/apps/opentelemetry_api_experimental/src/otel_meter.erl b/apps/opentelemetry_api_experimental/src/otel_meter.erl index 3277f3a7..651ce02b 100644 --- a/apps/opentelemetry_api_experimental/src/otel_meter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_meter.erl @@ -21,8 +21,11 @@ create_histogram/3, create_updown_counter/3, + create_observable_counter/3, create_observable_counter/5, + create_observable_gauge/3, create_observable_gauge/5, + create_observable_updowncounter/3, create_observable_updowncounter/5, scope/1, @@ -85,6 +88,13 @@ create_updown_counter(Meter, Name, Opts) -> create_histogram(Meter, Name, Opts) -> create_instrument(Meter, Name, ?KIND_HISTOGRAM, Opts). +-spec create_observable_counter(Meter, Name, Opts) -> otel_instrument:t() when + Meter :: t(), + Name :: otel_instrument:name(), + Opts :: opts(). +create_observable_counter(Meter, Name, Opts) -> + create_instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Opts). + -spec create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> otel_instrument:t() when Meter :: t(), Name :: otel_instrument:name(), @@ -94,6 +104,13 @@ create_histogram(Meter, Name, Opts) -> create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Callback, CallbackArgs, Opts). +-spec create_observable_gauge(Meter, Name, Opts) -> otel_instrument:t() when + Meter :: t(), + Name :: otel_instrument:name(), + Opts :: opts(). +create_observable_gauge(Meter, Name, Opts) -> + create_instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Opts). + -spec create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) -> otel_instrument:t() when Meter :: t(), Name :: otel_instrument:name(), @@ -103,6 +120,13 @@ create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) -> instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Callback, CallbackArgs, Opts). +-spec create_observable_updowncounter(Meter, Name, Opts) -> otel_instrument:t() when + Meter :: t(), + Name :: otel_instrument:name(), + Opts :: opts(). +create_observable_updowncounter(Meter, Name, Opts) -> + create_instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Opts). + -spec create_observable_updowncounter(Meter, Name, Callback, CallbackArgs, Opts) -> otel_instrument:t() when Meter :: t(), Name :: otel_instrument:name(), diff --git a/apps/opentelemetry_api_experimental/src/otel_observable_counter.erl b/apps/opentelemetry_api_experimental/src/otel_observable_counter.erl index ad324720..a4bbc67e 100644 --- a/apps/opentelemetry_api_experimental/src/otel_observable_counter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_observable_counter.erl @@ -18,7 +18,10 @@ %%%------------------------------------------------------------------------- -module(otel_observable_counter). --export([create/5]). +-export([create/3, create/5]). + +create(Meter, Name, Opts) -> + otel_meter:create_observable_counter(Meter, Name, Opts). create(Meter, Name, Callback, CallbackArgs, Opts) -> otel_meter:create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts). diff --git a/apps/opentelemetry_api_experimental/src/otel_observable_gauge.erl b/apps/opentelemetry_api_experimental/src/otel_observable_gauge.erl index 98e55649..46f8c9b6 100644 --- a/apps/opentelemetry_api_experimental/src/otel_observable_gauge.erl +++ b/apps/opentelemetry_api_experimental/src/otel_observable_gauge.erl @@ -25,7 +25,10 @@ %%%------------------------------------------------------------------------- -module(otel_observable_gauge). --export([create/5]). +-export([create/3, create/5]). + +create(Meter, Name, Opts) -> + otel_meter:create_observable_gauge(Meter, Name, Opts). create(Meter, Name, Callback, CallbackArgs, Opts) -> otel_meter:create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts). diff --git a/apps/opentelemetry_api_experimental/src/otel_observable_updowncounter.erl b/apps/opentelemetry_api_experimental/src/otel_observable_updowncounter.erl index 5bc26411..565c821f 100644 --- a/apps/opentelemetry_api_experimental/src/otel_observable_updowncounter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_observable_updowncounter.erl @@ -23,7 +23,10 @@ %%%------------------------------------------------------------------------- -module(otel_observable_updowncounter). --export([create/5]). +-export([create/3, create/5]). + +create(Meter, Name, Opts) -> + otel_meter:create_observable_updowncounter(Meter, Name, Opts). create(Meter, Name, Callback, CallbackArgs, Opts) -> otel_meter:create_observable_updowncounter(Meter, Name, Callback, CallbackArgs, Opts). diff --git a/apps/opentelemetry_api_experimental/test/otel_metrics_test.exs b/apps/opentelemetry_api_experimental/test/otel_metrics_test.exs index aeb0aa8d..286e8c33 100644 --- a/apps/opentelemetry_api_experimental/test/otel_metrics_test.exs +++ b/apps/opentelemetry_api_experimental/test/otel_metrics_test.exs @@ -9,48 +9,114 @@ defmodule OpenTelemetryTest do require OpenTelemetryAPIExperimental.Histogram, as: Histogram require Record - @fields Record.extract(:instrument, from_lib: "opentelemetry_api_experimental/include/otel_metrics.hrl") + + @fields Record.extract(:instrument, + from_lib: "opentelemetry_api_experimental/include/otel_metrics.hrl" + ) Record.defrecordp(:instrument, @fields) test "create counter instrument with no-op meter" do c = Counter.create(:a_counter, %{}) - assert instrument(module: :otel_meter_noop, - meter: {:otel_meter_noop, []}, - name: :a_counter, - kind: :counter) == c + + assert instrument( + module: :otel_meter_noop, + meter: {:otel_meter_noop, []}, + name: :a_counter, + kind: :counter, + temporality: :temporality_delta + ) == c end test "create updown counter instrument with no-op meter" do c = UpDownCounter.create(:ud_counter, %{}) - assert instrument(module: :otel_meter_noop, - meter: {:otel_meter_noop, []}, - name: :ud_counter, - kind: :updown_counter) == c + + assert instrument( + module: :otel_meter_noop, + meter: {:otel_meter_noop, []}, + name: :ud_counter, + kind: :updown_counter, + temporality: :temporality_delta + ) == c end test "create histogram instrument with no-op meter" do c = Histogram.create(:a_histogram, %{}) - assert instrument(module: :otel_meter_noop, - meter: {:otel_meter_noop, []}, - name: :a_histogram, - kind: :histogram) == c + + assert instrument( + module: :otel_meter_noop, + meter: {:otel_meter_noop, []}, + name: :a_histogram, + kind: :histogram, + temporality: :temporality_delta + ) == c end test "create observable counter with no-op meter" do o = ObservableCounter.create(:o_counter, fn _ -> {3, %{}} end, [], %{}) - assert instrument(name: :o_counter, - kind: :observable_counter) = o + + assert match?(instrument( + name: :o_counter, + kind: :observable_counter, + callback: callback, + callback_args: [] + ) + when callback != :undefined, o) end test "create observable gauge with no-op meter" do o = ObservableGauge.create(:a_gauge, fn _ -> {3, %{}} end, [], %{}) - assert instrument(name: :a_gauge, - kind: :observable_gauge) = o + + assert match?(instrument( + name: :a_gauge, + kind: :observable_gauge, + callback: callback, + callback_args: [] + ) + when callback != :undefined, o) end test "create observable updown counter with no-op meter" do o = ObservableUpDownCounter.create(:ouc_counter, fn _ -> {3, %{}} end, [], %{}) - assert instrument(name: :ouc_counter, - kind: :observable_updowncounter) = o + + assert match?(instrument( + name: :ouc_counter, + kind: :observable_updowncounter, + callback: callback, + callback_args: [] + ) + when callback != :undefined, o) + end + + test "create observable counter with no-op meter and no callback" do + o = ObservableCounter.create(:o_counter_no_cbk, %{}) + + assert instrument( + name: :o_counter_no_cbk, + kind: :observable_counter, + callback: :undefined, + callback_args: :undefined + ) = o + end + + test "create observable gauge with no-op meter and no callback" do + o = ObservableGauge.create(:a_gauge_no_cbk, %{}) + + assert instrument( + name: :a_gauge_no_cbk, + kind: :observable_gauge, + callback: :undefined, + callback_args: :undefined + ) = o + end + + test "create observable updown counter with no-op meter and no callback" do + o = ObservableUpDownCounter.create(:ouc_counter_no_cbk, %{}) + + assert instrument( + name: :ouc_counter_no_cbk, + kind: :observable_updowncounter, + callback: :undefined, + callback_args: :undefined + ) = o end end diff --git a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl index 5d718357..4ca739b2 100644 --- a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl +++ b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl @@ -938,15 +938,8 @@ multi_instrument_callback(_Config) -> ?assert(otel_meter_server:add_view(#{instrument_name => CounterName}, #{aggregation_module => otel_aggregation_sum})), - Counter = otel_meter:create_observable_counter(Meter, CounterName, - undefined, [], - #{description => CounterDesc, - unit => Unit}), - - Gauge = otel_meter:create_observable_gauge(Meter, GaugeName, - undefined, [], - #{description => GaugeDesc, - unit => Unit}), + Counter = otel_observable_counter:create(Meter, CounterName, #{description => CounterDesc, unit => Unit}), + Gauge = otel_observable_gauge:create(Meter, GaugeName, #{description => GaugeDesc, unit => Unit}), otel_meter:register_callback(Meter, [Counter, Gauge], fun(_) -> From b7593344377b3df89ed5787318cfef1070c26526 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 17 Aug 2023 18:13:26 +0200 Subject: [PATCH 3/9] Add instrument_unit to view criteria --- apps/opentelemetry_experimental/src/otel_view.erl | 3 +++ apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/apps/opentelemetry_experimental/src/otel_view.erl b/apps/opentelemetry_experimental/src/otel_view.erl index bd4f8cf0..639246a8 100644 --- a/apps/opentelemetry_experimental/src/otel_view.erl +++ b/apps/opentelemetry_experimental/src/otel_view.erl @@ -30,6 +30,7 @@ -type criteria() :: #{instrument_name => otel_instrument:name(), instrument_kind => otel_instrument:kind(), + instrument_unit => otel_instrument:unit(), meter_name => unicode:unicode_binary() | undefined, meter_version => unicode:unicode_binary() | undefined, meter_schema_url => unicode:unicode_binary() | undefined}. @@ -134,6 +135,8 @@ criteria_to_instrument_matchspec(Criteria) when is_map(Criteria) -> InstrumentAcc#instrument{name=InstrumentName}; (instrument_kind, Kind, InstrumentAcc) -> InstrumentAcc#instrument{kind=Kind}; + (instrument_unit, Unit, InstrumentAcc) -> + InstrumentAcc#instrument{unit=Unit}; (meter_name, MeterName, InstrumentAcc) -> Meter = maybe_init_meter(InstrumentAcc), Meter1 = update_meter_name(MeterName, Meter), diff --git a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl index 4ca739b2..aee14b3c 100644 --- a/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl +++ b/apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl @@ -425,6 +425,12 @@ view_creation_test(_Config) -> Matches = otel_view:match_instrument_to_views(Counter, [View]), ?assertMatch([_], Matches), + ViewUnitMatch = otel_view:new(#{instrument_name => CounterName, instrument_unit => CounterUnit}, #{aggregation_module => otel_aggregation_sum}), + ?assertMatch([{#view{}, _}], otel_view:match_instrument_to_views(Counter, [ViewUnitMatch])), + + ViewUnitNotMatch = otel_view:new(#{instrument_name => CounterName, instrument_unit => not_matching}, #{aggregation_module => otel_aggregation_sum}), + ?assertMatch([{undefined, _}], otel_view:match_instrument_to_views(Counter, [ViewUnitNotMatch])), + %% views require a unique name ?assert(otel_meter_server:add_view(view_b, #{instrument_name => a_counter}, #{aggregation_module => otel_aggregation_sum})), %% ?assertNot(otel_meter_server:add_view(view_b, #{instrument_name => a_counter}, #{aggregation_module => otel_aggregation_sum})), From 95b08e129c6876472b15887589adf84ce5f669f3 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Fri, 18 Aug 2023 08:57:42 +0200 Subject: [PATCH 4/9] Remove unused export, uniform function names --- .../src/otel_meter.erl | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/opentelemetry_api_experimental/src/otel_meter.erl b/apps/opentelemetry_api_experimental/src/otel_meter.erl index 651ce02b..ded8ff20 100644 --- a/apps/opentelemetry_api_experimental/src/otel_meter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_meter.erl @@ -32,7 +32,6 @@ register_callback/4, - instrument/6, lookup_instrument/2, record/4]). @@ -102,7 +101,7 @@ create_observable_counter(Meter, Name, Opts) -> CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) -> - instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Callback, CallbackArgs, Opts). + create_instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Callback, CallbackArgs, Opts). -spec create_observable_gauge(Meter, Name, Opts) -> otel_instrument:t() when Meter :: t(), @@ -118,7 +117,7 @@ create_observable_gauge(Meter, Name, Opts) -> CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) -> - instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Callback, CallbackArgs, Opts). + create_instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Callback, CallbackArgs, Opts). -spec create_observable_updowncounter(Meter, Name, Opts) -> otel_instrument:t() when Meter :: t(), @@ -134,7 +133,7 @@ create_observable_updowncounter(Meter, Name, Opts) -> CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). create_observable_updowncounter(Meter, Name, Callback, CallbackArgs, Opts) -> - instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Callback, CallbackArgs, Opts). + create_instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Callback, CallbackArgs, Opts). -spec scope(Meter) -> Scope when Meter :: t(), @@ -150,22 +149,23 @@ scope(Meter={Module, _}) -> create_instrument(Meter={Module, _}, Name, Kind, Opts) -> Module:create_instrument(Meter, Name, Kind, Opts). --spec lookup_instrument(Meter, Name) -> otel_instrument:t() when - Meter :: t(), - Name :: otel_instrument:name(). -lookup_instrument(Meter={Module, _}, Name) -> - Module:lookup_instrument(Meter, Name). - --spec instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) -> otel_instrument:t() when +-spec create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) -> otel_instrument:t() when Meter :: t(), Name :: otel_instrument:name(), Kind :: otel_instrument:kind(), Callback :: otel_instrument:callback(), CallbackArgs :: otel_instrument:callback_args(), Opts :: opts(). -instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) -> +create_instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) -> Module:create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts). +-spec lookup_instrument(Meter, Name) -> otel_instrument:t() when + Meter :: t(), + Name :: otel_instrument:name(). +lookup_instrument(Meter={Module, _}, Name) -> + Module:lookup_instrument(Meter, Name). + + -spec register_callback(Meter, Instruments, Callback, CallbackArgs) -> ok when Meter :: t(), Instruments :: [otel_instrument:t()], From ca4f32406294f6e972984049411f97f88d5ed581 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Fri, 18 Aug 2023 09:47:36 +0200 Subject: [PATCH 5/9] Remove unused test Unused because the CT suite name was duplicated, the same tests are covered in the opentelemetry_experimental tests --- .../test/otel_metrics_SUITE.erl | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl diff --git a/apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl b/apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl deleted file mode 100644 index 74b0b10c..00000000 --- a/apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl +++ /dev/null @@ -1,93 +0,0 @@ --module(otel_metrics_SUITE). - --compile(export_all). - --include_lib("stdlib/include/assert.hrl"). --include_lib("common_test/include/ct.hrl"). --include_lib("opentelemetry_api/include/opentelemetry.hrl"). - -all() -> - [{group, integer}, {group, float}]. - -groups() -> - [{integer, [shuffle, parallel], [sync_instruments]}, - {float, [shuffle, parallel], [sync_instruments]}]. - -init_per_suite(Config) -> - application:load(opentelemetry_api), - Config. - -end_per_suite(_Config) -> - ok. - -init_per_group(Group, Config) -> - [{value_type, Group} | Config]. - -end_per_group(_, _) -> - ok. - -sync_instruments(Config) -> - ValueType = ?config(value_type, Config), - - Meter = opentelemetry_experimental:get_meter(), - ?assertMatch({otel_meter_noop, _}, Meter), - - CounterName = a_counter, - CounterDesc = <<"counter description">>, - CounterUnit = kb, - - Counter = otel_meter:create_counter(Meter, CounterName, ValueType, - #{description => CounterDesc, - unit => CounterUnit}), - ?assertEqual(#{meter => {otel_meter_noop,[]}, - module => otel_meter_noop, - name => CounterName, - description => CounterDesc, - kind => counter, - value_type => ValueType, - unit => CounterUnit}, Counter), - - ?assertEqual(ok, otel_counter:add(Counter, value(ValueType), #{})), - - UpDownCounterName = a_updown_counter, - UpDownCounterDesc = <<"updown counter description">>, - UpDownCounterUnit = '1', - - UpDownCounter = otel_meter:create_updown_counter(Meter, UpDownCounterName, ValueType, - #{description => UpDownCounterDesc, - unit => UpDownCounterUnit}), - ?assertEqual(#{meter => {otel_meter_noop,[]}, - module => otel_meter_noop, - name => UpDownCounterName, - description => UpDownCounterDesc, - kind => updown_counter, - value_type => ValueType, - unit => UpDownCounterUnit}, UpDownCounter), - - ?assertEqual(ok, otel_counter:add(Counter, 0 - value(ValueType), #{})), - - HistogramName = a_histogram, - HistogramDesc = <<"histogram description">>, - HistogramUnit = ms, - - Histogram = otel_meter:create_histogram(Meter, HistogramName, ValueType, - #{description => HistogramDesc, - unit => HistogramUnit}), - ?assertEqual(#{meter => {otel_meter_noop,[]}, - module => otel_meter_noop, - name => HistogramName, - description => HistogramDesc, - kind => histogram, - value_type => ValueType, - unit => HistogramUnit}, Histogram), - - ?assertEqual(ok, otel_histogram:record(Counter, value(ValueType), #{})), - - ok. - -%% - -value(integer) -> - 3; -value(float) -> - 2.0. From cb3694ed6075a1cdb89a96f4ae69694dea22588e Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Tue, 22 Aug 2023 17:25:54 +0200 Subject: [PATCH 6/9] Validate instrument name --- .../src/otel_meter.erl | 3 +-- .../src/otel_meter_default.erl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/opentelemetry_api_experimental/src/otel_meter.erl b/apps/opentelemetry_api_experimental/src/otel_meter.erl index ded8ff20..fbda6063 100644 --- a/apps/opentelemetry_api_experimental/src/otel_meter.erl +++ b/apps/opentelemetry_api_experimental/src/otel_meter.erl @@ -165,7 +165,6 @@ create_instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) - lookup_instrument(Meter={Module, _}, Name) -> Module:lookup_instrument(Meter, Name). - -spec register_callback(Meter, Instruments, Callback, CallbackArgs) -> ok when Meter :: t(), Instruments :: [otel_instrument:t()], @@ -175,4 +174,4 @@ register_callback(Meter={Module, _}, Instruments, Callback, CallbackArgs) -> Module:register_callback(Meter, Instruments, Callback, CallbackArgs). record(Meter={Module, _}, Name, Number, Attributes) -> - Module:record(Meter, Name, Number, Attributes). + Module:record(Meter, Name, Number, Attributes). \ No newline at end of file diff --git a/apps/opentelemetry_experimental/src/otel_meter_default.erl b/apps/opentelemetry_experimental/src/otel_meter_default.erl index 6668d5af..57d2fb23 100644 --- a/apps/opentelemetry_experimental/src/otel_meter_default.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_default.erl @@ -28,11 +28,13 @@ -export([record/3, record/4]). +-include_lib("kernel/include/logger.hrl"). -include_lib("opentelemetry_api_experimental/include/otel_metrics.hrl"). -include("otel_metrics.hrl"). -spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), otel_meter:opts()) -> otel_instrument:t(). create_instrument(Meter, Name, Kind, Opts) -> + validate_name(Name), Instrument=#instrument{meter={_, #meter{provider=Provider}}} = otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined), maps:get(unit, Opts, undefined)), @@ -50,6 +52,7 @@ lookup_instrument(Meter={_, #meter{instruments_tab=Tab}}, Name) -> -spec create_instrument(otel_meter:t(), otel_instrument:name(), otel_instrument:kind(), otel_instrument:callback(), otel_instrument:callback_args(), otel_meter:opts()) -> otel_instrument:t(). create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) -> + validate_name(Name), Instrument=#instrument{meter={_, #meter{provider=Provider}}} = otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined), maps:get(unit, Opts, undefined), Callback, CallbackArgs), @@ -64,6 +67,19 @@ register_callback(_, _, _, _) -> scope({_, #meter{instrumentation_scope=Scope}}) -> Scope. +validate_name(Name) when is_atom(Name) -> + Re = "^[A-Za-z]+[A-Za-z0-9_.\-]{0,62}$", + NameString = atom_to_list(Name), + case re:run(NameString, Re) of + {match, _} -> + ok; + nomatch -> + ?LOG_ERROR("Invalid instrument name, should be an atom matching '~s', but got '~s'", [NameString]), + ok + end; +validate_name(Name) -> + ?LOG_ERROR("Invalid instrument name, should be an atom matching '~s', but got ~p", [Name]), + ok. %% record(Instrument=#instrument{meter={_, #meter{view_aggregations_tab=ViewAggregationTab, From 39f382205051e537bba8afd6bbea449bd0e403a1 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Fri, 18 Aug 2023 11:39:40 +0200 Subject: [PATCH 7/9] Fix dialyzer warnings --- apps/opentelemetry_api/.dialyzer_ignore.exs | 3 --- apps/opentelemetry_api/dialyzer.ignore-warnings | 2 +- apps/opentelemetry_api/mix.exs | 13 ++++++++++++- apps/opentelemetry_api/mix.lock | 3 ++- apps/opentelemetry_api_experimental/mix.lock | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) delete mode 100644 apps/opentelemetry_api/.dialyzer_ignore.exs create mode 100644 apps/opentelemetry_api_experimental/mix.lock diff --git a/apps/opentelemetry_api/.dialyzer_ignore.exs b/apps/opentelemetry_api/.dialyzer_ignore.exs deleted file mode 100644 index 5d02cd94..00000000 --- a/apps/opentelemetry_api/.dialyzer_ignore.exs +++ /dev/null @@ -1,3 +0,0 @@ -[ - {"lib/open_telemetry/span.ex", :invalid_contract} -] diff --git a/apps/opentelemetry_api/dialyzer.ignore-warnings b/apps/opentelemetry_api/dialyzer.ignore-warnings index abba9cdc..c45a43c1 100644 --- a/apps/opentelemetry_api/dialyzer.ignore-warnings +++ b/apps/opentelemetry_api/dialyzer.ignore-warnings @@ -1 +1 @@ -src/otel_tracer_provider.erl:37:5: Unknown function otel_tracer_provider_sup:start/2 +src/otel_tracer_provider.erl:39:5: Unknown function otel_tracer_provider_sup:start/2 diff --git a/apps/opentelemetry_api/mix.exs b/apps/opentelemetry_api/mix.exs index ead0c84c..b1f7af1d 100644 --- a/apps/opentelemetry_api/mix.exs +++ b/apps/opentelemetry_api/mix.exs @@ -12,6 +12,12 @@ defmodule OpenTelemetry.MixProject do start_permanent: Mix.env() == :prod, deps: [ {:opentelemetry_semantic_conventions, "~> 0.2"}, + {:eqwalizer_support, + git: "https://github.com/whatsapp/eqwalizer.git", + branch: "main", + sparse: "eqwalizer_support", + only: [:dev], + runtime: false}, {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, {:covertool, ">= 0.0.0", only: :test} ], @@ -19,7 +25,12 @@ defmodule OpenTelemetry.MixProject do test_coverage: [tool: :covertool], package: package(), aliases: [docs: & &1], - dialyzer: [ignore_warnings: "dialyzer.ignore-warnings", remove_defaults: [:unknown]] + dialyzer: [ + ignore_warnings: "dialyzer.ignore-warnings", + remove_defaults: [:unknown], + plt_add_apps: [:eqwalizer_support], + list_unused_filters: true + ] ] end diff --git a/apps/opentelemetry_api/mix.lock b/apps/opentelemetry_api/mix.lock index 226a2f7d..badaab35 100644 --- a/apps/opentelemetry_api/mix.lock +++ b/apps/opentelemetry_api/mix.lock @@ -1,10 +1,11 @@ %{ "cmark": {:hex, :cmark, "0.10.0", "51217dc90fec459f34a30ea73345e6a7c1d2f3d618cb4a1738a2ebd0697a57a0", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "00abeadc6f3176e3941853122413082de95d57787777dd0400d64e568acf7c32"}, "covertool": {:hex, :covertool, "2.0.3", "5d1ca6958482b9b7e718daf61f398e382426ed0f4689d5c8698a60ae3b5ba521", [:rebar3], [], "hexpm", "5c13170a55dbd6bd9efc722bc7fa32caff6f3c9cde9c692bd4a88bfc9ac4f029"}, - "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"}, "earmark": {:hex, :earmark, "1.4.14", "d04572cef64dd92726a97d92d714e38d6e130b024ea1b3f8a56e7de66ec04e50", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "df338b8b1852ee425180b276c56c6941cb12220e04fe8718fe4acbdd35fd699f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"}, "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, + "eqwalizer_support": {:git, "https://github.com/whatsapp/eqwalizer.git", "1a787cb604f6083ebe8763e358ea362e4677e500", [branch: "main", sparse: "eqwalizer_support"]}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.28.0", "7eaf526dd8c80ae8c04d52ac8801594426ae322b52a6156cd038f30bafa8226f", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e55cdadf69a5d1f4cfd8477122ebac5e1fadd433a8c1022dafc5025e48db0131"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, diff --git a/apps/opentelemetry_api_experimental/mix.lock b/apps/opentelemetry_api_experimental/mix.lock new file mode 100644 index 00000000..a1cc64e6 --- /dev/null +++ b/apps/opentelemetry_api_experimental/mix.lock @@ -0,0 +1,15 @@ +%{ + "cmark": {:hex, :cmark, "0.10.0", "51217dc90fec459f34a30ea73345e6a7c1d2f3d618cb4a1738a2ebd0697a57a0", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "00abeadc6f3176e3941853122413082de95d57787777dd0400d64e568acf7c32"}, + "covertool": {:hex, :covertool, "2.0.6", "4a291b4e3449025b0595d8f44c8d7635d4f48f033be2ce88d22a329f36f94a91", [:rebar3], [], "hexpm", "5db3fcd82180d8ea4ad857d4d1ab21a8d31b5aee0d60d2f6c0f9e25a411d1e21"}, + "dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"}, + "earmark": {:hex, :earmark, "1.4.39", "acdb2f02c536471029dbcc509fbd6b94b89f40ad7729fb3f68f4b6944843f01d", [:mix], [{:earmark_parser, "~> 1.4.33", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "156c9d8ec3cbeccdbf26216d8247bdeeacc8c76b4d9eee7554be2f1b623ea440"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"}, + "elixir_make": {:hex, :elixir_make, "0.7.7", "7128c60c2476019ed978210c245badf08b03dbec4f24d05790ef791da11aa17c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bc19fff950fad52bbe5f211b12db9ec82c6b34a9647da0c2224b8b8464c7e6c"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_doc": {:hex, :ex_doc, "0.21.0", "7af8cd3e3df2fe355e99dabd2d4dcecc6e76eb417200e3b7a3da362d52730e3c", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "ef679a81de63385c7e72597e81ca1276187505eeacb38281a672d2822254ff1a"}, + "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [: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", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, + "opentelemetry_api": {:hex, :opentelemetry_api, "1.2.2", "693f47b0d8c76da2095fe858204cfd6350c27fe85d00e4b763deecc9588cf27a", [:mix, :rebar3], [{:opentelemetry_semantic_conventions, "~> 0.2", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: false]}], "hexpm", "dc77b9a00f137a858e60a852f14007bb66eda1ffbeb6c05d5fe6c9e678b05e9d"}, + "opentelemetry_semantic_conventions": {:hex, :opentelemetry_semantic_conventions, "0.2.0", "b67fe459c2938fcab341cb0951c44860c62347c005ace1b50f8402576f241435", [:mix, :rebar3], [], "hexpm", "d61fa1f5639ee8668d74b527e6806e0503efc55a42db7b5f39939d84c07d6895"}, +} From c4060002c4b3c4b0bd9c34086f70316f1d0e4435 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Fri, 18 Aug 2023 18:01:22 +0200 Subject: [PATCH 8/9] Duplicated code --- .../src/otel_meter_server.erl | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/apps/opentelemetry_experimental/src/otel_meter_server.erl b/apps/opentelemetry_experimental/src/otel_meter_server.erl index 9f23a278..2f149f8d 100644 --- a/apps/opentelemetry_experimental/src/otel_meter_server.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_server.erl @@ -299,20 +299,9 @@ new_view(ViewConfig) -> %% Match the Instrument to views and then store a per-Reader aggregation for the View add_instrument_(InstrumentsTab, CallbacksTab, ViewAggregationsTab, Instrument=#instrument{meter=Meter, name=Name}, Views, Readers) -> - Key = {Meter, Name}, - case ets:insert_new(InstrumentsTab, {Key, Instrument}) of + case ets:insert_new(InstrumentsTab, {{Meter, Name}, Instrument}) of true -> - ViewMatches = otel_view:match_instrument_to_views(Instrument, Views), - lists:foreach(fun(Reader=#reader{id=ReaderId}) -> - Matches = per_reader_aggregations(Reader, Instrument, ViewMatches), - [_ = ets:insert(ViewAggregationsTab, {Key, M}) || M <- Matches], - case {Instrument#instrument.callback, Instrument#instrument.callback_args} of - {undefined, _} -> - ok; - {Callback, CallbackArgs} -> - ets:insert(CallbacksTab, {ReaderId, {Callback, CallbackArgs, Instrument}}) - end - end, Readers); + update_view_aggregations_(Instrument, CallbacksTab, ViewAggregationsTab, Views, Readers); false -> ?LOG_INFO("Instrument ~p already created. Ignoring attempt to create Instrument with the same name in the same Meter.", [Name]), ok From ca16631fd9748011bde47f5c3ca53ef457bad7e4 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Wed, 23 Aug 2023 13:38:34 +0200 Subject: [PATCH 9/9] Update apps/opentelemetry_experimental/src/otel_meter_default.erl Co-authored-by: Tristan Sloughter --- apps/opentelemetry_experimental/src/otel_meter_default.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opentelemetry_experimental/src/otel_meter_default.erl b/apps/opentelemetry_experimental/src/otel_meter_default.erl index 57d2fb23..83d3772c 100644 --- a/apps/opentelemetry_experimental/src/otel_meter_default.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_default.erl @@ -70,8 +70,8 @@ scope({_, #meter{instrumentation_scope=Scope}}) -> validate_name(Name) when is_atom(Name) -> Re = "^[A-Za-z]+[A-Za-z0-9_.\-]{0,62}$", NameString = atom_to_list(Name), - case re:run(NameString, Re) of - {match, _} -> + case re:run(NameString, Re, [{capture, none}]) of + match -> ok; nomatch -> ?LOG_ERROR("Invalid instrument name, should be an atom matching '~s', but got '~s'", [NameString]),