Sha256: 2a03873f215d50b5a826740f572a10842e7be9fa5c0aca9f9c488531f2835f2f

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 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
    # This module contains helper methods related to decorating log messages
    module LocalLogDecorator
      extend self

      def decorate(message)
        return message unless decorating_enabled?

        metadata = NewRelic::Agent.linking_metadata

        if message.is_a?(Hash)
          message.merge!(metadata) unless message.frozen?
          return
        end

        formatted_metadata = " NR-LINKING|#{metadata[ENTITY_GUID_KEY]}|#{metadata[HOSTNAME_KEY]}|" \
                             "#{metadata[TRACE_ID_KEY]}|#{metadata[SPAN_ID_KEY]}|" \
                             "#{escape_entity_name(metadata[ENTITY_NAME_KEY])}|"

        message.partition("\n").insert(1, formatted_metadata).join
      end

      private

      def decorating_enabled?
        NewRelic::Agent.config[:'application_logging.enabled'] &&
          (NewRelic::Agent::Instrumentation::Logger.enabled? ||
            NewRelic::Agent::Instrumentation::LogStasher.enabled?) &&
          NewRelic::Agent.config[:'application_logging.local_decorating.enabled']
      end

      def escape_entity_name(entity_name)
        return unless entity_name

        URI::DEFAULT_PARSER.escape(entity_name)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-9.16.1 lib/new_relic/agent/local_log_decorator.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/local_log_decorator.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/local_log_decorator.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/local_log_decorator.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/local_log_decorator.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/local_log_decorator.rb