lib/opentelemetry/instrumentation/active_job/patches/base.rb in opentelemetry-instrumentation-active_job-0.6.1 vs lib/opentelemetry/instrumentation/active_job/patches/base.rb in opentelemetry-instrumentation-active_job-0.7.0

- old
+ new

@@ -10,25 +10,36 @@ module Patches # Module to prepend to ActiveJob::Core for context propagation. module Base def self.prepended(base) base.class_eval do - attr_accessor :metadata + attr_accessor :__otel_headers end end - def initialize(*args) - @metadata = {} + def initialize(...) + @__otel_headers = {} super end - ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true) def serialize - super.merge('metadata' => serialize_arguments(metadata)) + message = super + + begin + message.merge!('__otel_headers' => serialize_arguments(@__otel_headers)) + rescue StandardError => e + OpenTelemetry.handle_error(exception: e) + end + + message end def deserialize(job_data) - self.metadata = deserialize_arguments(job_data['metadata'] || []).to_h + begin + @__otel_headers = deserialize_arguments(job_data.delete('__otel_headers') || []).to_h + rescue StandardError => e + OpenTelemetry.handle_error(exception: e) + end super end end end end