Sha256: f23579cf63b59dde93f80a28017169eb748575353cb63fb15f7cac02afa73c87

Contents?: true

Size: 1.59 KB

Versions: 19

Compression:

Stored size: 1.59 KB

Contents

require "timber/event"
require "timber/util"

module Timber
  module Events
    # The HTTP server request event tracks incoming HTTP requests to your HTTP server.
    # Such as unicorn, webrick, puma, etc.
    #
    # @note This event should be installed automatically through integrations,
    #   such as the {Integrations::ActionController::LogSubscriber} integration.
    class HTTPRequest < Timber::Event
      attr_reader :body, :headers, :host, :method, :path, :port, :query_string, :request_id,
        :scheme, :service_name

      def initialize(attributes)
        @body = attributes[:body] && Util::HTTPEvent.normalize_body(attributes[:body])
        @headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
        @host = attributes[:host]
        @method = Util::HTTPEvent.normalize_method(attributes[:method]) || raise(ArgumentError.new(":method is required"))
        @path = attributes[:path]
        @port = attributes[:port]
        @query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string])
        @scheme = attributes[:scheme]
        @request_id = attributes[:request_id]
      end

      def to_hash
        {body: body, headers: headers, host: host, method: method, path: path, port: port,
          query_string: query_string, request_id: request_id, scheme: scheme}
      end
      alias to_h to_hash

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def as_json(_options = {})
        {:http_request => to_hash}
      end

      def message
        'Started %s "%s"' % [method, path]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
timber-2.4.0 lib/timber/events/http_request.rb
timber-2.3.4 lib/timber/events/http_request.rb
timber-2.3.3 lib/timber/events/http_request.rb
timber-2.3.2 lib/timber/events/http_request.rb
timber-2.3.1 lib/timber/events/http_request.rb
timber-2.3.0 lib/timber/events/http_request.rb
timber-2.2.3 lib/timber/events/http_request.rb
timber-2.2.2 lib/timber/events/http_request.rb
timber-2.2.1 lib/timber/events/http_request.rb
timber-2.2.0 lib/timber/events/http_request.rb
timber-2.1.10 lib/timber/events/http_request.rb
timber-2.1.9 lib/timber/events/http_request.rb
timber-2.1.8 lib/timber/events/http_request.rb
timber-2.1.7 lib/timber/events/http_request.rb
timber-2.1.6 lib/timber/events/http_request.rb
timber-2.1.5 lib/timber/events/http_request.rb
timber-2.1.4 lib/timber/events/http_request.rb
timber-2.1.3 lib/timber/events/http_request.rb
timber-2.1.2 lib/timber/events/http_request.rb