add first Elixir metric test

This commit is contained in:
Tristan Sloughter 2023-05-10 16:17:10 -06:00
parent a4aaf0a619
commit 77be15a65f
No known key found for this signature in database
GPG Key ID: 6BC93CF674613287
4 changed files with 44 additions and 6 deletions

View File

@ -53,7 +53,7 @@ jobs:
- name: Compile
run: rebar3 as test compile
- name: ExUnit
run: mix test --no-start test/otel_tests.exs
run: mix test --no-start test/otel_tests.exs test/otel_metric_tests.exs
api_tests:
runs-on: ${{ matrix.os }}

View File

@ -45,10 +45,6 @@ defmodule OpenTelemetryExperimental.MixProject do
# Run "mix help compile.app" to learn about applications.
def application, do: []
defp deps() do
[{:opentelemetry_api, path: "../opentelemetry_api/"}]
end
defp deps(rebar) do
rebar
|> Enum.map(fn

View File

@ -15,7 +15,11 @@ defmodule OtelElixirTests.MixProject do
{:opentelemetry, path: "apps/opentelemetry", only: :test, override: true},
{:opentelemetry_api, path: "apps/opentelemetry_api", only: :test, override: true},
{:opentelemetry_semantic_conventions,
path: "apps/opentelemetry_semantic_conventions", only: :test, override: true}
path: "apps/opentelemetry_semantic_conventions", only: :test, override: true},
{:opentelemetry_experimental,
path: "apps/opentelemetry_experimental", only: :test, override: true},
{:opentelemetry_api_experimental,
path: "apps/opentelemetry_api_experimental", only: :test, override: true}
]
end

View File

@ -0,0 +1,38 @@
defmodule OtelMetricTests do
use ExUnit.Case, async: true
require OpenTelemetryAPIExperimental.Counter, as: Counter
require Record
@fields Record.extract(:metric, from_lib: "opentelemetry_experimental/include/otel_metrics.hrl")
Record.defrecordp(:metric, @fields)
setup do
Application.load(:opentelemetry_experimental)
Application.put_env(:opentelemetry_experimental, :readers, [
%{
module: :otel_metric_reader,
config: %{
exporter: {:otel_metric_exporter_pid, {:metric, self()}}
}
}
])
{:ok, _} = Application.ensure_all_started(:opentelemetry_experimental)
on_exit(fn ->
Application.stop(:opentelemetry_experimental)
Application.unload(:opentelemetry_experimental)
end)
end
test "create Counter with macros" do
Counter.create(:counter_a, %{unit: "1", description: "some counter_a"})
Counter.add(:counter_a, 1, [])
:otel_meter_server.force_flush()
assert_receive {:metric, metric(name: :counter_a)}
end
end