Class: Datadog::Tracing::SpanOperation::Events::OnError

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/span_operation.rb

Overview

Triggered when the span raises an error during measurement.

Instance Method Summary collapse

Constructor Details

#initialize(default) ⇒ OnError

Returns a new instance of OnError.



380
381
382
# File 'lib/datadog/tracing/span_operation.rb', line 380

def initialize(default)
  @handler = default
end

Instance Method Details

#publish(*args) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/datadog/tracing/span_operation.rb', line 407

def publish(*args)
  begin
    @handler.call(*args)
  rescue StandardError => e
    Datadog.logger.debug do
      "Error in on_error handler '#{@default}': #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
    end
  end

  true
end

#wrap_defaultObject

DEV: Revisit this before full 1.0 release. It seems like OnError wants to behave like a middleware stack, where each “subscriber”‘s executed is chained to the previous one. This is different from how Event works, and might be incompatible.



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/datadog/tracing/span_operation.rb', line 390

def wrap_default
  original = @handler

  @handler = proc do |op, error|
    begin
      yield(op, error)
    rescue StandardError => e
      Datadog.logger.debug do
        "Custom on_error handler #{@handler} failed, using fallback behavior. \
        Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
      end

      original.call(op, error) if original
    end
  end
end