update elixir experimental api for simplified metrics api

This commit is contained in:
Tristan Sloughter 2025-03-02 05:05:25 -07:00
parent 84d46d524a
commit 278a599b24
No known key found for this signature in database
GPG Key ID: CA1A05537D0EC36D
4 changed files with 29 additions and 125 deletions

View File

@ -13,47 +13,15 @@ defmodule OpenTelemetryAPIExperimental.Counter do
end
end
defmacro add(name_or_instrument, number) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number] do
case is_atom(name_or_instrument) do
true ->
:otel_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
%{}
)
_ ->
:otel_counter.add(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
%{}
)
end
end
end
defmacro add(name_or_instrument, number, attributes) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number, attributes: attributes] do
case is_atom(name_or_instrument) do
true ->
:otel_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
attributes
)
_ ->
:otel_counter.add(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
attributes
)
end
defmacro add(name, number, attributes) do
quote bind_quoted: [name: name, number: number, attributes: attributes] do
:otel_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name,
number,
attributes
)
end
end
end

View File

@ -13,47 +13,15 @@ defmodule OpenTelemetryAPIExperimental.Histogram do
end
end
defmacro record(name_or_instrument, number) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number] do
case is_atom(name_or_instrument) do
true ->
:otel_histogram.record(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
%{}
)
_ ->
:otel_histogram.record(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
%{}
)
end
end
end
defmacro record(name_or_instrument, number, attributes) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number, attributes: attributes] do
case is_atom(name_or_instrument) do
true ->
:otel_histogram.record(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
attributes
)
_ ->
:otel_histogram.record(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
attributes
)
end
defmacro record(name, number, attributes) do
quote bind_quoted: [name: name, number: number, attributes: attributes] do
:otel_histogram.record(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name,
number,
attributes
)
end
end
end

View File

@ -13,47 +13,15 @@ defmodule OpenTelemetryAPIExperimental.UpDownCounter do
end
end
defmacro add(name_or_instrument, number) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number] do
case is_atom(name_or_instrument) do
true ->
:otel_updown_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
%{}
)
_ ->
:otel_updown_counter.add(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
%{}
)
end
end
end
defmacro add(name_or_instrument, number, attributes) do
quote bind_quoted: [name_or_instrument: name_or_instrument, number: number, attributes: attributes] do
case is_atom(name_or_instrument) do
true ->
:otel_updown_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name_or_instrument,
number,
attributes
)
_ ->
:otel_updown_counter.add(
OpenTelemetry.Ctx.get_current(),
name_or_instrument,
number,
attributes
)
end
defmacro add(name, number, attributes) do
quote bind_quoted: [name: name, number: number, attributes: attributes] do
:otel_updown_counter.add(
OpenTelemetry.Ctx.get_current(),
:opentelemetry_experimental.get_meter(:opentelemetry.get_application_scope(__MODULE__)),
name,
number,
attributes
)
end
end
end

View File

@ -106,7 +106,7 @@ defmodule OtelMetricTests do
test "create Histogram with macros" do
Histogram.create(:histogram_a, %{unit: "1", description: "some histogram_a"})
Histogram.record(:histogram_a, 1)
Histogram.record(:histogram_a, 1, %{})
:otel_meter_server.force_flush()
@ -140,7 +140,7 @@ defmodule OtelMetricTests do
)
)}
Histogram.record(:histogram_a, 10)
Histogram.record(:histogram_a, 10, %{})
:otel_meter_server.force_flush()