Class: Appsignal::Hooks::OwnershipHook Private

Inherits:
Hook show all
Defined in:
lib/appsignal/hooks/ownership.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Hook

#initialize, #installed?, register, #try_to_install

Constructor Details

This class inherits a constructor from Appsignal::Hooks::Hook

Instance Method Details

#dependencies_present?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/appsignal/hooks/ownership.rb', line 9

def dependencies_present?
  defined?(::Ownership) &&
    Gem::Version.new(::Ownership::VERSION) >= Gem::Version.new("0.2.0") &&
    Appsignal.config &&
    Appsignal.config[:instrument_ownership]
end

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/appsignal/hooks/ownership.rb', line 16

def install
  require "appsignal/integrations/ownership"

  # If a transaction is created in a code context that has an owner,
  # set the namespace of the transaction to the owner.
  Appsignal::Transaction.after_create <<
    Appsignal::Integrations::OwnershipIntegrationHelper.method(:after_create)

  # If an error was reported in a code context that has an owner,
  # set the namespace of the transaction to the owner.
  # In some circumstances, this will be more accurate than the last owner
  # that was set for the transaction, which is what would otherwise be
  # reported.
  Appsignal::Transaction.before_complete <<
    Appsignal::Integrations::OwnershipIntegrationHelper.method(:before_complete)

  # If an owner is set in a code context that has an active transaction,
  # set the namespace of the transaction to the owner.
  unless ::Ownership.singleton_class.included_modules.include?(
    Appsignal::Integrations::OwnershipIntegration
  )
    ::Ownership.singleton_class.prepend Appsignal::Integrations::OwnershipIntegration
  end

  Appsignal::Environment.report_enabled("ownership")
end