lib/ddtrace/span.rb
# Mark the span finished at the current time and submit it.
Mark the span finished at the current time and submit it.
Mark the span finished at the current time and submit it .
def finish(finish_time = nil)
      return if finished?
      @allocation_count_finish = now_allocations
      now = Time.now.utc
      start(finish_time || now) unless started?
      @end_time = finish_time || now
      @duration_end = finish_time.nil? ? duration_marker : nil
      return self if @tracer.nil? || @context.nil?
      @service ||= (@tracer && @tracer.default_service)
      begin
        @context.close_span(self)
        @tracer.record(self)
      rescue StandardError => e
        Datadog.logger.debug("error recording finished trace: #{e}")
        Datadog.health_metrics.error_span_finish(1, tags: ["error:#{e.class.name}"])
      end
      self
    end
def finish ( finish_time = nil ) return if finished? @allocation_count_finish = now_allocations now = Time . now . utc start ( finish_time || now ) unless started? @end_time = finish_time || now @duration_end = finish_time . nil? ? duration_marker : nil return self if @tracer . nil? || @context . nil? @service ||= ( @tracer && @tracer . default_service ) begin @context . close_span ( self ) @tracer . record ( self ) rescue StandardError => e Datadog . logger . debug ( "error recording finished trace: #{e}" ) Datadog . health_metrics . error_span_finish ( 1 , tags : [ "error:#{e.class.name}" ] ) end self end
Mark the span finished at the current time and submit it.
Mark the span finished at the current time and submit it .
# A span should not be finished twice. Note that this is not thread-safe, # finish is called from multiple threads, a given span might be finished # several times. Again, one should not do this, so this test is more a # fallback to avoid very bad things and protect you in most common cases. # Provide a default start_time if unset. # Using `now` here causes duration to be 0; this is expected # behavior when start_time is unknown. # Finish does not really do anything if the span is not bound to a tracer and a context. # spans without a service would be dropped, so here we provide a default. # This should really never happen with integrations in contrib, as a default # service is always set. It's only for custom instrumentation.
finish_time
<not_specific>