From 38bbe0b431d923692ac50c2aeb68866741e067c5 Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Mon, 9 Oct 2023 22:04:02 -0500 Subject: [PATCH] squash: fix --- instrumentation/active_job/README.md | 27 +++++++++++++++++++ .../active_job/handlers/default.rb | 7 ++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/instrumentation/active_job/README.md b/instrumentation/active_job/README.md index 5f0eff8dd2..a145ed66f5 100644 --- a/instrumentation/active_job/README.md +++ b/instrumentation/active_job/README.md @@ -64,6 +64,33 @@ Attributes that are specific to this instrumentation are recorded under `rails.a | `rails.active_job.priority` | Integer | | | `rails.active_job.scheduled_at` | Float | _Subject to be converted to a Span Event_ | +## Differences between ActiveJob versions + +### ActiveJob 6.1 + +`perform.active_job` events do not include timings for `ActiveJob` callbacks therefore time spent in `before` and `after` hooks will be missing + +`ActiveJob::Base#executions` start at `1`. + +### ActiveJob 7+ + +`perform.active_job` no longer includes exceptions handled using `rescue_from` in the payload. + +In order to preseve this behavior you will have to update the span yourself, e.g. + +```ruby + rescue_from MyCustomError do |e| + # Custom code to handle the error + span = OpenTelemetry::Instrumentation::ActiveJob.current_span + span.record_exception(e) + span.status = OpenTelemetry::Trace::Status.error('Job failed') + end +``` + +`ActiveJob::Base#executions` start at `0` instead of `1` as it did in v6.1. + + + ## Examples Example usage can be seen in the `./example/active_job.rb` file [here](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/active_job/example/active_job.rb) diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb index e4a183f974..76cb54ed17 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/handlers/default.rb @@ -12,13 +12,14 @@ module Handlers # This class provides default template methods that derived classes may override to generate spans and register contexts. class Default # @param tracer [OpenTelemetry::Trace::Tracer] to generate spans + # @param parent_span_provider [Object] provides access to the top most parent span (usually the ingress span) # @param mapper [Callable] converts ActiveSupport::Notifications payloads to span attributes # @param config [Hash] of instrumentation options - def initialize(tracer, mapper, config) + def initialize(tracer, parent_span_provider, mapper, config) @tracer = tracer @mapper = mapper @config = config - @ingress_span_provider = OpenTelemetry::Instrumentation::ActiveJob + @parent_span_provider = parent_span_provider end # Invoked by ActiveSupport::Notifications at the start of the instrumentation block @@ -97,9 +98,9 @@ def finish_span(span, tokens) # @param [OpenTelemetry::Trace::Span] the currently active span used to record the exception and set the status def on_exception(exception, span) status = OpenTelemetry::Trace::Status.error(exception.message) - @ingress_span_provider.current_span.status = status span&.record_exception(exception) span&.status = status + @parent_span_provider.current_span.status = status end end end