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.



391
392
393
# File 'lib/datadog/tracing/span_operation.rb', line 391

def initialize(default)
  @handler = default
end

Instance Method Details

#publish(*args) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
# File 'lib/datadog/tracing/span_operation.rb', line 418

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.



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/datadog/tracing/span_operation.rb', line 401

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