Skip to content

opentelemetry_oban: Add Attribute for Time Spent in QueueΒ #475

@bradschwartz

Description

@bradschwartz

Is your feature request related to a problem? Please describe.

Something I'm interesting in keeping track of is how much time a job has spent waiting in the queue since being scheduled. I would be able to use this as an indicator to know if my workers are taking longer than typical to process jobs.

Describe the solution you'd like

I would just add a new attribute in the handle_job_start function here.

Something like:

diff --git a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex
index 8d14f78..b31a989 100644
--- a/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex
+++ b/instrumentation/opentelemetry_oban/lib/opentelemetry_oban/job_handler.ex
@@ -70,7 +70,8 @@ defmodule OpentelemetryOban.JobHandler do
       :"oban.job.attempt" => attempt,
       :"oban.job.max_attempts" => max_attempts,
       :"oban.job.inserted_at" => DateTime.to_iso8601(inserted_at),
-      :"oban.job.scheduled_at" => DateTime.to_iso8601(scheduled_at)
+      :"oban.job.scheduled_at" => DateTime.to_iso8601(scheduled_at),
+      :"oban.job.queue_time_ms" => DateTime.diff(DateTime.utc_now(), scheduled_at, :millisecond)
     }
 
     span_name = "#{worker} process"

Describe alternatives you've considered
Continue to just calculate and add this attribute by hand manually.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions