Skip to content

Commit

Permalink
fix: Change appsignal info method based precense
Browse files Browse the repository at this point in the history
Change appsignal info method based precense
  • Loading branch information
KoenSengers committed Feb 2, 2024
1 parent 116e699 commit ad32a54
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 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
2 changes: 1 addition & 1 deletion appsignal-sourcemap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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"]

Expand Down
16 changes: 16 additions & 0 deletions lib/appsignal/sourcemap/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Appsignal
module Sourcemap
class Base

Check failure on line 6 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L6

Extra empty line detected at class body beginning.
Raw output
  lib/appsignal/sourcemap/base.rb:6:1: Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
private

def log_appsignal(message, type = 'info')

Check failure on line 9 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L9

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Raw output
  lib/appsignal/sourcemap/base.rb:9:41: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
log_method = Appsignal.respond_to?('internal_logger') ? 'internal_logger' : 'logger'

Check failure on line 10 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L10

Use `:internal_logger` instead of `'internal_logger'`.
Raw output
  lib/appsignal/sourcemap/base.rb:10:44: Performance/StringIdentifierArgument: Use `:internal_logger` instead of `'internal_logger'`.

Check failure on line 10 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L10

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Raw output
  lib/appsignal/sourcemap/base.rb:10:44: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 10 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L10

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Raw output
  lib/appsignal/sourcemap/base.rb:10:65: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check failure on line 10 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L10

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Raw output
  lib/appsignal/sourcemap/base.rb:10:85: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Appsignal.send(log_method).send(type, message)
end

Check failure on line 13 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L13

Trailing whitespace detected.
Raw output
  lib/appsignal/sourcemap/base.rb:13:1: Layout/TrailingWhitespace: Trailing whitespace detected.
end
end
end

Check failure on line 16 in lib/appsignal/sourcemap/base.rb

View workflow job for this annotation

GitHub Actions / standardrb

[standardrb] lib/appsignal/sourcemap/base.rb#L16

Final newline missing.
Raw output
  lib/appsignal/sourcemap/base.rb:16:4: Layout/TrailingEmptyLines: Final newline missing.
12 changes: 6 additions & 6 deletions lib/appsignal/sourcemap/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Appsignal
module Sourcemap
class Supervisor
class Supervisor < Base
PARALLEL_THREADS = 10

def self.start
Expand All @@ -15,26 +15,26 @@ def self.start
def start
return if invalid_preconditions

Appsignal.logger.info("Starting sourcemaps upload")
log_appsignal("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")
log_appsignal("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 log_appsignal("Skipping sourcemaps upload since Appsignal config is invalid", "error")
end
if asset_host.blank?
return Appsignal.logger.error("Skipping sourcemaps upload since Rails asset_host is not set")
return log_appsignal("Skipping sourcemaps upload since Rails asset_host is not set", "error")
end
if source_map_paths.empty?
return Appsignal.logger.info("Skipping sourcemaps upload since no javascript maps are found")
return log_appsignal("Skipping sourcemaps upload since no javascript maps are found")
end

false
Expand Down
16 changes: 10 additions & 6 deletions lib/appsignal/sourcemap/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Appsignal
module Sourcemap
class Uploader
class Uploader < Base
UPLOAD_URI = URI("https://appsignal.com/api/sourcemaps")

def self.upload(sourcemap_path)
Expand All @@ -14,28 +14,32 @@ def initialize(sourcemap_path)
end

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

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}'")
log_appsignal("Finished sourcemap upload '#{@sourcemap_path}'", "debug")
File.delete(sourcemap_full_path)
return
end

Appsignal.logger.error <<~MESSAGE
log_appsignal(error_message(response), "error")
end

private

def error_message(response)
<<~MESSAGE
Uploading sourcemap #{@sourcemap_path} failed with message '#{response.message}'.
Response: #{response.body}
MESSAGE
end

private

def sourcemap_full_path
Rails.public_path.join(@sourcemap_path)
end
Expand Down

0 comments on commit ad32a54

Please sign in to comment.