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 ship` family of tasks in the appsignal-agent repository. Modifications to this file will be overwritten with the next agent release.
{ "version" => "0.35.25", "mirrors" => [ "https://appsignal-agent-releases.global.ssl.fastly.net", "https://d135dj0rjqvssy.cloudfront.net" ], "triples" => { "x86_64-darwin" => { "static" => { "checksum" => "f7d6332565a44130bcefb4574d7b81ae90234347ee2bb745f6d4158b7b75c7a7", "filename" => "appsignal-x86_64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "12f654a00d044983253b3b21b4158d964e36cb1f6f24130cf73e0fe4ecc27ca6", "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz" } }, "universal-darwin" => { "static" => { "checksum" => "f7d6332565a44130bcefb4574d7b81ae90234347ee2bb745f6d4158b7b75c7a7", "filename" => "appsignal-x86_64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "12f654a00d044983253b3b21b4158d964e36cb1f6f24130cf73e0fe4ecc27ca6", "filename" => "appsignal-x86_64-darwin-all-dynamic.tar.gz" } }, "aarch64-darwin" => { "static" => { "checksum" => "a5ad691a67a7417dfbacf2ecb0ad31830d0f2ebb9bad1ed640426477bd0c2023", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "eefe5860a0b353c9539e70002096d0080a01e9b95a0ce5c492c1d1f86916e5bc", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "arm64-darwin" => { "static" => { "checksum" => "a5ad691a67a7417dfbacf2ecb0ad31830d0f2ebb9bad1ed640426477bd0c2023", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "eefe5860a0b353c9539e70002096d0080a01e9b95a0ce5c492c1d1f86916e5bc", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "arm-darwin" => { "static" => { "checksum" => "a5ad691a67a7417dfbacf2ecb0ad31830d0f2ebb9bad1ed640426477bd0c2023", "filename" => "appsignal-aarch64-darwin-all-static.tar.gz" }, "dynamic" => { "checksum" => "eefe5860a0b353c9539e70002096d0080a01e9b95a0ce5c492c1d1f86916e5bc", "filename" => "appsignal-aarch64-darwin-all-dynamic.tar.gz" } }, "aarch64-linux" => { "static" => { "checksum" => "fee51c4d0740298a295eaca0cc7bebf9ae05ad03993af7f18501944170492c7b", "filename" => "appsignal-aarch64-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "49d52a9f18f6543d4436a64cea184f37884257a03e95ceb59245e03c672ce377", "filename" => "appsignal-aarch64-linux-all-dynamic.tar.gz" } }, "i686-linux" => { "static" => { "checksum" => "0a84aeb8c57d8a401bd971a6d0adae104ef11a6ab101e4b7f2f0b5b744f3be16", "filename" => "appsignal-i686-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "c16dc7c7ae2b2cf9d54b263eb43717396fd8ed21dc6b0e28f4a15c6adb9c2f90", "filename" => "appsignal-i686-linux-all-dynamic.tar.gz" } }, "x86-linux" => { "static" => { "checksum" => "0a84aeb8c57d8a401bd971a6d0adae104ef11a6ab101e4b7f2f0b5b744f3be16", "filename" => "appsignal-i686-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "c16dc7c7ae2b2cf9d54b263eb43717396fd8ed21dc6b0e28f4a15c6adb9c2f90", "filename" => "appsignal-i686-linux-all-dynamic.tar.gz" } }, "x86_64-linux" => { "static" => { "checksum" => "2c913ea2196ab69aaabf8bafb38a3f156f879b363d9c3245fcd7eb6bc4a6d13e", "filename" => "appsignal-x86_64-linux-all-static.tar.gz" }, "dynamic" => { "checksum" => "d8963880dcc2dc75f3a7a5909f7bc1e259a1f687117e7cc69f5234fd5690e659", "filename" => "appsignal-x86_64-linux-all-dynamic.tar.gz" } }, "x86_64-linux-musl" => { "static" => { "checksum" => "d15a51024585597985f1e0c7b5c5a2ea83e59aacf9bd3acc4f4bbbb00f8e7ee8", "filename" => "appsignal-x86_64-linux-musl-all-static.tar.gz" }, "dynamic" => { "checksum" => "f190d6a79242151434ca2758b32bce9be05b43a0f3dbf7467ffac518751ba54c", "filename" => "appsignal-x86_64-linux-musl-all-dynamic.tar.gz" } }, "aarch64-linux-musl" => { "static" => { "checksum" => "7b1db25a569e9050f4689fc9874719d40f8ef86e960e425cca5bd4a2d40f922d", "filename" => "appsignal-aarch64-linux-musl-all-static.tar.gz" }, "dynamic" => { "checksum" => "5538c5a597de923fe5e60c7bfe626269b3f4f76d769a16dfcd18a060c4c27ee2", "filename" => "appsignal-aarch64-linux-musl-all-dynamic.tar.gz" } }, "x86_64-freebsd" => { "static" => { "checksum" => "31d2e6bdb294c29934e57f6b5c0ce87538bdb3e2639ec1dbda10b013b3655c3e", "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz" }, "dynamic" => { "checksum" => "e68aca29d9538be90a113c015e98b2e02f9a11c41db655c17f1bdf785c88cc20", "filename" => "appsignal-x86_64-freebsd-all-dynamic.tar.gz" } }, "amd64-freebsd" => { "static" => { "checksum" => "31d2e6bdb294c29934e57f6b5c0ce87538bdb3e2639ec1dbda10b013b3655c3e", "filename" => "appsignal-x86_64-freebsd-all-static.tar.gz" }, "dynamic" => { "checksum" => "e68aca29d9538be90a113c015e98b2e02f9a11c41db655c17f1bdf785c88cc20", "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 |