Module: Appsignal::System Private

Defined in:
lib/appsignal/system.rb

Overview

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

System environment detection module.

Provides useful methods to find out more about the host system.

Constant Summary collapse

LINUX_TARGET =

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

"linux"
LINUX_ARM_ARCHITECTURE =

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

"aarch64"
MUSL_TARGET =

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

"linux-musl"
FREEBSD_TARGET =

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

"freebsd"
GEM_EXT_PATH =

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

File.expand_path("../../ext", __dir__).freeze

Class Method Summary collapse

Class Method Details

.agent_architectureString

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.

Detect agent and extension architecture build

Used by the ‘ext/*` tasks to select which architecture build it should download and install.

  • Use ‘export APPSIGNAL_BUILD_FOR_LINUX_ARM=1` to enable the experimental Linux ARM build.

Returns:

  • (String)


68
69
70
71
72
73
# File 'lib/appsignal/system.rb', line 68

def self.agent_architecture
  return LINUX_ARM_ARCHITECTURE if force_linux_arm_build?

  # Fallback on the Ruby
  RbConfig::CONFIG["host_cpu"]
end

.agent_platformString

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.

Detect agent and extension platform build

Used by ‘ext/*` to select which build it should download and install.

  • Use ‘export APPSIGNAL_BUILD_FOR_MUSL=1` if the detection doesn’t work and to force selection of the musl build.

  • Use ‘export APPSIGNAL_BUILD_FOR_LINUX_ARM=1` to enable the experimental Linux ARM build.

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/appsignal/system.rb', line 32

def self.agent_platform
  return LINUX_TARGET if force_linux_arm_build?
  return MUSL_TARGET if force_musl_build?

  host_os = RbConfig::CONFIG["host_os"].downcase
  local_os =
    case host_os
    when /#{LINUX_TARGET}/
      LINUX_TARGET
    when /darwin/
      "darwin"
    when /#{FREEBSD_TARGET}/
      FREEBSD_TARGET
    else
      host_os
    end
  if local_os =~ /linux/
    ldd_output = ldd_version_output
    return MUSL_TARGET if ldd_output.include? "musl"

    ldd_version = extract_ldd_version(ldd_output)
    return MUSL_TARGET if ldd_version && versionify(ldd_version) < versionify("2.15")
  end

  local_os
end

.extract_ldd_version(string) ⇒ Object

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.



100
101
102
103
# File 'lib/appsignal/system.rb', line 100

def self.extract_ldd_version(string)
  ldd_version = string.match(/\d+\.\d+/)
  ldd_version && ldd_version[0]
end

.force_linux_arm_build?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 whether or not the linux ARM build was selected by the user.

Returns:

  • (Boolean)


85
86
87
# File 'lib/appsignal/system.rb', line 85

def self.force_linux_arm_build?
  %w[true 1].include?(ENV.fetch("APPSIGNAL_BUILD_FOR_LINUX_ARM", nil))
end

.force_musl_build?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 whether or not the musl build was forced by the user.

Returns:

  • (Boolean)


78
79
80
# File 'lib/appsignal/system.rb', line 78

def self.force_musl_build?
  %w[true 1].include?(ENV.fetch("APPSIGNAL_BUILD_FOR_MUSL", nil))
end

.heroku?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)


16
17
18
# File 'lib/appsignal/system.rb', line 16

def self.heroku?
  ENV.key? "DYNO"
end

.jruby?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)


105
106
107
# File 'lib/appsignal/system.rb', line 105

def self.jruby?
  RUBY_PLATFORM == "java"
end

.ldd_version_outputObject

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.



95
96
97
# File 'lib/appsignal/system.rb', line 95

def self.ldd_version_output
  `ldd --version 2>&1`
end

.versionify(version) ⇒ Object

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.



90
91
92
# File 'lib/appsignal/system.rb', line 90

def self.versionify(version)
  Gem::Version.new(version)
end