Sha256: c9a0855278fc97898fb02f0c2e09f9926b9329c0547653a8c1b7fd766a469c0e

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 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

module NewRelic
  module Agent
    module Instrumentation
      module Logger
        def skip_instrumenting?
          defined?(@skip_instrumenting) && @skip_instrumenting
        end

        # We support setting this on loggers which might not have
        # instrumentation installed yet. This lets us disable in AgentLogger
        # and AuditLogger without them having to know the inner details.
        def self.mark_skip_instrumenting(logger)
          return if logger.frozen?

          logger.instance_variable_set(:@skip_instrumenting, true)
        end

        def self.clear_skip_instrumenting(logger)
          return if logger.frozen?

          logger.instance_variable_set(:@skip_instrumenting, false)
        end

        def mark_skip_instrumenting
          return if frozen?

          @skip_instrumenting = true
        end

        def clear_skip_instrumenting
          return if frozen?

          @skip_instrumenting = false
        end

        def self.enabled?
          NewRelic::Agent.config[:'instrumentation.logger'] != 'disabled'
        end

        def format_message_with_tracing(severity, datetime, progname, msg)
          formatted_message = yield
          return formatted_message if skip_instrumenting?

          begin
            # It's critical we don't instrument logging from metric recording
            # methods within NewRelic::Agent, or we'll stack overflow!!
            mark_skip_instrumenting

            unless ::NewRelic::Agent.agent.nil?
              ::NewRelic::Agent.agent.log_event_aggregator.record(formatted_message, severity)
              formatted_message = LocalLogDecorator.decorate(formatted_message)
            end

            formatted_message
          ensure
            clear_skip_instrumenting
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
newrelic_rpm-9.4.2 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.3.1 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.3.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.2.2 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.2.1 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.2.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.1.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-9.0.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.16.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.15.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.14.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.13.1 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.13.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb
newrelic_rpm-8.12.0 lib/new_relic/agent/instrumentation/logger/instrumentation.rb