From 3faa246d02816ca4ef2b006da5895594104c8de6 Mon Sep 17 00:00:00 2001 From: Andrew Rosa Date: Thu, 24 Mar 2022 14:48:59 -0300 Subject: [PATCH] Remove exporter race-condition on tests (#44) Default exporter immediately attempts on start connect to `:otel-collector` default port. As we don't have any collector running on our test environment, this results in a few warnings. That's not an issue in itself, as code immediately switches to another export, but creates a lot of noise. This patch moves the exporter setup to `config/test.exs`, essentially removing the need to restart opentelemetry applicationn for each test case. The only work setup blocks do is update the exporter's target pid. The processor was changed to simple mode, available now, which also remove another vector of (unlikely but theoretically possible) race-conditions. --- instrumentation/opentelemetry_ecto/config/test.exs | 2 +- .../test/opentelemetry_ecto_test.exs | 11 +---------- instrumentation/opentelemetry_phoenix/config/test.exs | 2 +- .../test/opentelemetry_phoenix_test.exs | 10 +--------- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/instrumentation/opentelemetry_ecto/config/test.exs b/instrumentation/opentelemetry_ecto/config/test.exs index 7a781d0..5087377 100644 --- a/instrumentation/opentelemetry_ecto/config/test.exs +++ b/instrumentation/opentelemetry_ecto/config/test.exs @@ -11,4 +11,4 @@ config :opentelemetry_ecto, OpentelemetryEcto.TestRepo, pool: Ecto.Adapters.SQL.Sandbox config :opentelemetry, - processors: [{:otel_batch_processor, %{scheduled_delay_ms: 1}}] + processors: [{:otel_simple_processor, %{}}] diff --git a/instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs b/instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs index 44d0aef..11be4f3 100644 --- a/instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs +++ b/instrumentation/opentelemetry_ecto/test/opentelemetry_ecto_test.exs @@ -15,16 +15,7 @@ defmodule OpentelemetryEctoTest do end setup do - :application.stop(:opentelemetry) - :application.set_env(:opentelemetry, :tracer, :otel_tracer_default) - - :application.set_env(:opentelemetry, :processors, [ - {:otel_batch_processor, %{scheduled_delay_ms: 1}} - ]) - - :application.start(:opentelemetry) - - :otel_batch_processor.set_exporter(:otel_exporter_pid, self()) + :otel_simple_processor.set_exporter(:otel_exporter_pid, self()) OpenTelemetry.Tracer.start_span("test") diff --git a/instrumentation/opentelemetry_phoenix/config/test.exs b/instrumentation/opentelemetry_phoenix/config/test.exs index a279b9d..28a095d 100644 --- a/instrumentation/opentelemetry_phoenix/config/test.exs +++ b/instrumentation/opentelemetry_phoenix/config/test.exs @@ -1,4 +1,4 @@ import Config config :opentelemetry, - processors: [{:otel_batch_processor, %{scheduled_delay_ms: 1}}] + processors: [{:otel_simple_processor, %{}}] diff --git a/instrumentation/opentelemetry_phoenix/test/opentelemetry_phoenix_test.exs b/instrumentation/opentelemetry_phoenix/test/opentelemetry_phoenix_test.exs index 526d360..077c900 100644 --- a/instrumentation/opentelemetry_phoenix/test/opentelemetry_phoenix_test.exs +++ b/instrumentation/opentelemetry_phoenix/test/opentelemetry_phoenix_test.exs @@ -17,16 +17,8 @@ defmodule OpentelemetryPhoenixTest do end setup do - :application.stop(:opentelemetry) - :application.set_env(:opentelemetry, :tracer, :otel_tracer_default) + :otel_simple_processor.set_exporter(:otel_exporter_pid, self()) - :application.set_env(:opentelemetry, :processors, [ - {:otel_batch_processor, %{scheduled_delay_ms: 1}} - ]) - - :application.start(:opentelemetry) - - :otel_batch_processor.set_exporter(:otel_exporter_pid, self()) :ok end