Top Level Namespace
Defined Under Namespace
Modules: Appsignal Classes: AppsignalPumaPlugin, Object
Constant Summary collapse
- EXT_PATH =
File.(__dir__).freeze
- AGENT_PLATFORM =
Appsignal::System.agent_platform
- AGENT_ARCHITECTURE =
Appsignal::System.agent_architecture
- TARGET_TRIPLE =
"#{AGENT_ARCHITECTURE}-#{AGENT_PLATFORM}"
- ARCH_CONFIG =
APPSIGNAL_AGENT_CONFIG["triples"][TARGET_TRIPLE].freeze
- CA_CERT_PATH =
File.join(EXT_PATH, "../resources/cacert.pem").freeze
- APPSIGNAL_AGENT_CONFIG =
DO NOT EDIT This is a generated file by the ‘rake publish` family of tasks in the appsignal-agent repository. Modifications to this file will be overwritten with the next agent release.
{ "version" => "0.35.28", "mirrors" => [ "https://d135dj0rjqvssy.cloudfront.net", "https://appsignal-agent-releases.global.ssl.fastly.net" ], "triples" => { "x86_64-darwin" => { "static" => { "checksum" => "8759daae4f842a7dcf370e521de8de9390b3883e09abe8b4f868b6827c855bb3", "filename" => "appsignal-x86_64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "bf65784cd4b082db18f241f02e21472f7356b59c5be1a1ef19788ffdac82e737", "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz" } }, "universal-darwin" => { "static" => { "checksum" => "8759daae4f842a7dcf370e521de8de9390b3883e09abe8b4f868b6827c855bb3", "filename" => "appsignal-x86_64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "bf65784cd4b082db18f241f02e21472f7356b59c5be1a1ef19788ffdac82e737", "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz" } }, "aarch64-darwin" => { "static" => { "checksum" => "247551894b2195bb7e9cc6b52e8a42e10af0723b67f757d3eb84fe34791d0509", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "21941505aed9051c31883e29e3b2de1816ef881ae68dc30cb0fd39104b5fcd4f", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "arm64-darwin" => { "static" => { "checksum" => "247551894b2195bb7e9cc6b52e8a42e10af0723b67f757d3eb84fe34791d0509", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "21941505aed9051c31883e29e3b2de1816ef881ae68dc30cb0fd39104b5fcd4f", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "arm-darwin" => { "static" => { "checksum" => "247551894b2195bb7e9cc6b52e8a42e10af0723b67f757d3eb84fe34791d0509", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "21941505aed9051c31883e29e3b2de1816ef881ae68dc30cb0fd39104b5fcd4f", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "aarch64-linux" => { "static" => { "checksum" => "02d62cfab5ab81faec40db6d80d47e53b2fca640026715697ab43f19539ace34", "filename" => "appsignal-aarch64-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "8b580113f28781063be3538c8097c837ac85c3213c80d2597c00e32786921ef1", "filename" => "appsignal-aarch64-linux-all-dynamic.tar.gz" } }, "i686-linux" => { "static" => { "checksum" => "d5771f360fbb24eb6d39459a910fcbb097904f8459a1735747dde3589c7d710d", "filename" => "appsignal-i686-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "03a066d55a5722802d053f8bdfdbe4bcb4ba9ee72b27d6a39aa62adad037f273", "filename" => "appsignal-i686-linux-all-dynamic.tar.gz" } }, "x86-linux" => { "static" => { "checksum" => "d5771f360fbb24eb6d39459a910fcbb097904f8459a1735747dde3589c7d710d", "filename" => "appsignal-i686-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "03a066d55a5722802d053f8bdfdbe4bcb4ba9ee72b27d6a39aa62adad037f273", "filename" => "appsignal-i686-linux-all-dynamic.tar.gz" } }, "x86_64-linux" => { "static" => { "checksum" => "f3efd7973a0a4b5a0dca7ef23a896a866f011e70d90e2d22cd77c343ffbdf0c1", "filename" => "appsignal-x86_64-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "0900dd8f79838943532db19876018d95065b851eeb5f01c15dfb227bce7a01d8", "filename" => "appsignal-x86_64-linux-all-dynamic.tar.gz" } }, "x86_64-linux-musl" => { "static" => { "checksum" => "9e0cc593389e08527d2e62cc4389711a137511021fd59abd311da8ef5343aee6", "filename" => "appsignal-x86_64-linux-musl-all-static.tar.gz" }, "dynamic" => { "checksum" => "b4420a303780e8733387338dca5a0f7dce03c4e0ec95526ec108bc66f39970ab", "filename" => "appsignal-x86_64-linux-musl-all-dynamic.tar.gz" } }, "aarch64-linux-musl" => { "static" => { "checksum" => "5112c3d0b22f27e6ed108d671ec2903f4cbe084c8d104a05bc946d88ccfed633", "filename" => "appsignal-aarch64-linux-musl-all-static.tar.gz" }, "dynamic" => { "checksum" => "f15aaacdb197b114113c9a382ab371623e49ed0593af8a7d3c7d84aa10b77556", "filename" => "appsignal-aarch64-linux-musl-all-dynamic.tar.gz" } }, "x86_64-freebsd" => { "static" => { "checksum" => "5d87cf82173f95440277b4565a58742c2843f0ddb17bf8f285023c294d1d30ad", "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz" }, "dynamic" => { "checksum" => "9ba8d1c731212b23dccd76f22ad6979da160fe0d688f383acf8126c8922ecbdf", "filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz" } }, "amd64-freebsd" => { "static" => { "checksum" => "5d87cf82173f95440277b4565a58742c2843f0ddb17bf8f285023c294d1d30ad", "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz" }, "dynamic" => { "checksum" => "9ba8d1c731212b23dccd76f22ad6979da160fe0d688f383acf8126c8922ecbdf", "filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz" } } } }.freeze
Instance Method Summary collapse
- #abort_installation(reason) ⇒ Object
- #check_architecture ⇒ Object
- #create_dummy_makefile ⇒ Object
- #download_archive(type) ⇒ Object
- #ext_path(path) ⇒ Object
-
#fail_install_on_purpose_in_test! ⇒ Object
Fail the installation on purpose in a specific test environment.
- #fail_installation_with_error(error) ⇒ Object
-
#have_required_function(library, func) ⇒ Object
rubocop:disable Naming/PredicateName.
- #http_proxy ⇒ Object
- #install ⇒ Object
- #installation_succeeded? ⇒ Boolean
-
#link_libraries ⇒ Object
Ruby 2.6 requires us to statically link more libraries we use in our extension library than previous versions.
- #local_build? ⇒ Boolean
- #report ⇒ Object
- #store_download_version_on_report ⇒ Object
- #successful_installation ⇒ Object
- #try_http_proxy_value(value) ⇒ Object
- #unarchive(archive) ⇒ Object
- #verify_archive(archive, type) ⇒ Object
- #write_report ⇒ Object
Instance Method Details
#abort_installation(reason) ⇒ Object
81 82 83 84 85 86 87 |
# File 'ext/base.rb', line 81 def abort_installation(reason) report["result"] = { "status" => "failed", "message" => reason } false end |
#check_architecture ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'ext/base.rb', line 102 def check_architecture if APPSIGNAL_AGENT_CONFIG["triples"].key?(TARGET_TRIPLE) true else abort_installation( "AppSignal currently does not support your system architecture (#{TARGET_TRIPLE})." \ "Please let us know at support@appsignal.com, we aim to support everything " \ "our customers run." ) end end |
#create_dummy_makefile ⇒ Object
73 74 75 |
# File 'ext/base.rb', line 73 def create_dummy_makefile File.write(File.join(EXT_PATH, "Makefile"), "default:\nclean:\ninstall:") end |
#download_archive(type) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'ext/base.rb', line 114 def download_archive(type) report["build"]["source"] = "remote" unless ARCH_CONFIG.key?(type) abort_installation( "AppSignal currently does not support your system. " \ "Expected config for architecture '#{TARGET_TRIPLE}' and package type '#{type}', " \ "but none found. For a full list of supported systems visit: " \ "https://docs.appsignal.com/support/operating-systems.html" ) return end version = APPSIGNAL_AGENT_CONFIG["version"] filename = ARCH_CONFIG[type]["filename"] download_errors = [] APPSIGNAL_AGENT_CONFIG["mirrors"].each do |mirror| download_url = [mirror, version, filename].join("/") report["download"]["download_url"] = download_url begin proxy, _error = http_proxy args = [ download_url, { :ssl_ca_cert => CA_CERT_PATH, :proxy => proxy } ] if URI.respond_to?(:open) # rubocop:disable Style/GuardClause return URI.open(*args) else return open(*args) end rescue => error download_errors << "- URL: #{download_url}\n Error: #{error.class}: #{error.}" next end end abort_installation( "Could not download archive from any of our mirrors. " \ "Please make sure your network allows access to any of these mirrors.\n" \ "Attempted to download the archive from the following urls:\n#{download_errors.join("\n")}" ) end |
#ext_path(path) ⇒ Object
21 22 23 |
# File 'ext/base.rb', line 21 def ext_path(path) File.join(EXT_PATH, path) end |
#fail_install_on_purpose_in_test! ⇒ Object
Fail the installation on purpose in a specific test environment.
222 223 224 225 226 |
# File 'ext/base.rb', line 222 def fail_install_on_purpose_in_test! return unless ENV["_TEST_APPSIGNAL_EXTENSION_FAILURE"] raise "AppSignal internal test failure" end |
#fail_installation_with_error(error) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'ext/base.rb', line 89 def fail_installation_with_error(error) report["result"] = { "status" => "error", "error" => "#{error.class}: #{error}", "backtrace" => error.backtrace } false end |
#have_required_function(library, func) ⇒ Object
rubocop:disable Naming/PredicateName
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/extconf.rb', line 80 def have_required_function(library, func) # rubocop:disable Naming/PredicateName if have_func(func) report["build"]["dependencies"][library] = "linked" return end report["build"]["dependencies"][library] = "not linked" abort_installation("Missing function '#{func}'") # Exit with true/0/success because the AppSignal installation should never # break a build exit end |
#http_proxy ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'ext/base.rb', line 192 def http_proxy proxy = try_http_proxy_value(ENV.fetch("APPSIGNAL_HTTP_PROXY", nil)) return [proxy, nil] if proxy proxy, error = begin [try_http_proxy_value(Gem.configuration[:http_proxy]), nil] rescue => error # Ignore this setting if the `.gemrc` file can't be read. This raises an # error on Rubies with psych 4 in the standard library, but also have # psych 5 installed: Ruby < 3.2. # https://github.com/appsignal/appsignal-ruby/issues/904 [nil, error] end return [proxy, error] if proxy proxy = try_http_proxy_value(ENV.fetch("http_proxy", nil)) return [proxy, error] if proxy proxy = try_http_proxy_value(ENV.fetch("HTTP_PROXY", nil)) return [proxy, error] if proxy [nil, error] end |
#install ⇒ Object
11 12 13 14 15 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/extconf.rb', line 11 def install fail_install_on_purpose_in_test! library_type = "static" report["language"]["implementation"] = "ruby" report["build"]["library_type"] = library_type return unless check_architecture if local_build? report["build"]["source"] = "local" else archive = download_archive(library_type) return unless archive return unless verify_archive(archive, library_type) unarchive(archive) end is_linux_system = [ Appsignal::System::LINUX_TARGET, Appsignal::System::MUSL_TARGET ].include?(AGENT_PLATFORM) require "mkmf" link_libraries if is_linux_system if !have_library("appsignal", "appsignal_start", "appsignal.h") abort_installation("Library libappsignal.a or appsignal.h not found") elsif !find_executable("appsignal-agent", EXT_PATH) abort_installation("File appsignal-agent not found") else if is_linux_system # Statically link libgcc and libgcc_s libraries. # Dependencies of the libappsignal extension library. # If the gem is installed on a host with build tools installed, but is # run on one that isn't the missing libraries will cause the extension # to fail on start. $LDFLAGS += " -static-libgcc" # rubocop:disable Style/GlobalVars report["build"]["flags"]["LDFLAGS"] = $LDFLAGS # rubocop:disable Style/GlobalVars end create_makefile "appsignal_extension" successful_installation end rescue => error fail_installation_with_error(error) ensure create_dummy_makefile unless installation_succeeded? write_report end |
#installation_succeeded? ⇒ Boolean
98 99 100 |
# File 'ext/base.rb', line 98 def installation_succeeded? report["result"]["status"] == "success" end |
#link_libraries ⇒ Object
Ruby 2.6 requires us to statically link more libraries we use in our extension library than previous versions. Needed for normal Linux libc and musl builds.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/extconf.rb', line 64 def link_libraries if RbConfig::CONFIG["THREAD_MODEL"] == "pthread" # Link gem extension against pthread library have_library "pthread" have_required_function "pthread", "pthread_create" end # Links gem extension against the `dl` library. This is needed when Ruby is # not linked against `dl` itself, so link it on the gem extension. have_library "dl" # Check if functions are available now from the linked library %w[dlopen dlclose dlsym].each do |func| have_required_function "dl", func end end |
#local_build? ⇒ Boolean
5 6 7 8 9 |
# File 'ext/extconf.rb', line 5 def local_build? File.exist?(ext_path("appsignal-agent")) && File.exist?(ext_path("libappsignal.a")) && File.exist?(ext_path("appsignal.h")) end |
#report ⇒ Object
25 26 27 28 29 30 31 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 58 59 60 61 62 63 64 65 66 67 |
# File 'ext/base.rb', line 25 def report @report ||= begin rbconfig = RbConfig::CONFIG patchlevel = rbconfig["PATCHLEVEL"] patchlevel_label = "-p#{patchlevel}" if patchlevel ruby_version = "#{RUBY_VERSION}#{patchlevel_label}" { "result" => { "status" => "incomplete" }, "language" => { "name" => "ruby", "version" => ruby_version }, "download" => { "checksum" => "unverified" }, "build" => { "time" => Time.now.utc, "package_path" => File.dirname(EXT_PATH), "architecture" => AGENT_ARCHITECTURE, "target" => AGENT_PLATFORM, "musl_override" => Appsignal::System.force_musl_build?, "linux_arm_override" => Appsignal::System.force_linux_arm_build?, "dependencies" => {}, "flags" => {} }, "host" => { "root_user" => Process.uid.zero?, "dependencies" => {}.tap do |d| ldd_output = Appsignal::System.ldd_version_output ldd_version = Appsignal::System.extract_ldd_version(ldd_output) d["libc"] = ldd_version if ldd_version end } }.tap do |r| proxy, error = http_proxy r["download"]["http_proxy"] = proxy r["download"]["http_proxy_error"] = error if error end end end |
#store_download_version_on_report ⇒ Object
187 188 189 190 |
# File 'ext/base.rb', line 187 def store_download_version_on_report path = File.(File.join(File.dirname(__FILE__), "appsignal.version")) report["build"]["agent_version"] = File.read(path).strip end |
#successful_installation ⇒ Object
77 78 79 |
# File 'ext/base.rb', line 77 def successful_installation report["result"] = { "status" => "success" } end |
#try_http_proxy_value(value) ⇒ Object
217 218 219 |
# File 'ext/base.rb', line 217 def try_http_proxy_value(value) value if value.respond_to?(:empty?) && !value.strip.empty? end |
#unarchive(archive) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 |
# File 'ext/base.rb', line 175 def unarchive(archive) Gem::Package::TarReader.new(Zlib::GzipReader.open(archive)) do |tar| tar.each do |entry| next unless entry.file? File.binwrite(ext_path(entry.full_name), entry.read) end end store_download_version_on_report FileUtils.chmod(0o755, ext_path("appsignal-agent")) end |
#verify_archive(archive, type) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/base.rb', line 160 def verify_archive(archive, type) expected_checksum = ARCH_CONFIG[type]["checksum"] actual_checksum = Digest::SHA256.hexdigest(archive.read) if actual_checksum == expected_checksum report["download"]["checksum"] = "verified" true else report["download"]["checksum"] = "invalid" abort_installation( "Checksum of downloaded archive could not be verified: " \ "Expected '#{expected_checksum}', got '#{actual_checksum}'." ) end end |