lib/ddtrace/tracer.rb in ddtrace-0.42.0 vs lib/ddtrace/tracer.rb in ddtrace-0.43.0
- old
+ new
@@ -5,10 +5,11 @@
require 'ddtrace/environment'
require 'ddtrace/span'
require 'ddtrace/context'
require 'ddtrace/logger'
require 'ddtrace/writer'
+require 'ddtrace/runtime/identity'
require 'ddtrace/sampler'
require 'ddtrace/sampling'
require 'ddtrace/correlation'
# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
@@ -199,10 +200,11 @@
span = Span.new(self, name, span_options)
if parent.nil?
# root span
@sampler.sample!(span)
span.set_tag('system.pid', Process.pid)
+ span.set_tag(Datadog::Ext::Runtime::TAG_ID, Datadog::Runtime::Identity.id)
if ctx && ctx.trace_id
span.trace_id = ctx.trace_id
span.parent_id = ctx.span_id unless ctx.span_id.nil?
end
@@ -285,11 +287,22 @@
# Here we really want to catch *any* exception, not only StandardError,
# as we really have no clue of what is in the block,
# and it is user code which should be executed no matter what.
# It's not a problem since we re-raise it afterwards so for example a
# SignalException::Interrupt would still bubble up.
+ # rubocop:disable Metrics/BlockNesting
rescue Exception => e
- (options[:on_error] || DEFAULT_ON_ERROR).call(span, e)
+ if (on_error_handler = options[:on_error]) && on_error_handler.respond_to?(:call)
+ begin
+ on_error_handler.call(span, e)
+ rescue
+ Datadog.logger.debug('Custom on_error handler failed, falling back to default')
+ DEFAULT_ON_ERROR.call(span, e)
+ end
+ else
+ Datadog.logger.debug('Custom on_error handler must be a callable, falling back to default') if on_error_handler
+ DEFAULT_ON_ERROR.call(span, e)
+ end
raise e
ensure
span.finish unless span.nil?
end