diff --git a/.changesets/remove-deprecated-components.md b/.changesets/remove-deprecated-components.md new file mode 100644 index 000000000..d0cadc805 --- /dev/null +++ b/.changesets/remove-deprecated-components.md @@ -0,0 +1,6 @@ +--- +bump: major +type: remove +--- + +Remove all deprecated components. Please follow [our Ruby gem 4 upgrade guide](https://docs.appsignal.com/ruby/installation/upgrade-from-3-to-4.html) when upgrading to this version to avoid any errors from calling removed components, methods and helpers. diff --git a/benchmark.rake b/benchmark.rake index 1a7c08164..18d86bf02 100644 --- a/benchmark.rake +++ b/benchmark.rake @@ -58,11 +58,9 @@ namespace :benchmark do end def start_agent - Appsignal.config = Appsignal::Config.new( - Dir.pwd, - "production", - :endpoint => "http://localhost:8080" - ) + Appsignal.configure(:production) do |config| + config.endpoint = "http://localhost:8080" + end Appsignal.start end diff --git a/lib/appsignal.rb b/lib/appsignal.rb index c10913099..4897c4412 100644 --- a/lib/appsignal.rb +++ b/lib/appsignal.rb @@ -36,21 +36,6 @@ class << self # @see Config attr_reader :config - # Set the AppSignal config. - # - # @deprecated Use {Appsignal.configure} instead. - # @param conf [Appsignal::Config] - # @return [void] - # @see Config - def config=(conf) - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "Configuring AppSignal with `Appsignal.config=` is deprecated. " \ - "Use `Appsignal.configure { |config| ... }` to configure AppSignal. " \ - "https://docs.appsignal.com/ruby/configuration.html\n" \ - "#{caller.first}" - @config = conf - end - # @api private def _config=(conf) @config = conf @@ -333,18 +318,6 @@ def log_formatter(prefix = nil) end end - # @deprecated Only {.start} has to be called. - # @return [void] - # @since 0.7.0 - def start_logger - callers = caller - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "Calling 'Appsignal.start_logger' is deprecated. " \ - "The logger will be started when calling 'Appsignal.start'. " \ - "Remove the 'Appsignal.start_logger' call in the following file to " \ - "remove this message.\n#{callers.first}" - end - # Start the AppSignal internal logger. # # Sets the log level and sets the logger. Uses a file-based logger or the @@ -448,22 +421,6 @@ def collect_environment_metadata end Appsignal::Environment.report_supported_gems end - - # Alias constants that have moved with a warning message that points to the - # place to update the reference. - def const_missing(name) - case name - when :Minutely - callers = caller - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The constant Appsignal::Minutely has been deprecated. " \ - "Please update the constant name to Appsignal::Probes " \ - "in the following file to remove this message.\n#{callers.first}" - Appsignal::Probes - else - super - end - end end end diff --git a/lib/appsignal/config.rb b/lib/appsignal/config.rb index 66eddddf7..839e436ed 100644 --- a/lib/appsignal/config.rb +++ b/lib/appsignal/config.rb @@ -8,8 +8,6 @@ module Appsignal class Config - include Appsignal::Utils::StdoutAndLoggerMessage - # @api private def self.loader_defaults @loader_defaults ||= [] @@ -24,7 +22,6 @@ def self.add_loader_defaults(name, options) DEFAULT_CONFIG = { :activejob_report_errors => "all", :ca_file_path => File.expand_path(File.join("../../../resources/cacert.pem"), __FILE__), - :debug => false, :dns_servers => [], :enable_allocation_tracking => true, :enable_host_metrics => true, @@ -59,8 +56,8 @@ def self.add_loader_defaults(name, options) ], :send_environment_metadata => true, :send_params => true, - :sidekiq_report_errors => "all", - :transaction_debug_mode => false + :send_session_data => true, + :sidekiq_report_errors => "all" }.freeze # @api private @@ -96,13 +93,11 @@ def self.add_loader_defaults(name, options) "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => :sidekiq_report_errors, "APPSIGNAL_STATSD_PORT" => :statsd_port, "APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path, - "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path, "APP_REVISION" => :revision }.freeze # @api private ENV_BOOLEAN_KEYS = { "APPSIGNAL_ACTIVE" => :active, - "APPSIGNAL_DEBUG" => :debug, "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking, "APPSIGNAL_ENABLE_HOST_METRICS" => :enable_host_metrics, "APPSIGNAL_ENABLE_MINUTELY_PROBES" => :enable_minutely_probes, @@ -121,9 +116,7 @@ def self.add_loader_defaults(name, options) "APPSIGNAL_RUNNING_IN_CONTAINER" => :running_in_container, "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => :send_environment_metadata, "APPSIGNAL_SEND_PARAMS" => :send_params, - "APPSIGNAL_SEND_SESSION_DATA" => :send_session_data, - "APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data, - "APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode + "APPSIGNAL_SEND_SESSION_DATA" => :send_session_data }.freeze # @api private ENV_ARRAY_KEYS = { @@ -274,9 +267,6 @@ def load_config # Load config overrides @override_config = determine_overrides merge(override_config) - - # Handle deprecated config options - maintain_backwards_compatibility end # @api private @@ -306,12 +296,12 @@ def []=(key, value) # @api private def log_level - level = ::Logger::DEBUG if config_hash[:debug] || config_hash[:transaction_debug_mode] option = config_hash[:log_level] - if option - log_level_option = LOG_LEVEL_MAP[option] - level = log_level_option if log_level_option - end + level = + if option + log_level_option = LOG_LEVEL_MAP[option] + log_level_option + end level.nil? ? Appsignal::Config::DEFAULT_LOG_LEVEL : level end @@ -359,7 +349,6 @@ def write_to_environment # rubocop:disable Metrics/AbcSize ENV["_APPSIGNAL_BIND_ADDRESS"] = config_hash[:bind_address].to_s ENV["_APPSIGNAL_CA_FILE_PATH"] = config_hash[:ca_file_path].to_s ENV["_APPSIGNAL_CPU_COUNT"] = config_hash[:cpu_count].to_s - ENV["_APPSIGNAL_DEBUG_LOGGING"] = config_hash[:debug].to_s ENV["_APPSIGNAL_DNS_SERVERS"] = config_hash[:dns_servers].join(",") ENV["_APPSIGNAL_ENABLE_HOST_METRICS"] = config_hash[:enable_host_metrics].to_s ENV["_APPSIGNAL_ENABLE_STATSD"] = config_hash[:enable_statsd].to_s @@ -386,13 +375,9 @@ def write_to_environment # rubocop:disable Metrics/AbcSize ENV["_APPSIGNAL_RUNNING_IN_CONTAINER"] = config_hash[:running_in_container].to_s ENV["_APPSIGNAL_SEND_ENVIRONMENT_METADATA"] = config_hash[:send_environment_metadata].to_s ENV["_APPSIGNAL_STATSD_PORT"] = config_hash[:statsd_port].to_s - ENV["_APPSIGNAL_TRANSACTION_DEBUG_MODE"] = config_hash[:transaction_debug_mode].to_s if config_hash[:working_directory_path] ENV["_APPSIGNAL_WORKING_DIRECTORY_PATH"] = config_hash[:working_directory_path] end - if config_hash[:working_dir_path] - ENV["_APPSIGNAL_WORKING_DIR_PATH"] = config_hash[:working_dir_path] - end ENV["_APP_REVISION"] = config_hash[:revision].to_s end @@ -476,27 +461,6 @@ def load_from_disk nil end - # Maintain backwards compatibility with deprecated config options. - # - # Add warnings for deprecated config options here if they have no - # replacement, or should be non-functional. - # - # Add them to {determine_overrides} if replacement config options should be - # set instead. - # - # Make sure to remove the contents of this method in the next major - # version, but the method itself with an empty body can stick around as a - # structure for future deprecations. - def maintain_backwards_compatibility - return unless config_hash.key?(:working_dir_path) - - stdout_and_logger_warning \ - "The `working_dir_path` option is deprecated, please use " \ - "`working_directory_path` instead and specify the " \ - "full path to the working directory", - logger - end - def load_from_environment config = {} @@ -536,11 +500,7 @@ def load_from_environment end # Set config options based on the final user config. Fix any conflicting - # config or set new config options based on deprecated config options. - # - # Make sure to remove behavior for deprecated config options in this method - # in the next major version, but the method itself with an empty body can - # stick around as a structure for future deprecations. + # config. def determine_overrides config = {} # If an error was detected during config file reading/parsing and the new @@ -549,19 +509,6 @@ def determine_overrides # TODO: Make default behavior in next major version. Remove # `inactive_on_config_file_error?` call. config[:active] = false if @config_file_error && inactive_on_config_file_error? - skip_session_data = config_hash[:skip_session_data] - send_session_data = config_hash[:send_session_data] - if skip_session_data.nil? # Deprecated option is not set - if send_session_data.nil? # Not configured by user - config[:send_session_data] = true # Set default value - end - else - stdout_and_logger_warning "The `skip_session_data` config option is " \ - "deprecated. Please use `send_session_data` instead.", - logger - # Not configured by user - config[:send_session_data] = !skip_session_data if send_session_data.nil? - end if config_hash[:activejob_report_errors] == "discard" && !Appsignal::Hooks::ActiveJobHook.version_7_1_or_higher? diff --git a/lib/appsignal/helpers/instrumentation.rb b/lib/appsignal/helpers/instrumentation.rb index f914f4e91..53d49cdbf 100644 --- a/lib/appsignal/helpers/instrumentation.rb +++ b/lib/appsignal/helpers/instrumentation.rb @@ -3,8 +3,6 @@ module Appsignal module Helpers module Instrumentation - include Appsignal::Utils::StdoutAndLoggerMessage - # Monitor a block of code with AppSignal. # # This is a helper to create an AppSignal transaction, track any errors @@ -160,124 +158,6 @@ def monitor_and_stop(action:, namespace: nil) Appsignal.stop("monitor_and_stop") end - # Creates an AppSignal transaction for the given block. - # - # If AppSignal is not {Appsignal.active?} it will still execute the - # block, but not create a transaction for it. - # - # A event is created for this transaction with the name given in the - # `name` argument. The event name must start with either `perform_job` or - # `process_action` to differentiate between the "web" and "background" - # namespace. Custom namespaces are not supported by this helper method. - # - # This helper method also captures any exception that occurs in the given - # block. - # - # @example - # Appsignal.monitor_transaction("perform_job.nightly_update") do - # # your code - # end - # - # @example with an environment - # Appsignal.monitor_transaction( - # "perform_job.nightly_update", - # :metadata => { "user_id" => 1 } - # ) do - # # your code - # end - # - # @param name [String] main event name. - # @param env [Hash] - # @option env [Hash] :params Params for the - # monitored request/job, see {Appsignal::Transaction#params=} for more - # information. - # @option env [String] :controller name of the controller in which the - # transaction was recorded. - # @option env [String] :class name of the Ruby class in which the - # transaction was recorded. If `:controller` is also given, - # `:controller` is used instead. - # @option env [String] :action name of the controller action in which the - # transaction was recorded. - # @option env [String] :method name of the Ruby method in which the - # transaction was recorded. If `:action` is also given, `:action` - # is used instead. - # @option env [Integer] :queue_start the moment the request/job was - # queued. Used to track how long requests/jobs were queued before being - # executed. - # @option env [Hash] :metadata Additional - # metadata for the transaction, see - # {Appsignal::Transaction#set_metadata} for more information. - # @yield the block to monitor. - # @raise [Exception] any exception that occurs within the given block is - # re-raised by this method. - # @return [Object] the value of the given block is returned. - # @since 0.10.0 - def monitor_transaction(name, env = {}, &block) - stdout_and_logger_warning \ - "The `Appsignal.monitor_transaction` helper is deprecated. " \ - "Please use `Appsignal.monitor` and `Appsignal.instrument` instead. " \ - "Read our instrumentation documentation: " \ - "https://docs.appsignal.com/ruby/instrumentation/instrumentation.html" - _monitor_transaction(name, env, &block) - end - - # @api private - def _monitor_transaction(name, env = {}, &block) - # Always verify input, even when Appsignal is not active. - # This makes it more likely invalid arguments get flagged in test/dev - # environments. - if name.start_with?("perform_job") - namespace = Appsignal::Transaction::BACKGROUND_JOB - request = Appsignal::Transaction::InternalGenericRequest.new(env) - elsif name.start_with?("process_action") - namespace = Appsignal::Transaction::HTTP_REQUEST - request = ::Rack::Request.new(env) - else - internal_logger.error "Unrecognized name '#{name}': names must " \ - "start with either 'perform_job' (for jobs and tasks) or " \ - "'process_action' (for HTTP requests)" - return yield - end - - return yield unless active? - - transaction = Appsignal::Transaction.create( - SecureRandom.uuid, - namespace, - request - ) - begin - Appsignal.instrument(name, &block) - rescue Exception => error # rubocop:disable Lint/RescueException - transaction.set_error(error) - raise error - ensure - transaction.set_http_or_background_action(request.env) - queue_start = Appsignal::Rack::Utils.queue_start_from(request.env) || - (env[:queue_start]&.to_i&.* 1_000) - transaction.set_queue_start(queue_start) if queue_start - Appsignal::Transaction.complete_current! - end - end - - # Monitor a transaction, stop AppSignal and wait for this single - # transaction to be flushed. - # - # Useful for cases such as Rake tasks and Resque-like systems where a - # process is forked and immediately exits after the transaction finishes. - # - # @see monitor_transaction - def monitor_single_transaction(name, env = {}, &block) - stdout_and_logger_warning \ - "The `Appsignal.monitor_single_transaction` helper is deprecated. " \ - "Please use `Appsignal.monitor_and_stop` and `Appsignal.instrument` instead. " \ - "Read our instrumentation documentation: " \ - "https://docs.appsignal.com/ruby/instrumentation/instrumentation.html" - monitor_transaction(name, env, &block) - ensure - stop("monitor_single_transaction") - end - # Listen for an error to occur and send it to AppSignal. # # Uses {.send_error} to directly send the error in a separate @@ -339,13 +219,6 @@ def listen_for_error( # Appsignal.send_error(e) # end # - # @example Send an exception with tags. Deprecated method. - # begin - # raise "oh no!" - # rescue => e - # Appsignal.send_error(e, :key => "value") - # end - # # @example Add more metadata to transaction # Appsignal.send_error(e) do |transaction| # transaction.set_params(:search_query => params[:search_query]) @@ -355,12 +228,6 @@ def listen_for_error( # end # # @param error [Exception] The error to send to AppSignal. - # @param tags [Hash{String, Symbol => String, Symbol, Integer}] - # Additional tags to add to the error. See also {.tag_request}. - # This parameter is deprecated. Use the block argument instead. - # @param namespace [String] The namespace in which the error occurred. - # See also {.set_namespace}. - # This parameter is deprecated. Use the block argument instead. # @yield [transaction] yields block to allow modification of the # transaction before it's send. # @yieldparam transaction [Transaction] yields the AppSignal transaction @@ -373,31 +240,7 @@ def listen_for_error( # @see https://docs.appsignal.com/ruby/instrumentation/tagging.html # Tagging guide # @since 0.6.0 - def send_error( - error, - tags = nil, - namespace = nil - ) - if tags - call_location = caller(1..1).first - stdout_and_logger_warning \ - "The tags argument for `Appsignal.send_error` is deprecated. " \ - "Please use the block method to set tags instead.\n\n" \ - " Appsignal.send_error(error) do |transaction|\n" \ - " transaction.set_tags(#{tags})\n" \ - " end\n\n" \ - "Appsignal.send_error called on location: #{call_location}" - end - if namespace - call_location = caller(1..1).first - stdout_and_logger_warning \ - "The namespace argument for `Appsignal.send_error` is deprecated. " \ - "Please use the block method to set the namespace instead.\n\n" \ - " Appsignal.send_error(error) do |transaction|\n" \ - " transaction.set_namespace(#{namespace.inspect})\n" \ - " end\n\n" \ - "Appsignal.send_error called on location: #{call_location}" - end + def send_error(error) return unless active? unless error.is_a?(Exception) @@ -407,9 +250,8 @@ def send_error( end transaction = Appsignal::Transaction.new( SecureRandom.uuid, - namespace || Appsignal::Transaction::HTTP_REQUEST + Appsignal::Transaction::HTTP_REQUEST ) - transaction.set_tags(tags) if tags transaction.set_error(error) yield transaction if block_given? transaction.complete @@ -453,12 +295,6 @@ def send_error( # # @param exception [Exception] The error to add to the current # transaction. - # @param tags [Hash{String, Symbol => String, Symbol, Integer}] - # Additional tags to add to the error. See also {.tag_request}. - # This parameter is deprecated. Use the block argument instead. - # @param namespace [String] The namespace in which the error occurred. - # See also {.set_namespace}. - # This parameter is deprecated. Use the block argument instead. # @yield [transaction] yields block to allow modification of the # transaction. # @yieldparam transaction [Transaction] yields the AppSignal transaction @@ -470,27 +306,7 @@ def send_error( # @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html # Exception handling guide # @since 0.6.6 - def set_error(exception, tags = nil, namespace = nil) - if tags - call_location = caller(1..1).first - stdout_and_logger_warning \ - "The tags argument for `Appsignal.set_error` is deprecated. " \ - "Please use the block method to set tags instead.\n\n" \ - " Appsignal.set_error(error) do |transaction|\n" \ - " transaction.set_tags(#{tags})\n" \ - " end\n\n" \ - "Appsignal.set_error called on location: #{call_location}" - end - if namespace - call_location = caller(1..1).first - stdout_and_logger_warning \ - "The namespace argument for `Appsignal.set_error` is deprecated. " \ - "Please use the block method to set the namespace instead.\n\n" \ - " Appsignal.set_error(error) do |transaction|\n" \ - " transaction.set_namespace(#{namespace.inspect})\n" \ - " end\n\n" \ - "Appsignal.set_error called on location: #{call_location}" - end + def set_error(exception) unless exception.is_a?(Exception) internal_logger.error "Appsignal.set_error: Cannot set error. " \ "The given value is not an exception: #{exception.inspect}" @@ -500,8 +316,6 @@ def set_error(exception, tags = nil, namespace = nil) transaction = Appsignal::Transaction.current transaction.set_error(exception) - transaction.set_tags(tags) if tags - transaction.set_namespace(namespace) if namespace yield transaction if block_given? end alias :set_exception :set_error @@ -1068,15 +882,6 @@ def ignore_instrumentation_events ensure Appsignal::Transaction.current&.resume! end - - # @deprecated Use {.ignore_instrumentation_events} instead. - # @since 0.8.7 - def without_instrumentation(&block) - stdout_and_logger_warning \ - "The `Appsignal.without_instrumentation` helper is deprecated. " \ - "Please use `Appsignal.ignore_instrumentation_events` instead." - ignore_instrumentation_events(&block) - end end end end diff --git a/lib/appsignal/helpers/metrics.rb b/lib/appsignal/helpers/metrics.rb index 605a8edc9..11ce9cd59 100644 --- a/lib/appsignal/helpers/metrics.rb +++ b/lib/appsignal/helpers/metrics.rb @@ -14,22 +14,6 @@ def set_gauge(key, value, tags = {}) .warn("Gauge value #{value} for key '#{key}' is too big") end - def set_host_gauge(_key, _value) - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The `set_host_gauge` method has been deprecated. " \ - "Calling this method has no effect. " \ - "Please remove method call in the following file to remove " \ - "this message.\n#{caller.first}" - end - - def set_process_gauge(_key, _value) - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The `set_process_gauge` method has been deprecated. " \ - "Calling this method has no effect. " \ - "Please remove method call in the following file to remove " \ - "this message.\n#{caller.first}" - end - def increment_counter(key, value = 1.0, tags = {}) Appsignal::Extension.increment_counter( key.to_s, diff --git a/lib/appsignal/hooks.rb b/lib/appsignal/hooks.rb index 2df2c0a04..e7c39aa69 100644 --- a/lib/appsignal/hooks.rb +++ b/lib/appsignal/hooks.rb @@ -69,22 +69,6 @@ def truncate(text) text.size > 200 ? "#{text[0...197]}..." : text end end - - # Alias integration constants that have moved to their own module. - def self.const_missing(name) - case name - when :SidekiqPlugin - require "appsignal/integrations/sidekiq" - callers = caller - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The constant Appsignal::Hooks::SidekiqPlugin has been deprecated. " \ - "Please update the constant name to Appsignal::Integrations::SidekiqMiddleware " \ - "in the following file to remove this message.\n#{callers.first}" - Appsignal::Integrations::SidekiqMiddleware - else - super - end - end end end diff --git a/lib/appsignal/integrations/grape.rb b/lib/appsignal/integrations/grape.rb deleted file mode 100644 index 785903ac3..000000000 --- a/lib/appsignal/integrations/grape.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "appsignal" -require "appsignal/rack/grape_middleware" - -Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The 'require \"appsignal/integrations/grape\"' file require integration " \ - "method is deprecated. " \ - "Please follow the Grape setup guide in our docs for the new method: " \ - "https://docs.appsignal.com/ruby/integrations/grape.html" -) - -Appsignal.internal_logger.debug("Loading Grape integration") - -module Appsignal - # @api private - module Grape - # Alias constants that have moved with a warning message that points to the - # place to update the reference. - def self.const_missing(name) - case name - when :Middleware - callers = caller - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The constant Appsignal::Grape::Middleware has been deprecated. " \ - "Please update the constant name to " \ - "Appsignal::Rack::GrapeMiddleware in the following file to " \ - "remove this message.\n#{callers.first}" - Appsignal::Rack::GrapeMiddleware - else - super - end - end - end -end diff --git a/lib/appsignal/integrations/hanami.rb b/lib/appsignal/integrations/hanami.rb deleted file mode 100644 index 459269a16..000000000 --- a/lib/appsignal/integrations/hanami.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "appsignal" - -Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The 'require \"appsignal/integrations/hanami\"' file require integration " \ - "method is deprecated. " \ - "Please follow the Hanami setup guide in our docs for the new method: " \ - "https://docs.appsignal.com/ruby/integrations/hanami.html" -) - -Appsignal.load(:hanami) -Appsignal.start diff --git a/lib/appsignal/integrations/padrino.rb b/lib/appsignal/integrations/padrino.rb deleted file mode 100644 index ca91fba0a..000000000 --- a/lib/appsignal/integrations/padrino.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "appsignal" - -Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The 'require \"appsignal/integrations/padrino\"' file require integration " \ - "method is deprecated. " \ - "Please follow the Padrino setup guide in our docs for the new method: " \ - "https://docs.appsignal.com/ruby/integrations/padrino.html" -) - -Appsignal.load(:padrino) -Appsignal.start diff --git a/lib/appsignal/integrations/sinatra.rb b/lib/appsignal/integrations/sinatra.rb deleted file mode 100644 index b28e7db9a..000000000 --- a/lib/appsignal/integrations/sinatra.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "appsignal" - -Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The 'require \"appsignal/integrations/sinatra\"' file require integration " \ - "method is deprecated. " \ - "Please follow the Sinatra setup guide in our docs for the new method: " \ - "https://docs.appsignal.com/ruby/integrations/sinatra.html" -) - -Appsignal.load(:sinatra) -Appsignal.start diff --git a/lib/appsignal/probes.rb b/lib/appsignal/probes.rb index 66dfbabe9..49e57336a 100644 --- a/lib/appsignal/probes.rb +++ b/lib/appsignal/probes.rb @@ -29,15 +29,6 @@ def [](key) probes[key] end - # @deprecated Use {Appsignal::Probes.register} instead. - def register(name, probe) - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The method 'Appsignal::Probes.probes.register' is deprecated. " \ - "Use 'Appsignal::Probes.register' instead." - ) - Appsignal::Probes.register(name, probe) - end - # @api private def internal_register(name, probe) if probes.key?(name) diff --git a/lib/appsignal/rack.rb b/lib/appsignal/rack.rb index ff6a59647..884534474 100644 --- a/lib/appsignal/rack.rb +++ b/lib/appsignal/rack.rb @@ -37,30 +37,5 @@ def self.queue_start_from(env) end end end - - # Alias constants that have moved with a warning message that points to the - # place to update the reference. - def self.const_missing(name) - case name - when :GenericInstrumentation - require "appsignal/rack/generic_instrumentation" - - callers = caller - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The constant Appsignal::Rack::GenericInstrumentation has been deprecated. " \ - "Please use the new Appsignal::Rack::InstrumentationMiddleware middleware. " \ - "This new middleware does not default the action name to 'unknown'. " \ - "Set the action name for the endpoint using the Appsignal.set_action helper. " \ - "Read our Rack docs for more information " \ - "https://docs.appsignal.com/ruby/integrations/rack.html " \ - "Update the constant name to " \ - "Appsignal::Rack::InstrumentationMiddleware in the following file to " \ - "remove this message.\n#{callers.first}" - # Return the alias so it can't ever get stuck in a recursive loop - Appsignal::Rack::GenericInstrumentationAlias - else - super - end - end end end diff --git a/lib/appsignal/rack/abstract_middleware.rb b/lib/appsignal/rack/abstract_middleware.rb index cf2fc85c4..56b973ccb 100644 --- a/lib/appsignal/rack/abstract_middleware.rb +++ b/lib/appsignal/rack/abstract_middleware.rb @@ -136,9 +136,6 @@ def add_transaction_metadata_before(transaction, request) # Override this method to set metadata after the app is called. # Call `super` to also include the default set metadata. def add_transaction_metadata_after(transaction, request) - default_action = - appsignal_route_env_value(request) || appsignal_action_env_value(request) - transaction.set_action_if_nil(default_action) transaction.set_metadata("path", request.path) request_method = request_method_for(request) @@ -179,26 +176,6 @@ def request_method_for(request) def request_for(env) @request_class.new(env) end - - def appsignal_route_env_value(request) - request.env["appsignal.route"].tap do |value| - next unless value - - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "Setting the action name with the request env 'appsignal.route' is deprecated. " \ - "Please use `Appsignal.set_action` instead. " - end - end - - def appsignal_action_env_value(request) - request.env["appsignal.action"].tap do |value| - next unless value - - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "Setting the action name with the request env 'appsignal.action' is deprecated. " \ - "Please use `Appsignal.set_action` instead. " - end - end end end end diff --git a/lib/appsignal/rack/generic_instrumentation.rb b/lib/appsignal/rack/generic_instrumentation.rb deleted file mode 100644 index 2678fae4f..000000000 --- a/lib/appsignal/rack/generic_instrumentation.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Appsignal - module Rack - # @deprecated Use {InstrumentationMiddleware} instead. - # @api private - class GenericInstrumentation < AbstractMiddleware - def initialize(app, options = {}) - options[:instrument_event_name] ||= "process_action.generic" - super - end - - def add_transaction_metadata_after(transaction, request) - super - transaction.set_action_if_nil("unknown") - end - end - - # @api private - class GenericInstrumentationAlias < GenericInstrumentation; end - end -end diff --git a/lib/appsignal/rack/streaming_listener.rb b/lib/appsignal/rack/streaming_listener.rb deleted file mode 100644 index 75b328cd2..000000000 --- a/lib/appsignal/rack/streaming_listener.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The constant Appsignal::Rack::StreamingListener has been deprecated. " \ - "Please update the constant name to " \ - "Appsignal::Rack::InstrumentationMiddleware." - -module Appsignal - module Rack - # Instrumentation middleware that tracks exceptions in streaming Rack - # responses. - # - # @deprecated Use {InstrumentationMiddleware} instead. - # @api private - class StreamingListener < AbstractMiddleware - def initialize(app, options = {}) - options[:instrument_event_name] ||= "process_streaming_request.rack" - super - end - - def add_transaction_metadata_after(transaction, request) - transaction.set_action_if_nil(request.env["appsignal.action"]) - - super - end - end - end -end diff --git a/lib/appsignal/transaction.rb b/lib/appsignal/transaction.rb index 107a381b7..865ac6969 100644 --- a/lib/appsignal/transaction.rb +++ b/lib/appsignal/transaction.rb @@ -25,64 +25,23 @@ class << self # Create a new transaction and set it as the currently active # transaction. # - # @param id_or_namespace [String] Namespace of the to be created transaction. + # @param namespace [String] Namespace of the to be created transaction. # @return [Transaction] - def create(id_or_namespace, arg_namespace = nil, request = nil, options = {}) - if id_or_namespace && arg_namespace - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction.create: " \ - "A new Transaction is created using the transaction ID argument. " \ - "This argument is deprecated without replacement." - ) - end - if arg_namespace - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction.create: " \ - "A Transaction is created using the namespace argument. " \ - "Specify the namespace as the first argument to the 'create' " \ - "method without the ID argument." - ) - end - if request - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction.create: " \ - "A Transaction is created using the request argument. " \ - "This argument is deprecated. Please use the `Appsignal.set_*` helpers instead." - ) - end - # Allow middleware to force a new transaction - if options[:force] - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction.create: " \ - "A Transaction is created using the `:force => true` option argument. " \ - "The options argument is deprecated without replacement." - ) - Thread.current[:appsignal_transaction] = nil - end - if arg_namespace - id = id_or_namespace - namespace = arg_namespace - else - id = SecureRandom.uuid - namespace = id_or_namespace - end - + def create(namespace) # Check if we already have a running transaction if Thread.current[:appsignal_transaction].nil? # If not, start a new transaction Thread.current[:appsignal_transaction] = Appsignal::Transaction.new( - id, - namespace, - request, - options + SecureRandom.uuid, + namespace ) else # Otherwise, log the issue about trying to start another transaction Appsignal.internal_logger.warn( - "Trying to start new transaction with id " \ - "'#{id}', but a transaction with id '#{current.transaction_id}' " \ - "is already running. Using transaction '#{current.transaction_id}'." + "Trying to start new transaction, but a transaction " \ + "with id '#{current.transaction_id}' is already running. " \ + "Using transaction '#{current.transaction_id}'." ) # And return the current transaction instead @@ -137,19 +96,16 @@ def clear_current_transaction! # @param namespace [String] Namespace of the to be created transaction. # @see create # @api private - def initialize(transaction_id, namespace, request = nil, options = {}) + def initialize(transaction_id, namespace) @transaction_id = transaction_id @action = nil @namespace = namespace - @request = request || InternalGenericRequest.new({}) @paused = false @discarded = false @tags = {} @custom_data = nil @breadcrumbs = [] @store = Hash.new({}) - @options = options - @options[:params_method] ||= :params @params = nil @session_data = nil @headers = nil @@ -171,7 +127,7 @@ def complete "because it was manually discarded." return end - _sample_data if @ext.finish(0) + sample_data if @ext.finish(0) @ext.complete end @@ -210,20 +166,6 @@ def store(key) @store[key] end - # @api private - def params - parameters = @params || request_params - - if parameters.respond_to? :call - parameters.call - else - parameters - end - rescue => e - Appsignal.internal_logger.error("Exception while fetching params: #{e.class}: #{e}") - nil - end - # Set parameters on the transaction. # # When no parameters are set this way, the transaction will look for @@ -246,15 +188,6 @@ def set_params(given_params = nil, &block) @params = given_params if given_params end - # @deprecated Use {#set_params} or {#set_params_if_nil} instead. - def params=(given_params) - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Transaction#params= is deprecated." \ - "Use Transaction#set_params or #set_params_if_nil instead." - ) - set_params(given_params) - end - # Set parameters on the transaction if not already set # # When no parameters are set this way, the transaction will look for @@ -479,18 +412,6 @@ def set_namespace(namespace) @ext.set_namespace(namespace) end - # @deprecated Use the {#set_action} helper. - # @api private - def set_http_or_background_action(from = request.params) - return unless from - - group_and_action = [ - from[:controller] || from[:class], - from[:action] || from[:method] - ] - set_action_if_nil(group_and_action.compact.join("#")) - end - # Set queue start time for transaction. # # @param start [Integer] Queue start time in milliseconds. @@ -507,35 +428,6 @@ def set_queue_start(start) Appsignal.internal_logger.warn("Queue start value #{start} is too big") end - # Set the queue time based on the HTTP header or `:queue_start` env key - # value. - # - # This method will first try to read the queue time from the HTTP headers - # `X-Request-Start` or `X-Queue-Start`. Which are parsed by Rack as - # `HTTP_X_QUEUE_START` and `HTTP_X_REQUEST_START`. - # The header value is parsed by AppSignal as either milliseconds or - # microseconds. - # - # If no headers are found, or the value could not be parsed, it falls back - # on the `:queue_start` env key on this Transaction's {request} environment - # (called like `request.env[:queue_start]`). This value is parsed by - # AppSignal as seconds. - # - # @see https://docs.appsignal.com/ruby/instrumentation/request-queue-time.html - # @deprecated Use {#set_queue_start} instead. - # @return [void] - def set_http_or_background_queue_start - Appsignal::Utils::StdoutAndLoggerMessage.warning \ - "The Appsignal::Transaction#set_http_or_background_queue_start " \ - "method has been deprecated. " \ - "Please use the Appsignal::Transaction#set_queue_start method instead." - - start = http_queue_start || background_queue_start - return unless start - - set_queue_start(start) - end - # @api private def set_metadata(key, value) return unless key && value @@ -544,28 +436,6 @@ def set_metadata(key, value) @ext.set_metadata(key, value) end - # @deprecated Use one of the set_tags, set_params, set_session_data, - # set_params or set_custom_data helpers instead. - # @api private - def set_sample_data(key, data) - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction#set_sample_data is deprecated. " \ - "Please use one of the instrumentation helpers: set_tags, " \ - "set_params, set_session_data, set_params or set_custom_data." - ) - _set_sample_data(key, data) - end - - # @deprecated No replacement. - # @api private - def sample_data - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "Appsignal::Transaction#sample_data is deprecated. " \ - "Please remove any calls to this method." - ) - _sample_data - end - # @see Appsignal::Helpers::Instrumentation#set_error def set_error(error) unless error.is_a?(Exception) @@ -613,7 +483,7 @@ def set_error(error) causes_sample_data.last[:is_root_cause] = false if root_cause_missing - _set_sample_data( + set_sample_data( "error_causes", causes_sample_data ) @@ -671,37 +541,9 @@ def to_h end alias_method :to_hash, :to_h - # @api private - class InternalGenericRequest - attr_reader :env - - def initialize(env) - @env = env - end - - def params - env[:params] - end - end - - # @deprecated Use the instrumentation helpers to set metadata on the - # transaction, rather than rely on the GenericRequest automation. See the - # {Helpers::Instrumentation} module for a list of helpers. - # @api private - class GenericRequest < InternalGenericRequest - def initialize(_env) - Appsignal::Utils::StdoutAndLoggerMessage.warning( - "The use of Appsignal::Transaction::GenericRequest is deprecated. " \ - "Use the `Appsignal.set_*` helpers instead. " \ - "https://docs.appsignal.com/guides/custom-data/sample-data.html" - ) - super - end - end - private - def _set_sample_data(key, data) + def set_sample_data(key, data) return unless key && data if !data.is_a?(Array) && !data.is_a?(Hash) @@ -728,44 +570,31 @@ def _set_sample_data(key, data) end end - def _sample_data + def sample_data { :params => sanitized_params, - :environment => sanitized_environment, + :environment => sanitized_request_headers, :session_data => sanitized_session_data, - :metadata => sanitized_metadata, :tags => sanitized_tags, :breadcrumbs => breadcrumbs, :custom_data => custom_data }.each do |key, data| - _set_sample_data(key, data) + set_sample_data(key, data) end end - # Returns calculated background queue start time in milliseconds, based on - # environment values. - # - # @return [nil] if no {#environment} is present. - # @return [nil] if there is no `:queue_start` in the {#environment}. - # @return [Integer] `:queue_start` time (in seconds) converted to milliseconds - def background_queue_start - env = environment - return unless env - - queue_start = env[:queue_start] - return unless queue_start - - (queue_start.to_f * 1000.0).to_i # Convert seconds to milliseconds - end + # @api private + def params + return unless @params - # Returns HTTP queue start time in milliseconds. - # - # @return [nil] if no queue start time is found. - # @return [nil] if begin time is too low to be plausible. - # @return [Integer] queue start in milliseconds. - def http_queue_start - env = environment - Appsignal::Rack::Utils.queue_start_from(env) + if @params.respond_to? :call + @params.call + else + @params + end + rescue => e + Appsignal.internal_logger.error("Exception while fetching params: #{e.class}: #{e}") + nil end def sanitized_params @@ -787,14 +616,12 @@ def request_params end def session_data - if @session_data - if @session_data.respond_to? :call - @session_data.call - else - @session_data - end - elsif request.respond_to?(:session) - request.session + return unless @session_data + + if @session_data.respond_to? :call + @session_data.call + else + @session_data end rescue => e Appsignal.internal_logger.error \ @@ -818,30 +645,11 @@ def sanitized_session_data ) end - # Returns sanitized metadata set on the request environment. - # - # @return [Hash] - def sanitized_metadata - env = environment - return unless env - - metadata = env[:metadata] - return unless metadata - - metadata - .transform_keys(&:to_s) - .reject { |key, _value| Appsignal.config[:filter_metadata].include?(key) } - end - - def environment - if @headers - if @headers.respond_to? :call - @headers.call - else - @headers - end - elsif request.respond_to?(:env) - request.env + def request_headers + if @headers.respond_to? :call + @headers.call + else + @headers end rescue => e Appsignal.internal_logger.error \ @@ -856,15 +664,13 @@ def environment # # @return [nil] if no environment is present. # @return [Hash] - def sanitized_environment - env = environment - return unless env - return unless env.respond_to?(:empty?) - return if env.empty? + def sanitized_request_headers + headers = request_headers + return unless headers {}.tap do |out| Appsignal.config[:request_headers].each do |key| - out[key] = env[key] if env[key] + out[key] = headers[key] if headers[key] end end end diff --git a/spec/integration/diagnose b/spec/integration/diagnose index 7acb6e7c5..13d26a738 160000 --- a/spec/integration/diagnose +++ b/spec/integration/diagnose @@ -1 +1 @@ -Subproject commit 7acb6e7c56a93ec1e0e1fd148407b3e7461a08ef +Subproject commit 13d26a738d63c8c0f660cb4dfdfbc8d11c176a1c diff --git a/spec/lib/appsignal/cli/diagnose_spec.rb b/spec/lib/appsignal/cli/diagnose_spec.rb index 310b4c40d..48188fc47 100644 --- a/spec/lib/appsignal/cli/diagnose_spec.rb +++ b/spec/lib/appsignal/cli/diagnose_spec.rb @@ -782,7 +782,7 @@ def dont_accept_prompt_to_send_diagnostics_report "initial" => { "env" => "" }, "file" => {}, "env" => {}, - "override" => { "send_session_data" => true } + "override" => {} }, "modifiers" => { "APPSIGNAL_INACTIVE_ON_CONFIG_FILE_ERROR" => "" @@ -880,7 +880,8 @@ def dont_accept_prompt_to_send_diagnostics_report context "when the source is only default" do it "does not print a source" do - expect(output).to include("debug: #{Appsignal.config[:debug]}\n") + expect(output) + .to include("enable_host_metrics: #{Appsignal.config[:enable_host_metrics]}\n") end end end @@ -961,7 +962,7 @@ def dont_accept_prompt_to_send_diagnostics_report ), "file" => hash_with_string_keys(config.file_config), "env" => {}, - "override" => { "send_session_data" => true } + "override" => {} }, "modifiers" => { "APPSIGNAL_INACTIVE_ON_CONFIG_FILE_ERROR" => "" @@ -992,7 +993,7 @@ def dont_accept_prompt_to_send_diagnostics_report "initial" => hash_with_string_keys(config.initial_config), "file" => hash_with_string_keys(config.file_config), "env" => {}, - "override" => { "send_session_data" => true } + "override" => {} }, "modifiers" => { "APPSIGNAL_INACTIVE_ON_CONFIG_FILE_ERROR" => "" diff --git a/spec/lib/appsignal/config_spec.rb b/spec/lib/appsignal/config_spec.rb index 443e7c017..73a727f58 100644 --- a/spec/lib/appsignal/config_spec.rb +++ b/spec/lib/appsignal/config_spec.rb @@ -212,7 +212,6 @@ def on_load :active => true, :activejob_report_errors => "all", :ca_file_path => File.join(resources_dir, "cacert.pem"), - :debug => false, :dns_servers => [], :enable_allocation_tracking => true, :enable_gvl_global_timer => true, @@ -245,8 +244,7 @@ def on_load :send_environment_metadata => true, :send_params => true, :send_session_data => true, - :sidekiq_report_errors => "all", - :transaction_debug_mode => false + :sidekiq_report_errors => "all" ) end @@ -478,7 +476,6 @@ def on_load :bind_address => "0.0.0.0", :ca_file_path => "/some/path", :cpu_count => 1.5, - :debug => true, :dns_servers => ["8.8.8.8", "8.8.4.4"], :enable_allocation_tracking => false, :enable_gvl_global_timer => false, @@ -518,10 +515,7 @@ def on_load :send_params => false, :send_session_data => false, :sidekiq_report_errors => "all", - :skip_session_data => false, :statsd_port => "7890", - :transaction_debug_mode => false, - :working_dir_path => "/some/path", :working_directory_path => working_directory_path } end @@ -544,12 +538,10 @@ def on_load "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => "all", "APPSIGNAL_STATSD_PORT" => "7890", "APPSIGNAL_WORKING_DIRECTORY_PATH" => working_directory_path, - "APPSIGNAL_WORKING_DIR_PATH" => "/some/path", "APP_REVISION" => "v2.5.1", # Booleans "APPSIGNAL_ACTIVE" => "true", - "APPSIGNAL_DEBUG" => "true", "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => "false", "APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER" => "false", "APPSIGNAL_ENABLE_GVL_WAITING_THREADS" => "false", @@ -568,8 +560,6 @@ def on_load "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => "false", "APPSIGNAL_SEND_PARAMS" => "false", "APPSIGNAL_SEND_SESSION_DATA" => "false", - "APPSIGNAL_SKIP_SESSION_DATA" => "false", - "APPSIGNAL_TRANSACTION_DEBUG_MODE" => "false", # Arrays "APPSIGNAL_DNS_SERVERS" => "8.8.8.8,8.8.4.4", @@ -659,78 +649,6 @@ def on_load described_class.new(Dir.pwd, "production", config_options, logger) end - describe "skip_session_data" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:deprecation_message) do - "The `skip_session_data` config option is deprecated. Please use " \ - "`send_session_data` instead." - end - before do - capture_std_streams(std_stream, err_stream) { config } - end - - context "when not set" do - let(:config_options) { {} } - - it "sets the default send_session_data value" do - expect(config[:skip_session_data]).to be_nil - expect(config[:send_session_data]).to eq(true) - expect(config.override_config[:send_session_data]).to eq(true) - end - - it "does not print a deprecation warning" do - expect(stderr).to_not include("appsignal WARNING: #{deprecation_message}") - expect(logs).to_not include(deprecation_message) - end - end - - context "when set to true" do - let(:config_options) { { :skip_session_data => true } } - - it "sets send_session_data if send_session_data is not set by the user" do - expect(config[:skip_session_data]).to eq(true) - expect(config[:send_session_data]).to eq(false) - expect(config.override_config[:send_session_data]).to eq(false) - end - - it "prints a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - - context "when set to false" do - let(:config_options) { { :skip_session_data => false } } - - it "sets send_session_data if send_session_data is not set by the user" do - expect(config[:skip_session_data]).to eq(false) - expect(config[:send_session_data]).to eq(true) - expect(config.override_config[:send_session_data]).to eq(true) - end - - it "prints a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - - context "when skip_session_data and send_session_data are both set" do - let(:config_options) { { :skip_session_data => true, :send_session_data => true } } - - it "does not overwrite the send_session_data value" do - expect(config[:skip_session_data]).to eq(true) - expect(config[:send_session_data]).to eq(true) - expect(config.override_config[:send_session_data]).to be_nil - end - - it "prints a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - end - if DependencyHelper.rails_present? require "active_job" @@ -885,7 +803,6 @@ def on_load expect(ENV.fetch("_APPSIGNAL_AGENT_PATH", nil)).to end_with("/ext") expect(ENV.fetch("_APPSIGNAL_BIND_ADDRESS", nil)).to eq("0.0.0.0") expect(ENV.fetch("_APPSIGNAL_CPU_COUNT", nil)).to eq("1.5") - expect(ENV.fetch("_APPSIGNAL_DEBUG_LOGGING", nil)).to eq "false" expect(ENV.fetch("_APPSIGNAL_LOG", nil)).to eq "stdout" expect(ENV.fetch("_APPSIGNAL_LOG_FILE_PATH", nil)).to end_with("/tmp/appsignal.log") expect(ENV.fetch("_APPSIGNAL_LOGGING_ENDPOINT", nil)).to eq "http://localhost:123" @@ -909,13 +826,11 @@ def on_load .to eq File.join(resources_dir, "cacert.pem") expect(ENV.fetch("_APPSIGNAL_DNS_SERVERS", nil)).to eq "8.8.8.8,8.8.4.4" expect(ENV.fetch("_APPSIGNAL_FILES_WORLD_ACCESSIBLE", nil)).to eq "true" - expect(ENV.fetch("_APPSIGNAL_TRANSACTION_DEBUG_MODE", nil)).to eq "true" expect(ENV.fetch("_APPSIGNAL_SEND_ENVIRONMENT_METADATA", nil)).to eq "false" expect(ENV.fetch("_APPSIGNAL_STATSD_PORT", nil)).to eq "" expect(ENV.fetch("_APPSIGNAL_FILTER_PARAMETERS", nil)).to eq "password,confirm_password" expect(ENV.fetch("_APPSIGNAL_FILTER_SESSION_DATA", nil)).to eq "key1,key2" expect(ENV.fetch("_APP_REVISION", nil)).to eq "v2.5.1" - expect(ENV).to_not have_key("_APPSIGNAL_WORKING_DIR_PATH") expect(ENV).to_not have_key("_APPSIGNAL_WORKING_DIRECTORY_PATH") end @@ -941,17 +856,6 @@ def on_load end end - context "with :working_dir_path" do - before do - config[:working_dir_path] = "/tmp/appsignal2" - config.write_to_environment - end - - it "sets the modified :working_dir_path" do - expect(ENV.fetch("_APPSIGNAL_WORKING_DIR_PATH", nil)).to eq "/tmp/appsignal2" - end - end - context "with :working_directory_path" do before do config[:working_directory_path] = "/tmp/appsignal2" @@ -1161,54 +1065,6 @@ def log_file_path end end - describe "#maintain_backwards_compatibility" do - let(:log_stream) { StringIO.new } - let(:logger) { test_logger(log_stream) } - let(:logs) { log_contents(log_stream) } - let(:config) do - described_class.new(Dir.pwd, "production", config_options, logger) - end - - describe "working_dir_path" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:deprecation_message) do - "The `working_dir_path` option is deprecated, please use " \ - "`working_directory_path` instead and specify the " \ - "full path to the working directory" - end - before do - capture_std_streams(std_stream, err_stream) { config } - end - - context "when not set" do - let(:config_options) { {} } - - it "sets the default working_dir_path value" do - expect(config[:working_dir_path]).to be_nil - end - - it "does not print a deprecation warning" do - expect(stderr).to_not include("appsignal WARNING: #{deprecation_message}") - expect(logs).to_not include(deprecation_message) - end - end - - context "when set" do - let(:config_options) { { :working_dir_path => "/tmp/appsignal2" } } - - it "sets the default working_dir_path value" do - expect(config[:working_dir_path]).to eq("/tmp/appsignal2") - end - - it "does not print a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - end - end - describe "#validate" do subject { config.valid? } let(:config) do @@ -1264,16 +1120,6 @@ def log_file_path end end - context "with debug set to true" do - let(:options) { { :debug => true } } - it { is_expected.to eq(Logger::DEBUG) } - end - - context "with transaction_debug_mode set to true" do - let(:options) { { :transaction_debug_mode => true } } - it { is_expected.to eq(Logger::DEBUG) } - end - context "with log_level set to error" do let(:options) { { :log_level => "error" } } it { is_expected.to eq(Logger::ERROR) } @@ -1321,14 +1167,6 @@ def log_file_path it "prints a warning and doesn't use the log_level" do is_expected.to eql(Logger::INFO) end - - context "with debug option set to true" do - let(:options) { { :log_level => "fatal", :debug => true } } - - it "prints a warning and sets it to debug" do - is_expected.to eql(Logger::DEBUG) - end - end end end diff --git a/spec/lib/appsignal/hooks_spec.rb b/spec/lib/appsignal/hooks_spec.rb index cb4ff2625..13b1ac3d4 100644 --- a/spec/lib/appsignal/hooks_spec.rb +++ b/spec/lib/appsignal/hooks_spec.rb @@ -82,47 +82,6 @@ def install expect(Appsignal::Hooks.hooks[:mock_error_hook].installed?).to be_falsy Appsignal::Hooks.hooks.delete(:mock_error_hook) end - - describe "missing constants" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:log_stream) { std_stream } - let(:log) { log_contents(log_stream) } - before do - Appsignal.internal_logger = test_logger(log_stream) - end - - def call_constant(&block) - capture_std_streams(std_stream, err_stream, &block) - end - - describe "SidekiqPlugin" do - it "logs a deprecation message and returns the new constant" do - constant = call_constant { Appsignal::Hooks::SidekiqPlugin } - - expect(constant).to eql(Appsignal::Integrations::SidekiqMiddleware) - expect(constant.name).to eql("Appsignal::Integrations::SidekiqMiddleware") - - deprecation_message = - "The constant Appsignal::Hooks::SidekiqPlugin has been deprecated. " \ - "Please update the constant name to Appsignal::Integrations::SidekiqMiddleware " \ - "in the following file to remove this message.\n#{__FILE__}:" - expect(stderr).to include "appsignal WARNING: #{deprecation_message}" - expect(log).to contains_log :warn, deprecation_message - end - end - - describe "other constant" do - it "raises a NameError like Ruby normally does" do - expect do - call_constant { Appsignal::Hooks::Unknown } - end.to raise_error(NameError) - - expect(stderr).to be_empty - expect(log).to be_empty - end - end - end end describe Appsignal::Hooks::Helpers do diff --git a/spec/lib/appsignal/integrations/grape_spec.rb b/spec/lib/appsignal/integrations/grape_spec.rb deleted file mode 100644 index b74dacab9..000000000 --- a/spec/lib/appsignal/integrations/grape_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -if DependencyHelper.grape_present? - require "appsignal/integrations/grape" - - context "Appsignal::Grape::Middleware constant" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - - it "returns the Rack::GrapeMiddleware constant calling the Grape::Middleware constant" do - silence { expect(Appsignal::Grape::Middleware).to be(Appsignal::Rack::GrapeMiddleware) } - end - - it "prints a deprecation warning to STDERR" do - capture_std_streams(std_stream, err_stream) do - expect(Appsignal::Grape::Middleware).to be(Appsignal::Rack::GrapeMiddleware) - end - - expect(stderr).to include( - "appsignal WARNING: The constant Appsignal::Grape::Middleware has been deprecated." - ) - end - - it "logs a warning" do - logs = - capture_logs do - silence do - expect(Appsignal::Grape::Middleware).to be(Appsignal::Rack::GrapeMiddleware) - end - end - - expect(logs).to contains_log( - :warn, - "The constant Appsignal::Grape::Middleware has been deprecated." - ) - end - end -end diff --git a/spec/lib/appsignal/integrations/hanami_spec.rb b/spec/lib/appsignal/integrations/hanami_spec.rb deleted file mode 100644 index 9322f6519..000000000 --- a/spec/lib/appsignal/integrations/hanami_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -if DependencyHelper.hanami_present? - describe "Hanami integration" do - it "loads the Hanami loader" do - ENV["APPSIGNAL_APP_NAME"] = "test/sinatra" - ENV["APPSIGNAL_PUSH_API_KEY"] = "test-key" - - require "appsignal/integrations/hanami" - - expect(Appsignal::Loaders.instances).to include( - :hanami => kind_of(Appsignal::Loaders::HanamiLoader) - ) - expect(Appsignal.active?).to be(true) - end - end -end diff --git a/spec/lib/appsignal/integrations/padrino_spec.rb b/spec/lib/appsignal/integrations/padrino_spec.rb deleted file mode 100644 index 729b94935..000000000 --- a/spec/lib/appsignal/integrations/padrino_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -if DependencyHelper.padrino_present? - describe "Padrino integration" do - it "loads the Padrino loader" do - ENV["APPSIGNAL_APP_NAME"] = "test/sinatra" - ENV["APPSIGNAL_PUSH_API_KEY"] = "test-key" - - require "appsignal/integrations/padrino" - - expect(Appsignal::Loaders.instances).to include( - :padrino => kind_of(Appsignal::Loaders::PadrinoLoader) - ) - expect(Appsignal.active?).to be(true) - end - end -end diff --git a/spec/lib/appsignal/integrations/railtie_spec.rb b/spec/lib/appsignal/integrations/railtie_spec.rb index 4b60340e9..84b7952e9 100644 --- a/spec/lib/appsignal/integrations/railtie_spec.rb +++ b/spec/lib/appsignal/integrations/railtie_spec.rb @@ -34,7 +34,6 @@ def expect_middleware_to_match(middleware, klass, args) let(:app) { MyApp::Application.new } before do RailtieHelper.ensure_initialize! - Appsignal.config = nil end def initialize_railtie(event) @@ -57,7 +56,7 @@ def initialize_railtie(event) end it "doesn't overwrite the config if a config is already present " do - Appsignal.config = Appsignal::Config.new( + Appsignal._config = Appsignal::Config.new( Dir.pwd, "my_env", :some_config => "some value" diff --git a/spec/lib/appsignal/integrations/sinatra_spec.rb b/spec/lib/appsignal/integrations/sinatra_spec.rb deleted file mode 100644 index 91c6c24e7..000000000 --- a/spec/lib/appsignal/integrations/sinatra_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -if DependencyHelper.padrino_present? - describe "Sinatra integration" do - it "loads the Sinatra loader" do - ENV["APPSIGNAL_APP_NAME"] = "test/sinatra" - ENV["APPSIGNAL_PUSH_API_KEY"] = "test-key" - - require "appsignal/integrations/sinatra" - - expect(Appsignal::Loaders.instances).to include( - :sinatra => kind_of(Appsignal::Loaders::SinatraLoader) - ) - expect(Appsignal.active?).to be(true) - end - end -end diff --git a/spec/lib/appsignal/loaders/hanami_spec.rb b/spec/lib/appsignal/loaders/hanami_spec.rb index 22bdd9686..5b58fc569 100644 --- a/spec/lib/appsignal/loaders/hanami_spec.rb +++ b/spec/lib/appsignal/loaders/hanami_spec.rb @@ -1,7 +1,5 @@ if DependencyHelper.hanami_present? describe "Appsignal::Loaders::HanamiLoader" do - before { Appsignal.config = nil } - describe "#on_load" do it "registers Hanami default config" do load_loader(:hanami) diff --git a/spec/lib/appsignal/loaders/padrino_spec.rb b/spec/lib/appsignal/loaders/padrino_spec.rb index 17b17f069..09d8b958f 100644 --- a/spec/lib/appsignal/loaders/padrino_spec.rb +++ b/spec/lib/appsignal/loaders/padrino_spec.rb @@ -1,7 +1,5 @@ if DependencyHelper.padrino_present? describe "Appsignal::Loaders::PadrinoLoader" do - before { Appsignal.config = nil } - describe "#on_load" do it "registers Padrino default config" do load_loader(:padrino) @@ -70,7 +68,6 @@ class PadrinoClassWithRouter # TODO: use an instance double let(:settings) { double(:name => "TestApp") } around { |example| keep_transactions { example.run } } - before { Appsignal.config = nil } describe "routes" do let(:env) do diff --git a/spec/lib/appsignal/loaders/sinatra_spec.rb b/spec/lib/appsignal/loaders/sinatra_spec.rb index 72c7acd75..92a03f3ea 100644 --- a/spec/lib/appsignal/loaders/sinatra_spec.rb +++ b/spec/lib/appsignal/loaders/sinatra_spec.rb @@ -1,7 +1,5 @@ if DependencyHelper.sinatra_present? describe "Appsignal::Loaders::SinatraLoader" do - before { Appsignal.config = nil } - describe "#on_load" do it "registers Sinatra default config" do ::Sinatra::Application.settings.root = "/some/path" diff --git a/spec/lib/appsignal/probes_spec.rb b/spec/lib/appsignal/probes_spec.rb index dccd69d4c..aaeb688b5 100644 --- a/spec/lib/appsignal/probes_spec.rb +++ b/spec/lib/appsignal/probes_spec.rb @@ -3,38 +3,6 @@ before { Appsignal::Probes.probes.clear } - context "Minutely constant" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - - it "returns the Probes constant calling the Minutely constant" do - silence { expect(Appsignal::Minutely).to be(Appsignal::Probes) } - end - - it "prints a deprecation warning to STDERR" do - capture_std_streams(std_stream, err_stream) do - expect(Appsignal::Minutely).to be(Appsignal::Probes) - end - - expect(stderr) - .to include("appsignal WARNING: The constant Appsignal::Minutely has been deprecated.") - end - - it "logs a warning" do - logs = - capture_logs do - silence do - expect(Appsignal::Minutely).to be(Appsignal::Probes) - end - end - - expect(logs).to contains_log( - :warn, - "The constant Appsignal::Minutely has been deprecated." - ) - end - end - it "returns a ProbeCollection" do expect(Appsignal::Probes.probes) .to be_instance_of(Appsignal::Probes::ProbeCollection) @@ -398,45 +366,6 @@ def call end end - describe "#register" do - it "adds the probe by key" do - expect(Appsignal::Probes).to receive(:probes).and_return(collection) - - probe = lambda {} - silence { collection.register :my_probe, probe } - expect(collection[:my_probe]).to eql(probe) - end - - context "logger" do - before { start_agent } - - it "logs a deprecation message" do - logs = - capture_logs do - silence { collection.register :my_probe, lambda {} } - end - expect(logs).to contains_log :warn, - "The method 'Appsignal::Probes.probes.register' is deprecated. " \ - "Use 'Appsignal::Probes.register' instead." - end - end - - context "stderr" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - - it "prints a deprecation warning" do - capture_std_streams(std_stream, err_stream) do - collection.register :my_probe, lambda {} - end - deprecation_message = - "The method 'Appsignal::Probes.probes.register' is deprecated. " \ - "Use 'Appsignal::Probes.register' instead." - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - end - end - end - describe "#internal_register" do let(:log_stream) { std_stream } let(:log) { log_contents(log_stream) } @@ -463,10 +392,8 @@ def call describe "#unregister" do it "removes the probe from the collection" do - expect(Appsignal::Probes).to receive(:probes).and_return(collection) - probe = lambda {} - silence { collection.register :my_probe, probe } + silence { collection.internal_register :my_probe, probe } expect(collection[:my_probe]).to eql(probe) silence { collection.unregister :my_probe } diff --git a/spec/lib/appsignal/rack/abstract_middleware_spec.rb b/spec/lib/appsignal/rack/abstract_middleware_spec.rb index b18f5e459..cad7f3fa6 100644 --- a/spec/lib/appsignal/rack/abstract_middleware_spec.rb +++ b/spec/lib/appsignal/rack/abstract_middleware_spec.rb @@ -165,64 +165,6 @@ def make_request_with_error(error_class, error_message) end end - context "with appsignal.route env" do - before { env["appsignal.route"] = "POST /my-route" } - - it "reports the appsignal.route value as the action name" do - make_request - - expect(last_transaction).to have_action("POST /my-route") - end - - it "prints a deprecation warning" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - make_request - end - - expect(err_stream.read).to include( - "Setting the action name with the request env 'appsignal.route' is deprecated." - ) - end - - it "logs a deprecation warning" do - logs = capture_logs { make_request } - expect(logs).to contains_log( - :warn, - "Setting the action name with the request env 'appsignal.route' is deprecated." - ) - end - end - - context "with appsignal.action env" do - before { env["appsignal.action"] = "POST /my-action" } - - it "reports the appsignal.action value as the action name" do - make_request - - expect(last_transaction).to have_action("POST /my-action") - end - - it "prints a deprecation warning" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - make_request - end - - expect(err_stream.read).to include( - "Setting the action name with the request env 'appsignal.action' is deprecated." - ) - end - - it "logs a deprecation warning" do - logs = capture_logs { make_request } - expect(logs).to contains_log( - :warn, - "Setting the action name with the request env 'appsignal.action' is deprecated." - ) - end - end - describe "request metadata" do it "sets request metadata" do env.merge!("PATH_INFO" => "/some/path", "REQUEST_METHOD" => "GET") diff --git a/spec/lib/appsignal/rack/generic_instrumentation_spec.rb b/spec/lib/appsignal/rack/generic_instrumentation_spec.rb deleted file mode 100644 index 05167227e..000000000 --- a/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -describe "Appsignal::Rack::GenericInstrumentation" do - describe "Appsignal::Rack::GenericInstrumentation constant" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - before do - if Appsignal::Rack.const_defined?(:GenericInstrumentation) - hide_const "Appsignal::Rack::GenericInstrumentation" - end - end - - it "returns the Rack::GenericInstrumentation constant" do - silence do - expect(Appsignal::Rack::GenericInstrumentation) - .to be(Appsignal::Rack::GenericInstrumentationAlias) - end - end - - it "prints a deprecation warning to STDERR" do - capture_std_streams(std_stream, err_stream) do - Appsignal::Rack::GenericInstrumentation - end - - expect(stderr).to include( - "appsignal WARNING: The constant Appsignal::Rack::GenericInstrumentation " \ - "has been deprecated." - ) - end - - it "logs a warning" do - logs = - capture_logs do - silence do - Appsignal::Rack::GenericInstrumentation - end - end - - expect(logs).to contains_log( - :warn, - "The constant Appsignal::Rack::GenericInstrumentation has been deprecated." - ) - end - end - - describe "middleware" do - let(:app) { double(:call => true) } - let(:env) { Rack::MockRequest.env_for("/some/path") } - let(:middleware) { Appsignal::Rack::GenericInstrumentation.new(app, {}) } - - before { start_agent } - around { |example| keep_transactions { example.run } } - - def make_request(env) - middleware.call(env) - end - - context "without an exception" do - it "reports a process_action.generic event" do - make_request(env) - - expect(last_transaction).to include_event("name" => "process_action.generic") - end - end - - context "with action name env" do - it "reports the appsignal.action env as the action name" do - env["appsignal.action"] = "MyAction" - make_request(env) - - expect(last_transaction).to have_action("MyAction") - end - end - - context "without action name metadata" do - it "reports 'unknown' as the action name" do - make_request(env) - - expect(last_transaction).to have_action("unknown") - end - end - end -end diff --git a/spec/lib/appsignal/rack/rails_instrumentation_spec.rb b/spec/lib/appsignal/rack/rails_instrumentation_spec.rb index ee4e82f13..3e7f168b0 100644 --- a/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +++ b/spec/lib/appsignal/rack/rails_instrumentation_spec.rb @@ -3,13 +3,7 @@ class MockController; end let(:log) { StringIO.new } - let(:transaction) do - Appsignal::Transaction.new( - "transaction_id", - Appsignal::Transaction::HTTP_REQUEST, - Rack::Request.new(env) - ) - end + let(:transaction) { new_transaction } let(:app) { DummyApp.new } let(:params) do { diff --git a/spec/lib/appsignal/rack/streaming_listener_spec.rb b/spec/lib/appsignal/rack/streaming_listener_spec.rb deleted file mode 100644 index ba7fb48f1..000000000 --- a/spec/lib/appsignal/rack/streaming_listener_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -describe "Appsignal::Rack::StreamingListener" do - def load_middleware - load "lib/appsignal/rack/streaming_listener.rb" - end - - describe "loading the streaming_listener integrations file" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - after { Appsignal::Rack.send(:remove_const, :StreamingListener) } - - it "prints a deprecation warning to STDERR" do - capture_std_streams(std_stream, err_stream) do - load_middleware - end - - expect(stderr).to include( - "appsignal WARNING: The constant Appsignal::Rack::StreamingListener " \ - "has been deprecated." - ) - end - - it "logs a warning" do - logs = - capture_logs do - silence do - load_middleware - end - end - - expect(logs).to contains_log( - :warn, - "The constant Appsignal::Rack::StreamingListener has been deprecated." - ) - end - end - - describe "middleware" do - let(:env) { {} } - let(:app) { DummyApp.new } - let(:middleware) { Appsignal::Rack::StreamingListener.new(app, {}) } - around { |example| keep_transactions { example.run } } - before(:context) { load_middleware } - before { start_agent } - - def make_request - middleware.call(env) - end - - it "instruments the call" do - make_request - - expect(last_transaction).to include_event("name" => "process_streaming_request.rack") - end - - it "set no action by default" do - make_request - - expect(last_transaction).to_not have_action - end - - it "set `appsignal.action` to the action name" do - env["appsignal.action"] = "Action" - - make_request - - expect(last_transaction).to have_action("Action") - end - end -end diff --git a/spec/lib/appsignal/transaction_spec.rb b/spec/lib/appsignal/transaction_spec.rb index 3e45c9b9a..98b23781a 100644 --- a/spec/lib/appsignal/transaction_spec.rb +++ b/spec/lib/appsignal/transaction_spec.rb @@ -32,87 +32,6 @@ transaction = create_transaction expect(transaction).to eq current_transaction end - - context "with legacy arguments" do - it "returns the created transaction" do - transaction_id = "mock-id" - namespace = "my_namespace" - transaction = legacy_create_transaction( - :id => transaction_id, - :namespace => namespace - ) - expect(transaction).to be_a(Appsignal::Transaction) - - expect(transaction).to have_id(transaction_id) - expect(transaction.transaction_id).to eq(transaction_id) - - expect(transaction).to have_namespace(namespace) - expect(transaction.namespace).to eq(namespace) - end - - it "logs deprecation warnings" do - logs = - capture_logs do - legacy_create_transaction( - :id => "mock-id", - :namespace => "my_namespace", - :request => Appsignal::Transaction::InternalGenericRequest.new({}), - :options => { :force => true } - ) - end - - expect(logs).to contains_log( - :warn, - "Appsignal::Transaction.create: " \ - "A new Transaction is created using the transaction ID argument." - ) - expect(logs).to contains_log( - :warn, - "Appsignal::Transaction.create: " \ - "A Transaction is created using the namespace argument." - ) - expect(logs).to contains_log( - :warn, - "Appsignal::Transaction.create: " \ - "A Transaction is created using the request argument." - ) - expect(logs).to contains_log( - :warn, - "Appsignal::Transaction.create: " \ - "A Transaction is created using the `:force => true` option argument. " - ) - end - - it "prints deprecation warnings" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - legacy_create_transaction( - :id => "mock-id", - :namespace => "my_namespace", - :request => Appsignal::Transaction::InternalGenericRequest.new({}), - :options => { :force => true } - ) - end - - stderr = err_stream.read - expect(stderr).to include( - "appsignal WARNING: Appsignal::Transaction.create: " \ - "A new Transaction is created using the transaction ID argument." - ) - expect(stderr).to include( - "appsignal WARNING: Appsignal::Transaction.create: " \ - "A Transaction is created using the namespace argument." - ) - expect(stderr).to include( - "appsignal WARNING: Appsignal::Transaction.create: " \ - "A Transaction is created using the request argument." - ) - expect(stderr).to include( - "appsignal WARNING: Appsignal::Transaction.create: " \ - "A Transaction is created using the `:force => true` option argument. " - ) - end - end end context "when a transaction is already running" do @@ -137,28 +56,9 @@ logs = capture_logs { create_transaction } expect(logs).to contains_log :warn, - "Trying to start new transaction with id 'transaction_id_2', but a " \ - "transaction with id 'transaction_id_1' is already " \ - "running. Using transaction 'transaction_id_1'." - end - - context "with option :force => true" do - it "returns the newly created (and current) transaction" do - original_transaction = create_transaction - - expect(original_transaction).to be_a(Appsignal::Transaction) - expect(current_transaction).to have_id("transaction_id_1") - - new_transaction = legacy_create_transaction( - :id => "transaction_id_2", - :options => { :force => true } - ) - - expect(new_transaction).to be_a(Appsignal::Transaction) - expect(new_transaction).to_not eq(original_transaction) - expect(new_transaction).to have_id("transaction_id_2") - expect(current_transaction).to eq(new_transaction) - end + "Trying to start new transaction, but a transaction with id " \ + "'transaction_id_1' is already running. " \ + "Using transaction 'transaction_id_1'." end end end @@ -363,49 +263,9 @@ end end - context "transaction id" do - before do - allow(SecureRandom).to receive(:uuid).and_return("mock_transaction_id") - end - - it "sets the transaction id" do - expect(transaction).to have_id("mock_transaction_id") - end - end - it "sets the namespace to http_request" do expect(transaction.namespace).to eq "http_request" end - - it "sets the request" do - expect(transaction.request).to be_a(Appsignal::Transaction::InternalGenericRequest) - end - - it "sets the request not to paused" do - expect(transaction.paused?).to be_falsy - end - - it "sets no tags by default" do - expect(transaction.tags).to be_empty - end - - describe "#options" do - let(:options) { transaction.options } - - it "sets the default :params_method" do - expect(options[:params_method]).to eq :params - end - - context "with overridden options" do - let(:transaction) do - legacy_new_transaction(:options => { :params_method => :filtered_params }) - end - - it "sets the overridden :params_method" do - expect(options[:params_method]).to eq :filtered_params - end - end - end end describe "#store" do @@ -423,76 +283,6 @@ end end - describe "#params" do - let(:transaction) { new_transaction } - let(:params) { transaction.params } - - context "with custom params set on transaction" do - before { transaction.set_params(:foo => "bar") } - - it "returns custom parameters" do - expect(params).to eq(:foo => "bar") - end - - context "when params is a callable object" do - it "calls the params object and sets the return value as parametesr" do - transaction.set_params { { "param1" => "value1" } } - - expect(params).to eq("param1" => "value1") - end - end - end - - context "without custom params set on transaction" do - let(:transaction) do - legacy_new_transaction( - :request => legacy_request( - :params => { - "action" => "show", - "controller" => "blog_posts", - "id" => "1" - - } - ) - ) - end - - it "returns parameters from request" do - expect(params).to eq( - "action" => "show", - "controller" => "blog_posts", - "id" => "1" - ) - end - end - end - - describe "#params=" do - let(:transaction) { new_transaction } - - it "sets params on the transaction" do - params = { "foo" => "bar" } - silence { transaction.params = params } - - transaction._sample - expect(transaction.params).to eq(params) - expect(transaction).to include_params(params) - end - - it "logs a deprecation warning" do - logs = - capture_logs do - transaction.params = { "foo" => "bar" } - end - - expect(logs).to contains_log( - :warn, - "Transaction#params= is deprecated." \ - "Use Transaction#set_params or #set_params_if_nil instead." - ) - end - end - describe "#set_params" do let(:transaction) { new_transaction } @@ -502,7 +292,6 @@ transaction.set_params(params) transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end @@ -511,7 +300,6 @@ transaction.set_params { params } transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end @@ -521,7 +309,6 @@ transaction.set_params(arg_params) { block_params } transaction._sample - expect(transaction.params).to eq(arg_params) expect(transaction).to include_params(arg_params) end @@ -534,6 +321,17 @@ "Exception while fetching params: RuntimeError: uh oh" ) end + + context "with AppSignal filtering" do + before { Appsignal.config.config_hash[:filter_parameters] = %w[foo] } + + it "returns sanitized custom params" do + transaction.set_params("foo" => "value", "baz" => "bat") + + transaction._sample + expect(transaction).to include_params("foo" => "[FILTERED]", "baz" => "bat") + end + end end context "when the given params is nil" do @@ -543,7 +341,6 @@ transaction.set_params(nil) transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end end @@ -558,7 +355,6 @@ transaction.set_params_if_nil(params) transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end @@ -567,7 +363,6 @@ transaction.set_params_if_nil { params } transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end @@ -577,7 +372,6 @@ transaction.set_params_if_nil(arg_params) { block_params } transaction._sample - expect(transaction.params).to eq(arg_params) expect(transaction).to include_params(arg_params) end @@ -588,7 +382,6 @@ transaction.set_params_if_nil(nil) transaction._sample - expect(transaction.params).to eq(params) expect(transaction).to include_params(params) end end @@ -602,7 +395,6 @@ transaction.set_params_if_nil(params) transaction._sample - expect(transaction.params).to eq(preset_params) expect(transaction).to include_params(preset_params) end @@ -613,7 +405,6 @@ transaction.set_params_if_nil { params } transaction._sample - expect(transaction.params).to eq(preset_params) expect(transaction).to include_params(preset_params) end end @@ -1150,42 +941,6 @@ end end - describe "#set_http_or_background_action" do - let(:transaction) { new_transaction } - - context "for a hash with controller and action" do - it "sets the action" do - transaction.set_http_or_background_action( - :controller => "HomeController", - :action => "show" - ) - expect(transaction).to have_action("HomeController#show") - end - end - - context "for a hash with just action" do - it "sets the action" do - transaction.set_http_or_background_action(:action => "show") - expect(transaction).to have_action("show") - end - end - - context "for a hash with class and method" do - it "sets the action" do - transaction.set_http_or_background_action(:class => "Worker", :method => "perform") - expect(transaction).to have_action("Worker#perform") - end - end - - context "when action is already set" do - it "does not overwrite the set action" do - transaction.set_action("MyCustomAction#perform") - transaction.set_http_or_background_action(:class => "Worker", :method => "perform") - expect(transaction).to have_action("MyCustomAction#perform") - end - end - end - describe "#set_queue_start" do let(:transaction) { new_transaction } @@ -1210,75 +965,6 @@ end end - describe "#set_http_or_background_queue_start" do - let(:transaction) { legacy_new_transaction(:request => legacy_request(env)) } - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:header_factor) { 1_000 } - let(:env_queue_start) { fixed_time + 20 } # in seconds - - def set_http_or_background_queue_start - capture_std_streams(std_stream, err_stream) do - transaction.set_http_or_background_queue_start - end - end - - context "when a queue time is found in a request header" do - let(:header_time) { ((fixed_time + 10) * header_factor).to_i } # in milliseconds - let(:env) { { "HTTP_X_REQUEST_START" => "t=#{header_time}" } } - - it "sets the http header value in milliseconds on the transaction" do - set_http_or_background_queue_start - - expect(transaction).to have_queue_start(1_389_783_610_000) - end - - it "logs a deprecation message" do - logs = capture_logs { set_http_or_background_queue_start } - - expect(logs).to contains_log( - :warn, - "The Appsignal::Transaction#set_http_or_background_queue_start " \ - "method has been deprecated." - ) - end - - it "prints a deprecation message" do - set_http_or_background_queue_start - - expect(stderr).to include( - "The Appsignal::Transaction#set_http_or_background_queue_start " \ - "method has been deprecated." - ) - end - - context "when a :queue_start key is found in the transaction environment" do - let(:env) do - { - "HTTP_X_REQUEST_START" => "t=#{header_time}", - :queue_start => env_queue_start - } - end - - it "sets the http header value in milliseconds on the transaction" do - set_http_or_background_queue_start - - expect(transaction).to have_queue_start(1_389_783_610_000) - end - end - end - - context "when a :queue_start key is found in the transaction environment" do - let(:env) { { :queue_start => env_queue_start } } # in seconds - - it "sets the :queue_start value in milliseconds on the transaction" do - set_http_or_background_queue_start - - expect(transaction).to have_queue_start(1_389_783_620_000) - end - end - end - describe "#set_metadata" do let(:transaction) { new_transaction } @@ -1400,7 +1086,8 @@ def to_s it "updates the sample data on the transaction" do silence do - transaction.set_sample_data( + transaction.send( + :set_sample_data, "params", :controller => "blog_posts", :action => "show", @@ -1419,7 +1106,7 @@ def to_s it "does not update the sample data on the transaction" do logs = capture_logs do - silence { transaction.set_sample_data("params", "string") } + silence { transaction.send(:set_sample_data, "params", "string") } end expect(transaction.to_h["sample_data"]).to eq({}) @@ -1437,7 +1124,7 @@ def to_s end logs = capture_logs do - silence { transaction.set_sample_data("params", klass.new => 1) } + silence { transaction.send(:set_sample_data, "params", klass.new => 1) } end expect(transaction).to_not include_params @@ -1447,55 +1134,6 @@ def to_s end end - describe "#sample_data" do - let(:transaction) { legacy_new_transaction(:request => rack_request(env)) } - let(:env) do - Rack::MockRequest.env_for( - "/blog", - "REQUEST_METHOD" => "GET", - "SERVER_NAME" => "example.org", - "SERVER_PORT" => "80", - "PATH_INFO" => "/blog", - "rack.session" => { "session" => "value" }, - :params => { - "controller" => "blog_posts", - "action" => "show", - "id" => "1" - } - ).merge( - :metadata => { "metadata" => "value" } - ) - end - - it "sets sample data from request" do - transaction.set_tags "tag" => "value" - transaction.add_breadcrumb "category", "action", "message", "key" => "value" - silence { transaction.sample_data } - - expect(transaction).to include_environment( - "REQUEST_METHOD" => "GET", - "SERVER_NAME" => "example.org", - "SERVER_PORT" => "80", - "PATH_INFO" => "/blog" - ) - expect(transaction).to include_session_data("session" => "value") - expect(transaction).to include_params( - "controller" => "blog_posts", - "action" => "show", - "id" => "1" - ) - expect(transaction).to include_sample_metadata("metadata" => "value") - expect(transaction).to include_tags("tag" => "value") - expect(transaction).to include_breadcrumb( - "action", - "category", - "message", - { "key" => "value" }, - kind_of(Integer) - ) - end - end - describe "#set_error" do let(:transaction) { new_transaction } let(:env) { http_request_env_with_data } @@ -1791,433 +1429,8 @@ def to_s end end - context "GenericRequest" do - let(:env) { {} } - subject { Appsignal::Transaction::GenericRequest.new(env) } - - it "prints a deprecation warning on use" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) { subject } - - expect(err_stream.read).to include( - "appsignal WARNING: The use of Appsignal::Transaction::GenericRequest is deprecated." - ) - end - - it "logs a deprecation warning on use" do - logs = capture_logs { silence { subject } } - - expect(logs).to contains_log( - :warn, - "The use of Appsignal::Transaction::GenericRequest is deprecated." - ) - end - - it "initializes with an empty env" do - expect(subject.env).to be_empty - end - - context "when given an env" do - let(:env) do - { - :params => { :id => 1 }, - :queue_start => 10 - } - end - - it "sets the given env" do - expect(subject.env).to eq env - end - - it "sets the params present in the env" do - expect(subject.params).to eq(:id => 1) - end - end - end - # private - describe "#background_queue_start" do - let(:transaction) { legacy_new_transaction(:request => request) } - let(:request) { rack_request(env) } - let(:env) { {} } - subject { transaction.send(:background_queue_start) } - - context "when request is nil" do - let(:request) { nil } - - it { is_expected.to eq nil } - end - - context "when env is nil" do - before { expect(request).to receive(:env).and_return(nil) } - - it { is_expected.to eq nil } - end - - context "when queue start is nil" do - it { is_expected.to eq nil } - end - - context "when queue start is set" do - before do - env[:queue_start] = fixed_time - end - - it { is_expected.to eq 1_389_783_600_000 } - end - end - - describe "#http_queue_start" do - let(:transaction) { legacy_new_transaction(:request => request) } - let(:request) { rack_request(env) } - let(:env) { {} } - let(:slightly_earlier_time) { fixed_time - 0.4 } - let(:slightly_earlier_time_value) { (slightly_earlier_time * factor).to_i } - subject { transaction.send(:http_queue_start) } - - shared_examples "http queue start" do - context "when request is nil" do - let(:request) { nil } - - it { is_expected.to be_nil } - end - - context "when env is nil" do - before { expect(request).to receive(:env).and_return(nil) } - - it { is_expected.to be_nil } - end - - context "with no relevant header set" do - let(:env) { {} } - - it { is_expected.to be_nil } - end - - context "with the HTTP_X_REQUEST_START header set" do - let(:env) { { "HTTP_X_REQUEST_START" => "t=#{slightly_earlier_time_value}" } } - - it { is_expected.to eq 1_389_783_599_600 } - - context "with unparsable content" do - let(:env) { { "HTTP_X_REQUEST_START" => "something" } } - - it { is_expected.to be_nil } - end - - context "with unparsable content at the end" do - let(:env) { { "HTTP_X_REQUEST_START" => "t=#{slightly_earlier_time_value}aaaa" } } - - it { is_expected.to eq 1_389_783_599_600 } - end - - context "with a really low number" do - let(:env) { { "HTTP_X_REQUEST_START" => "t=100" } } - - it { is_expected.to be_nil } - end - - context "with the alternate HTTP_X_QUEUE_START header set" do - let(:env) { { "HTTP_X_QUEUE_START" => "t=#{slightly_earlier_time_value}" } } - - it { is_expected.to eq 1_389_783_599_600 } - end - end - end - - context "time in milliseconds" do - let(:factor) { 1_000 } - - it_should_behave_like "http queue start" - end - - context "time in microseconds" do - let(:factor) { 1_000_000 } - - it_should_behave_like "http queue start" - end - end - - describe "#sanitized_params" do - let(:transaction) { new_transaction } - subject { transaction.send(:sanitized_params) } - - context "with params" do - before do - transaction.set_params(:foo => "bar", :baz => :bat) - end - - it "returns params" do - is_expected.to eq(:foo => "bar", :baz => :bat) - end - - context "with AppSignal filtering" do - before { Appsignal.config.config_hash[:filter_parameters] = %w[foo] } - after { Appsignal.config.config_hash[:filter_parameters] = [] } - - it "returns sanitized custom params" do - expect(subject).to eq(:foo => "[FILTERED]", :baz => :bat) - end - end - end - - context "params from request" do - let(:transaction) { legacy_new_transaction(:request => request, :options => options) } - let(:options) { {} } - let(:request) { rack_request(env) } - let(:env) { {} } - - context "without request params" do - before { allow(transaction.request).to receive(:params).and_return(nil) } - - it { is_expected.to be_nil } - end - - context "when request params crashes" do - before { expect(request).to receive(:params).and_raise(NoMethodError) } - - it { is_expected.to be_nil } - end - - context "when request params method does not exist" do - let(:options) { { :params_method => :nonsense } } - - it { is_expected.to be_nil } - end - - context "when not sending params" do - before { Appsignal.config.config_hash[:send_params] = false } - after { Appsignal.config.config_hash[:send_params] = true } - - it { is_expected.to be_nil } - end - - context "with an array" do - let(:request) { legacy_request(:params => %w[arg1 arg2]) } - - it { is_expected.to eq %w[arg1 arg2] } - - context "with AppSignal filtering" do - before { Appsignal.config.config_hash[:filter_parameters] = %w[foo] } - after { Appsignal.config.config_hash[:filter_parameters] = [] } - - it { is_expected.to eq %w[arg1 arg2] } - end - end - - context "with env" do - context "with sanitization" do - let(:request) { legacy_request(:params => { :foo => :bar }) } - - it "should call the params sanitizer" do - expect(subject).to eq(:foo => :bar) - end - end - - context "with AppSignal filtering" do - let(:request) { legacy_request(:params => { :foo => :bar, :baz => :bat }) } - before { Appsignal.config.config_hash[:filter_parameters] = %w[foo] } - after { Appsignal.config.config_hash[:filter_parameters] = [] } - - it "should call the params sanitizer with filtering" do - expect(subject).to eq(:foo => "[FILTERED]", :baz => :bat) - end - end - end - end - end - - describe "#sanitized_environment" do - let(:transaction) { legacy_new_transaction(:request => request) } - let(:request) { rack_request(env) } - let(:env) { {} } - let(:allowlisted_keys) { Appsignal.config[:request_headers] } - subject { transaction.send(:sanitized_environment) } - - context "when request is nil" do - let(:request) { nil } - - it { is_expected.to be_nil } - end - - context "when env is nil" do - before { expect(request).to receive(:env).and_return(nil) } - - it { is_expected.to be_nil } - end - - context "when env is present" do - let(:env) do - {}.tap do |hash| - allowlisted_keys.each { |o| hash[o] = 1 } # use all allowlisted keys - hash[allowlisted_keys] = nil # don't add if nil - hash[:not_allowlisted] = "I will be sanitized" - end - end - - it "only sets allowlisted keys" do - expect(subject.keys).to match_array(allowlisted_keys) - end - - context "with configured request_headers" do - before do - Appsignal.config.config_hash[:request_headers] = %w[CONTENT_LENGTH] - end - - it "only sets allowlisted keys" do - expect(subject.keys).to match_array(%w[CONTENT_LENGTH]) - end - end - end - end - - describe "#sanitized_session_data" do - let(:transaction) { legacy_new_transaction(:request => request) } - let(:request) { rack_request(env) } - let(:env) { {} } - subject { transaction.send(:sanitized_session_data) } - - context "when request is nil" do - let(:request) { nil } - - it { is_expected.to be_nil } - end - - context "when session is nil" do - before { expect(transaction.request).to receive(:session).and_return(nil) } - - it { is_expected.to be_nil } - end - - context "when session is empty" do - before { expect(transaction.request).to receive(:session).and_return({}) } - - it { is_expected.to eq({}) } - end - - context "when request class does not have a session method" do - let(:request) { Appsignal::Transaction::GenericRequest.new({}) } - - it { is_expected.to be_nil } - end - - context "with a session" do - let(:session_data_filter) { [] } - before { Appsignal.config[:filter_session_data] = session_data_filter } - after { Appsignal.config[:filter_session_data] = [] } - - context "with generic session object" do - before do - expect(transaction).to respond_to(:request) - allow(transaction).to receive_message_chain( - :request, - :session => { :foo => :bar, :abc => :def } - ) - allow(transaction).to receive_message_chain(:request, :fullpath => :bar) - end - - context "without session filtering" do - it "keeps the session data intact" do - expect(subject).to eq(:foo => :bar, :abc => :def) - end - end - - context "with session filtering" do - let(:session_data_filter) { %w[foo] } - - it "filters the session data" do - expect(subject).to eq(:foo => "[FILTERED]", :abc => :def) - end - end - end - - if defined? ActionDispatch::Request::Session - context "with ActionDispatch::Request::Session" do - let(:action_dispatch_session) do - store = Class.new do - def load_session(_env) - [1, { :foo => :bar, :abc => :def }] - end - - def session_exists?(_env) - true - end - end.new - ActionDispatch::Request::Session.create(store, - ActionDispatch::Request.new("rack.input" => StringIO.new), {}) - end - before do - expect(transaction).to respond_to(:request) - allow(transaction).to receive_message_chain( - :request, - :session => action_dispatch_session - ) - allow(transaction).to receive_message_chain(:request, :fullpath => :bar) - end - - context "without session filtering" do - it "keeps the session data intact" do - expect(subject).to eq("foo" => :bar, "abc" => :def) - end - end - - context "with session filtering" do - let(:session_data_filter) { %w[foo] } - - it "filters the session data" do - expect(subject).to eq("foo" => "[FILTERED]", "abc" => :def) - end - end - end - end - - context "when not sending session data" do - before { Appsignal.config[:send_session_data] = false } - - it "does not set any session data on the transaction" do - expect(subject).to be_nil - end - end - end - end - - describe "#sanitized_metadata" do - let(:transaction) { legacy_new_transaction(:request => request) } - let(:request) { rack_request(env) } - let(:env) { {} } - subject { transaction.send(:sanitized_metadata) } - - context "when request is nil" do - let(:request) { nil } - - it { is_expected.to be_nil } - end - - context "when env is nil" do - before { expect(request).to receive(:env).and_return(nil) } - - it { is_expected.to be_nil } - end - - context "when env is present" do - let(:env) { { :metadata => { "key" => "value" } } } - - it do - is_expected.to eq("key" => "value") - end - - context "with filter_metadata option set" do - before { Appsignal.config[:filter_metadata] = ["key"] } - after { Appsignal.config[:filter_metadata] = [] } - - it "filters out keys listed in the filter_metadata option" do - expect(subject.keys).to_not include("key") - end - end - end - end - describe "#cleaned_backtrace" do let(:transaction) { new_transaction } subject { transaction.send(:cleaned_backtrace, ["line 1", "line 2"]) } @@ -2324,7 +1537,7 @@ def session_exists?(_env) describe Appsignal::Transaction::NilTransaction do subject { Appsignal::Transaction::NilTransaction.new } - it "should have method stubs" do + it "has method stubs" do subject.complete subject.pause! subject.resume! diff --git a/spec/lib/appsignal_spec.rb b/spec/lib/appsignal_spec.rb index 132113e4b..c0794f88a 100644 --- a/spec/lib/appsignal_spec.rb +++ b/spec/lib/appsignal_spec.rb @@ -4,32 +4,14 @@ let(:transaction) { http_request_transaction } - describe ".config=" do + describe "._config=" do it "sets the config" do config = project_fixture_config expect(Appsignal.internal_logger).to_not receive(:level=) - silence { Appsignal.config = config } + Appsignal._config = config expect(Appsignal.config).to eq config end - - it "prints a deprecation warning" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - Appsignal.config = project_fixture_config - end - expect(err_stream.read).to include( - "appsignal WARNING: Configuring AppSignal with `Appsignal.config=` is deprecated." - ) - end - - it "logs a deprecation warning" do - logs = capture_logs { silence { Appsignal.config = project_fixture_config } } - expect(logs).to contains_log( - :warn, - "Configuring AppSignal with `Appsignal.config=` is deprecated." - ) - end end describe ".configure" do @@ -489,47 +471,6 @@ def on_start context "not active" do before { Appsignal._config = project_fixture_config("not_active") } - describe ".monitor_transaction" do - it "does not create a transaction" do - object = double(:some_method => 1) - - expect do - Appsignal.monitor_transaction("perform_job.nothing") do - object.some_method - end - end.to_not(change { created_transactions.count }) - end - - it "returns the block's return value" do - object = double(:some_method => 1) - - return_value = Appsignal.monitor_transaction("perform_job.nothing") do - object.some_method - end - expect(return_value).to eq 1 - end - - context "with an unknown event type" do - it "yields the given block" do - expect do |blk| - Appsignal.monitor_transaction("unknown.sidekiq", &blk) - end.to yield_control - end - - it "logs an error" do - logs = - capture_logs do - Appsignal.monitor_transaction("unknown.sidekiq") {} # rubocop:disable Lint/EmptyBlock - end - expect(logs).to contains_log( - :error, - "Unrecognized name 'unknown.sidekiq': names must start with either 'perform_job' " \ - "(for jobs and tasks) or 'process_action' (for HTTP requests)" - ) - end - end - end - describe ".listen_for_error" do let(:error) { ExampleException.new("specific error") } @@ -747,211 +688,6 @@ def on_start end end - describe ".monitor_transaction" do - it "prints a deprecation warning" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - Appsignal.monitor_transaction( - "perform_job.something", - :class => "BackgroundJob", - :method => "perform" - ) do - :return_value - end - end - - expect(err_stream.read).to include( - "appsignal WARNING: The `Appsignal.monitor_transaction` helper is deprecated." - ) - end - - it "logs a deprecation warning" do - logs = - capture_logs do - silence do - Appsignal.monitor_transaction( - "perform_job.something", - :class => "BackgroundJob", - :method => "perform" - ) do - :return_value - end - end - end - - expect(logs).to contains_log( - :warn, - "The `Appsignal.monitor_transaction` helper is deprecated." - ) - end - - context "with a successful call" do - it "instruments and completes for a background job" do - return_value = nil - expect do - return_value = - Appsignal.monitor_transaction( - "perform_job.something", - { - :class => "BackgroundJob", - :method => "perform", - :queue_start => fixed_time.to_i - } - ) do - :return_value - end - end.to(change { created_transactions.count }.by(1)) - expect(return_value).to eq(:return_value) - - transaction = last_transaction - expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB) - expect(transaction).to have_action("BackgroundJob#perform") - expect(transaction).to include_event("name" => "perform_job.something") - expect(transaction).to have_queue_start(1_389_783_600_000) - expect(transaction).to be_completed - end - - it "instruments and completes for a http request" do - return_value = nil - expect do - return_value = - Appsignal.monitor_transaction( - "process_action.something", - { - :controller => "BlogPostsController", - :action => "show", - "HTTP_X_REQUEST_START" => "t=#{fixed_time.to_i * 1000}" - } - ) do - :return_value - end - end.to(change { created_transactions.count }.by(1)) - expect(return_value).to eq(:return_value) - - transaction = last_transaction - expect(transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST) - expect(transaction).to have_action("BlogPostsController#show") - expect(transaction).to include_event("name" => "process_action.something") - expect(transaction).to have_queue_start(1_389_783_600_000) - expect(transaction).to be_completed - end - end - - context "with an erroring call" do - let(:error) { ExampleException.new("error message") } - - it "adds the error to the current transaction and complete" do - expect do - Appsignal.monitor_transaction("perform_job.something") do - raise error - end - end.to raise_error(error) - - expect(last_transaction).to have_error("ExampleException", "error message") - expect(last_transaction).to be_completed - end - end - - context "with an unknown event type" do - it "yields the given block" do - expect do |blk| - Appsignal.monitor_transaction("unknown.sidekiq", &blk) - end.to yield_control - end - - it "logs an error" do - logs = - capture_logs do - Appsignal.monitor_transaction("unknown.sidekiq") {} # rubocop:disable Lint/EmptyBlock - end - expect(logs).to contains_log( - :error, - "Unrecognized name 'unknown.sidekiq': names must start with either 'perform_job' " \ - "(for jobs and tasks) or 'process_action' (for HTTP requests)" - ) - end - end - end - - describe ".monitor_single_transaction" do - it "prints a deprecation warning" do - err_stream = std_stream - capture_std_streams(std_stream, err_stream) do - Appsignal.monitor_single_transaction( - "perform_job.something", - :class => "BackgroundJob", - :method => "perform" - ) do - :return_value - end - end - - expect(err_stream.read).to include( - "appsignal WARNING: The `Appsignal.monitor_single_transaction` helper is deprecated." - ) - end - - it "logs a deprecation warning" do - logs = - capture_logs do - silence do - Appsignal.monitor_single_transaction( - "perform_job.something", - :class => "BackgroundJob", - :method => "perform" - ) do - :return_value - end - end - end - - expect(logs).to contains_log( - :warn, - "The `Appsignal.monitor_single_transaction` helper is deprecated." - ) - end - - context "with a successful call" do - it "calls monitor_transaction and Appsignal.stop" do - expect(Appsignal).to receive(:stop) - - Appsignal.monitor_single_transaction( - "perform_job.something", - :controller => :my_controller, - :action => :my_action - ) do - # nothing - end - - transaction = last_transaction - expect(transaction).to have_action("my_controller#my_action") - expect(transaction).to include_event("name" => "perform_job.something") - end - end - - context "with an erroring call" do - let(:error) { ExampleException.new } - - it "calls monitor_transaction and stop and re-raises the error" do - expect(Appsignal).to receive(:stop) - - expect do - Appsignal.monitor_single_transaction( - "perform_job.something", - :controller => :my_controller, - :action => :my_action - ) do - raise error - end - end.to raise_error(error) - - transaction = last_transaction - expect(transaction).to have_action("my_controller#my_action") - expect(transaction).to include_event("name" => "perform_job.something") - end - end - end - describe ".tag_request" do before { start_agent } @@ -1208,50 +944,6 @@ def on_start end end - describe ".set_host_gauge" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:log_stream) { StringIO.new } - let(:logs) { log_contents(log_stream) } - let(:deprecation_message) do - "The `set_host_gauge` method has been deprecated. " \ - "Calling this method has no effect. " \ - "Please remove method call in the following file to remove " \ - "this message." - end - before do - Appsignal.internal_logger = test_logger(log_stream) - capture_std_streams(std_stream, err_stream) { Appsignal.set_host_gauge("key", 0.1) } - end - - it "logs a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - - describe ".set_process_gauge" do - let(:err_stream) { std_stream } - let(:stderr) { err_stream.read } - let(:log_stream) { StringIO.new } - let(:logs) { log_contents(log_stream) } - let(:deprecation_message) do - "The `set_process_gauge` method has been deprecated. " \ - "Calling this method has no effect. " \ - "Please remove method call in the following file to remove " \ - "this message." - end - before do - Appsignal.internal_logger = test_logger(log_stream) - capture_std_streams(std_stream, err_stream) { Appsignal.set_process_gauge("key", 0.1) } - end - - it "logs a deprecation warning" do - expect(stderr).to include("appsignal WARNING: #{deprecation_message}") - expect(logs).to include(deprecation_message) - end - end - describe ".increment_counter" do it "should call increment_counter on the extension with a string key" do expect(Appsignal::Extension).to receive(:increment_counter) @@ -1387,56 +1079,6 @@ def on_start end end - context "with tags" do - let(:tags) { { :a => "a", :b => "b" } } - - it "prints a deprecation warning and tags the transaction" do - logs = capture_logs do - expect do - capture_std_streams(std_stream, err_stream) do - Appsignal.send_error(error, tags) - end - end.to change { created_transactions.count }.by(1) - end - - expect(last_transaction).to include_tags("a" => "a", "b" => "b") - - message = "The tags argument for `Appsignal.send_error` is deprecated. " \ - "Please use the block method to set tags instead.\n\n" \ - " Appsignal.send_error(error) do |transaction|\n" \ - " transaction.set_tags(#{tags.inspect})\n" \ - " end\n\n" \ - "Appsignal.send_error called on location: #{__FILE__}:" - expect(stderr).to include("appsignal WARNING: #{message}") - expect(logs).to include(message) - end - end - - context "with namespace" do - let(:namespace) { "admin" } - - it "prints a deprecation warning and sets the namespace on the transaction" do - logs = capture_logs do - expect do - capture_std_streams(std_stream, err_stream) do - Appsignal.send_error(error, nil, namespace) - end - end.to change { created_transactions.count }.by(1) - end - - expect(last_transaction).to have_namespace(namespace) - - message = "The namespace argument for `Appsignal.send_error` is deprecated. " \ - "Please use the block method to set the namespace instead.\n\n" \ - " Appsignal.send_error(error) do |transaction|\n" \ - " transaction.set_namespace(#{namespace.inspect})\n" \ - " end\n\n" \ - "Appsignal.send_error called on location: #{__FILE__}:" - expect(stderr).to include("appsignal WARNING: #{message}") - expect(logs).to include(message) - end - end - context "when given a block" do it "yields the transaction and allows additional metadata to be set" do keep_transactions do @@ -1545,68 +1187,6 @@ def on_start end end - context "with tags" do - let(:tags) { { "foo" => "bar" } } - - it "tags the transaction" do - silence(:allowed => ["set_error", "The tags argument for"]) do - Appsignal.set_error(error, tags) - end - - transaction._sample - expect(transaction).to have_error(error) - expect(transaction).to include_tags(tags) - end - - it "prints a deprecation warning and tags the transaction" do - logs = capture_logs do - capture_std_streams(std_stream, err_stream) do - Appsignal.set_error(error, tags) - end - end - - message = "The tags argument for `Appsignal.set_error` is deprecated. " \ - "Please use the block method to set tags instead.\n\n" \ - " Appsignal.set_error(error) do |transaction|\n" \ - " transaction.set_tags(#{tags.inspect})\n" \ - " end\n\n" \ - "Appsignal.set_error called on location: #{__FILE__}:" - expect(stderr).to include("appsignal WARNING: #{message}") - expect(logs).to include(message) - end - end - - context "with namespace" do - let(:namespace) { "admin" } - - it "sets the namespace on the transaction" do - silence(:allowed => ["set_error", "The namespace argument for"]) do - Appsignal.set_error(error, nil, namespace) - end - - expect(transaction).to have_error("ExampleException", "I am an exception") - expect(transaction).to have_namespace(namespace) - expect(transaction).to_not include_tags - end - - it "prints a deprecation warning andsets the namespace on the transaction" do - logs = capture_logs do - capture_std_streams(std_stream, err_stream) do - Appsignal.set_error(error, nil, namespace) - end - end - - message = "The namespace argument for `Appsignal.set_error` is deprecated. " \ - "Please use the block method to set the namespace instead.\n\n" \ - " Appsignal.set_error(error) do |transaction|\n" \ - " transaction.set_namespace(#{namespace.inspect})\n" \ - " end\n\n" \ - "Appsignal.set_error called on location: #{__FILE__}:" - expect(stderr).to include("appsignal WARNING: #{message}") - expect(logs).to include(message) - end - end - context "when given a block" do it "yields the transaction and allows additional metadata to be set" do Appsignal.set_error(StandardError.new("my_error")) do |t| @@ -1829,30 +1409,6 @@ def on_start expect(transaction).to include_event("name" => "register.this.event") expect(transaction).to_not include_event("name" => "dont.register.this.event") end - - it "has a without_instrumentation alias that prints a deprecation warning" do - Appsignal.instrument("register.this.event") { :do_nothing } - err_stream = std_stream - logs = - capture_logs do - capture_std_streams(std_stream, err_stream) do - Appsignal.without_instrumentation do - Appsignal.instrument("dont.register.this.event") { :do_nothing } - end - end - end - - expect(transaction).to include_event("name" => "register.this.event") - expect(transaction).to_not include_event("name" => "dont.register.this.event") - - expect(logs).to contains_log( - :warn, - "The `Appsignal.without_instrumentation` helper is deprecated." - ) - expect(err_stream.read).to include( - "appsignal WARNING: The `Appsignal.without_instrumentation` helper is deprecated." - ) - end end context "without current transaction" do @@ -1865,24 +1421,6 @@ def on_start end end - describe ".start_logger" do - let(:stderr_stream) { std_stream } - let(:stderr) { stderr_stream.read } - let(:log_stream) { std_stream } - let(:log) { log_contents(log_stream) } - - it "prints and logs a deprecation warning" do - use_logger_with(log_stream) do - capture_std_streams(std_stream, stderr_stream) do - Appsignal.start_logger - end - end - expect(stderr) - .to include("appsignal WARNING: Calling 'Appsignal.start_logger' is deprecated.") - expect(log).to contains_log(:warn, "Calling 'Appsignal.start_logger' is deprecated.") - end - end - describe "._start_logger" do let(:out_stream) { std_stream } let(:output) { out_stream.read } diff --git a/spec/support/helpers/transaction_helpers.rb b/spec/support/helpers/transaction_helpers.rb index a1aa30cd5..37bed1d1d 100644 --- a/spec/support/helpers/transaction_helpers.rb +++ b/spec/support/helpers/transaction_helpers.rb @@ -19,28 +19,6 @@ def new_transaction(namespace = default_namespace) Appsignal::Transaction.new(SecureRandom.uuid, namespace) end - def legacy_create_transaction( - id: "mock_transaction_id", - namespace: "mock_namespace", - request: legacy_request, - options: {} - ) - Appsignal::Transaction.create(id, namespace, request, options) - end - - def legacy_new_transaction( - id: "mock_transaction_id", - namespace: "mock_namespace", - request: legacy_request, - options: {} - ) - Appsignal::Transaction.new(id, namespace, request, options) - end - - def legacy_request(env = {}) - Appsignal::Transaction::InternalGenericRequest.new(env) - end - def rack_request(env) Rack::Request.new(env) end diff --git a/spec/support/testing.rb b/spec/support/testing.rb index 945b3f087..6348d4f48 100644 --- a/spec/support/testing.rb +++ b/spec/support/testing.rb @@ -171,7 +171,7 @@ module ClassMethods # transactions are created on the {Appsignal::Testing.transactions} list. # # @see TransactionHelpers#last_transaction - def new(*_args) + def new(...) transaction = super Appsignal::Testing.transactions << transaction transaction @@ -180,7 +180,7 @@ def new(*_args) module InstanceMethods def _sample - _sample_data + sample_data end end end