Sha256: cad213975fc4d76d6cdac2120509eeb92ff83d6685a35b7815a160db014057a4

Contents?: true

Size: 926 Bytes

Versions: 11

Compression:

Stored size: 926 Bytes

Contents

require "timber/context"
require "timber/util"

module Timber
  module Contexts
    # The session context adds the current session ID to your logs. This allows you
    # to tail and filter logs by specific session IDs. Moreover, it gives you a unique
    # identifier to report on user activity by session. This way your logs can tell the
    # story of how many time a user has engaged your site.
    #
    # @note This is tracked automatically with the {Integrations::Rack::SessionContext} rack
    #   middleware.
    class Session < Context
      @keyspace = :session

      attr_reader :id

      def initialize(attributes)
        @id = attributes[:id] || raise(ArgumentError.new(":id is required"))
      end

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def as_json(_options = {})
        {id: Timber::Util::Object.try(id, :to_s)}
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
timber-2.1.9 lib/timber/contexts/session.rb
timber-2.1.8 lib/timber/contexts/session.rb
timber-2.1.7 lib/timber/contexts/session.rb
timber-2.1.6 lib/timber/contexts/session.rb
timber-2.1.5 lib/timber/contexts/session.rb
timber-2.1.4 lib/timber/contexts/session.rb
timber-2.1.3 lib/timber/contexts/session.rb
timber-2.1.2 lib/timber/contexts/session.rb
timber-2.1.1 lib/timber/contexts/session.rb
timber-2.1.0 lib/timber/contexts/session.rb
timber-2.1.0.rc6 lib/timber/contexts/session.rb