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.
This commit is contained in:
Andrew Rosa 2022-03-24 14:48:59 -03:00 committed by GitHub
parent 7a5802cb14
commit 3faa246d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 21 deletions

View File

@ -11,4 +11,4 @@ config :opentelemetry_ecto, OpentelemetryEcto.TestRepo,
pool: Ecto.Adapters.SQL.Sandbox pool: Ecto.Adapters.SQL.Sandbox
config :opentelemetry, config :opentelemetry,
processors: [{:otel_batch_processor, %{scheduled_delay_ms: 1}}] processors: [{:otel_simple_processor, %{}}]

View File

@ -15,16 +15,7 @@ defmodule OpentelemetryEctoTest do
end end
setup do setup do
:application.stop(:opentelemetry) :otel_simple_processor.set_exporter(:otel_exporter_pid, self())
: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())
OpenTelemetry.Tracer.start_span("test") OpenTelemetry.Tracer.start_span("test")

View File

@ -1,4 +1,4 @@
import Config import Config
config :opentelemetry, config :opentelemetry,
processors: [{:otel_batch_processor, %{scheduled_delay_ms: 1}}] processors: [{:otel_simple_processor, %{}}]

View File

@ -17,16 +17,8 @@ defmodule OpentelemetryPhoenixTest do
end end
setup do setup do
:application.stop(:opentelemetry) :otel_simple_processor.set_exporter(:otel_exporter_pid, self())
: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())
:ok :ok
end end