Module: RailsSemanticLogging::ActionController::DefaultPayload

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_semantic_logging/action_controller/default_payload.rb

Overview

Concern that enriches controller log payload with standard HTTP request fields. Include in ApplicationController (or a base controller) to automatically add host, user_agent, and referer to every request log line.

These fields are then mapped to Datadog Standard Attributes by the Datadog formatter:

host       -> http.url_details.host
user_agent -> http.useragent
referer    -> http.referer
status     -> http.status_code  (already in Rails payload)
method     -> http.method       (already in Rails payload)
path       -> http.url          (already in Rails payload)

Instance Method Summary collapse

Instance Method Details

#append_info_to_payload(payload) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rails_semantic_logging/action_controller/default_payload.rb', line 18

def append_info_to_payload(payload)
  super
  # Use :full_path because rails_semantic_logger strips query string from :path
  payload[:full_path] = request.fullpath
  payload[:host] = request.host
  payload[:user_agent] = request.user_agent
  payload[:referer] = request.referer if request.referer.present?
end