open-telemetry / opentelemetry-erlang-contrib

OpenTelemetry instrumentation for Erlang & Elixir
https://opentelemetry.io
Apache License 2.0
164 stars 115 forks source link

opentelemetry_oban crashes for inline in test #324

Open mdg opened 6 months ago

mdg commented 6 months ago

Describe the bug

Oban defaults to running in :inline mode in the test environment. When it does this, it seems to not actually install the job in the db, so the inserted_at field never gets set. Then handle_job_start runs and it tries to call DateTime.to_iso8601 on nil and gets a failure and the tests fail.

Expected behavior

Primary expectation is that it shouldn't crash. Seems like 3 possible options and from my perspective, any of them would be acceptable.

  1. Make it easier / default / better documented for how to disable opentelemetry_oban in testing config
  2. Default to disabling opentelemetry_oban if running in inline mode
  3. Default "oban.job.inserted_at" to be DateTime.utc_now() if job inserted_at is nil

Additional context

My app-specific fix for this was a version of option 1 which seems to work, but took some investigation and iteration to get to it.

    skipped_telemetry = Application.get_env(:appname, :skipped_telemetry, [])
    if not Enum.any?(skipped_telemetry, &(&1 == OpentelemetryOban)) do
      OpentelemetryOban.setup()
    end