Sha256: 3f904c2ff550e13af8e3efa8006f146f0259cb31ce2a52499b247a041a3777d8

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require 'new_relic/agent/instrumentation/notifications_subscriber'

# Listen for ActiveSupport::Notifications events for custom events
module NewRelic::Agent::Instrumentation
  class CustomEventsSubscriber < NotificationsSubscriber
    def start(name, id, _payload) # THREAD_LOCAL_ACCESS
      return unless state.is_execution_traced?

      finishable = NewRelic::Agent::Tracer.start_transaction_or_segment(name: transaction_name(name),
        category: :custom_events)
      push_segment(id, finishable)
    rescue => e
      log_notification_error(e, name, 'start')
    end

    def finish(name, id, payload) # THREAD_LOCAL_ACCESS
      return unless state.is_execution_traced?

      NewRelic::Agent.notice_error(payload[:exception_object]) if payload.key?(:exception_object)

      finishable = pop_segment(id)
      finishable.finish if finishable
    rescue => e
      log_notification_error(e, name, 'finish')
    end

    private

    def transaction_name(name)
      "ActiveSupport/CustomEvents/#{name}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
newrelic_rpm-9.0.0 lib/new_relic/agent/instrumentation/custom_events_subscriber.rb
newrelic_rpm-8.16.0 lib/new_relic/agent/instrumentation/custom_events_subscriber.rb
newrelic_rpm-8.15.0 lib/new_relic/agent/instrumentation/custom_events_subscriber.rb
newrelic_rpm-8.14.0 lib/new_relic/agent/instrumentation/custom_events_subscriber.rb