Class: Logtail::Integrator

Inherits:
Object
  • Object
show all
Defined in:
lib/logtail/integrator.rb

Overview

Base class for ‘Logtail::Integrations::*`. Provides a common interface for all integrators. An integrator is a single specific integration into a part of a library. See Integration for higher library level integration settings.

Defined Under Namespace

Classes: RequirementNotMetError

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.enabled=(value) ⇒ Object (writeonly)

Sets the attribute enabled

Parameters:

  • value

    the value to set the attribute enabled to.



12
13
14
# File 'lib/logtail/integrator.rb', line 12

def enabled=(value)
  @enabled = value
end

Class Method Details

.enabled?Boolean

Note:

Disabling specific low level integrations should only be needed for edge cases. If you want to disable integration with an entire library, we recommend doing so at a higher level. Ex: ‘Logtail::Integrations::ActiveRecord.enabled = false`.

Allows you to enable / disable specific integrations.

Examples:

Logtail::Integrations::ActiveRecord::LogSubscriber.enabled = false

Returns:

  • (Boolean)


22
23
24
# File 'lib/logtail/integrator.rb', line 22

def enabled?
  @enabled != false
end

.integrate!(*args) ⇒ Object

Convenience class level method that runs the integrator by instantiating a new object and calling #integrate!. It also takes care to look at the if the integrator is enabled, skipping it if not.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/logtail/integrator.rb', line 29

def integrate!(*args)
  if !enabled?
    Config.instance.debug_logger.debug("#{name} integration disabled, skipping") if Config.instance.debug_logger
    return false
  end

  new(*args).integrate!
  Config.instance.debug_logger.debug("Integrated #{name}") if Config.instance.debug_logger
  true
# RequirementUnsatisfiedError is the only silent failure we support
rescue RequirementNotMetError => e
  Config.instance.debug_logger.debug("Failed integrating #{name}: #{e.message}") if Config.instance.debug_logger
  false
end

Instance Method Details

#integrate!Object

Abstract method that each integration must implement.

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/logtail/integrator.rb', line 46

def integrate!
  raise NotImplementedError.new
end