Class: Rage::Configuration::LogContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/configuration.rb

Direct Known Subclasses

LogTags

Instance Method Summary collapse

Instance Method Details

#<<(hash) ⇒ Object #<<(callable) ⇒ Object Also known as: push

Add a new custom log context object. Each context object is evaluated independently and the results are merged into the final log entry.

Overloads:

  • #<<(hash) ⇒ Object

    Add a static log context entry.

    Examples:

    Rage.configure do
      config.log_context << { version: ENV["APP_VERSION"] }
    end

    Parameters:

    • hash (Hash)

      a hash representing the log context

  • #<<(callable) ⇒ Object
    Note:

    Exceptions from dynamic context callables will cause the entire request to fail. Make sure to handle exceptions inside the callable if necessary.

    Add a dynamic log context entry. Dynamic context entries are executed on every log call to capture dynamic state like changing span IDs during request processing.

    Examples:

    Rage.configure do
      config.log_context << proc { { trace_id: MyObservabilitySDK.trace_id } if MyObservabilitySDK.active? }
    end

    Parameters:

    • callable (#call)

      a callable object that returns a hash representing the log context or nil



243
244
245
246
247
248
249
# File 'lib/rage/configuration.rb', line 243

def <<(block_or_hash)
  validate_input!(block_or_hash)
  @objects << block_or_hash
  @objects.tap(&:flatten!).tap(&:uniq!)

  self
end

#delete(block_or_hash) ⇒ Object

Remove a custom log context object.

Examples:

Rage.configure do
  config.log_context.delete(MyObservabilitySDK::LOG_CONTEXT)
end

Parameters:

  • block_or_hash (Hash, #call)

    the context object to remove



259
260
261
# File 'lib/rage/configuration.rb', line 259

def delete(block_or_hash)
  @objects.delete(block_or_hash)
end