Skip to content

Commit

Permalink
fix: Move from appsignal logger to rails logger (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoenSengers committed Feb 2, 2024
1 parent 116e699 commit 39079a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ jobs:
fail-fast: false
matrix:
ruby:
- 3.0
- 3.1
- 3.2
- 3.3

runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion appsignal-sourcemap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Gem::Specification.new do |spec|

spec.metadata["allowed_push_host"] = "https://rubygems.pkg.github.com/Drieam"

spec.required_ruby_version = ">= 2.7"
spec.required_ruby_version = ">= 3.1"

spec.files = Dir["lib/**/*", "README.md"]

spec.add_dependency "rails", ">= 6.1", "< 8.0"
spec.add_dependency "appsignal", "~> 3.0"
spec.add_dependency "parallel", "~> 1.0"

spec.add_development_dependency "standard"
spec.metadata["rubygems_mfa_required"] = "true"
end
12 changes: 5 additions & 7 deletions lib/appsignal/sourcemap/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,25 @@ def self.start
def start
return if invalid_preconditions

Appsignal.logger.info("Starting sourcemaps upload")
Rails.logger.info("Starting sourcemaps upload")

Parallel.each(source_map_paths, in_threads: PARALLEL_THREADS) do |source_map_path|
Uploader.upload(source_map_path)
end

Appsignal.logger.info("Finished sourcemaps upload")
Rails.logger.info("Finished sourcemaps upload")
end

private

def invalid_preconditions
unless Appsignal.config.valid?
return Appsignal.logger.error("Skipping sourcemaps upload since Appsignal config is invalid")
return Rails.logger.error("Skipping sourcemaps upload since Appsignal config is invalid")
end
if asset_host.blank?
return Appsignal.logger.error("Skipping sourcemaps upload since Rails asset_host is not set")
end
if source_map_paths.empty?
return Appsignal.logger.info("Skipping sourcemaps upload since no javascript maps are found")
return Rails.logger.error("Skipping sourcemaps upload since Rails asset_host is not set")
end
return Rails.logger.info("Skipping sourcemaps upload since no javascript maps are found") if source_map_paths.empty?

false
end
Expand Down
10 changes: 4 additions & 6 deletions lib/appsignal/sourcemap/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ def initialize(sourcemap_path)
@sourcemap_path = sourcemap_path
end

def upload # rubocop:disable Metrics/AbcSize
Appsignal.logger.debug "Starting sourcemap upload '#{@sourcemap_path}' with parameters: #{request_form_data}"
def upload
Rails.logger.debug("Starting sourcemap upload '#{@sourcemap_path}' with parameters: #{request_form_data}")

response = Net::HTTP.start(UPLOAD_URI.hostname, UPLOAD_URI.port, use_ssl: true) do |http|
http.request(request)
end

if response.is_a?(Net::HTTPSuccess)
Appsignal.logger.debug("Finished sourcemap upload '#{@sourcemap_path}'")
Rails.logger.debug("Finished sourcemap upload '#{@sourcemap_path}'")
File.delete(sourcemap_full_path)
return
end

Appsignal.logger.error <<~MESSAGE
Rails.logger.error <<~MESSAGE
Uploading sourcemap #{@sourcemap_path} failed with message '#{response.message}'.
Response: #{response.body}
MESSAGE
end

Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/sourcemap/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Appsignal
module Sourcemap
VERSION = "1.0.0.develop"
VERSION = "1.1.1.develop"
end
end

0 comments on commit 39079a7

Please sign in to comment.