From fc567cb0b78c03de6241285744d1e8cecb3331f8 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Fri, 15 May 2020 10:47:28 +0100 Subject: [PATCH 01/44] Update Rubocop version and todo file We only need this for development and run it on the latest version of Ruby on CI, so there's no reason not to use the latest Rubocop version The TODO file has grown, we should look at fixing these (a lot of them can be autofixed) --- .rubocop.yml | 35 +++ .rubocop_todo.yml | 689 +++++++++++++++++++++++++++++++++++----------- Gemfile | 2 +- 3 files changed, 569 insertions(+), 157 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3ffe2b0d8..90207c269 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,37 @@ inherit_from: .rubocop_todo.yml +AllCops: + Exclude: + - 'bin/**/*' + - 'example/**/*' + - 'spec/fixtures/**/*' + - 'features/fixtures/**/*' + +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: true + +Layout/SpaceAroundMethodCallOperator: + Enabled: true + +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + +Style/ExponentialNotation: + Enabled: false + +Style/HashEachMethods: + Enabled: true + +# These require newer version of Ruby than our minimum supported version, so +# have to be disabled +Style/HashTransformKeys: # Requires Ruby 2.5 + Enabled: false + +Style/HashTransformValues: # Requires Ruby 2.4 + Enabled: false + +Style/SlicingWithRange: # Requires Ruby 2.6 + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4715394ab..56e603421 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,40 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-02-06 11:17:57 +0000 using RuboCop version 0.52.1. +# on 2020-05-15 11:04:08 +0100 using RuboCop version 0.83.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 3 +# Configuration parameters: Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/DuplicatedGem: + Exclude: + - 'Gemfile' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'bugsnag.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/BlockEndNewline: + Exclude: + - 'spec/integrations/mongo_spec.rb' + - 'spec/report_spec.rb' + # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. @@ -14,16 +43,45 @@ Layout/CaseIndentation: Exclude: - 'lib/bugsnag/cleaner.rb' -# Offense count: 3 +# Offense count: 15 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/bugsnag.rb' + - 'lib/bugsnag/cleaner.rb' + - 'lib/bugsnag/delivery/thread_queue.rb' + - 'lib/bugsnag/helpers.rb' + - 'lib/bugsnag/session_tracker.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'spec/breadcrumbs/validator_spec.rb' + - 'spec/bugsnag_spec.rb' + - 'spec/configuration_spec.rb' + - 'spec/integrations/mongo_spec.rb' + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/resque_spec.rb' + - 'spec/integrations/shoryuken_spec.rb' + - 'spec/middleware/exception_meta_data_spec.rb' + - 'spec/report_spec.rb' + - 'spec/session_tracker_spec.rb' + +# Offense count: 5 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: + - 'features/steps/ruby_notifier_steps.rb' - 'lib/bugsnag/helpers.rb' - 'lib/bugsnag/integrations/mailman.rb' - 'lib/bugsnag/stacktrace.rb' + - 'spec/integrations/mailman_spec.rb' # Offense count: 4 # Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: around, only_before Layout/EmptyLinesAroundAccessModifier: Exclude: - 'lib/bugsnag/delivery.rb' @@ -31,25 +89,38 @@ Layout/EmptyLinesAroundAccessModifier: - 'lib/bugsnag/middleware_stack.rb' - 'lib/bugsnag/session_tracker.rb' -# Offense count: 1 +# Offense count: 2 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundAttributeAccessor: + Exclude: + - 'lib/bugsnag/configuration.rb' + - 'spec/report_spec.rb' + +# Offense count: 24 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines Layout/EmptyLinesAroundBlockBody: Exclude: - 'lib/bugsnag/middleware/classify_error.rb' - -# Offense count: 11 + - 'spec/bugsnag_spec.rb' + - 'spec/helper_spec.rb' + - 'spec/integration_spec.rb' + - 'spec/integrations/logger_spec.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/integrations/rails3_request_spec.rb' + - 'spec/middleware_spec.rb' + - 'spec/report_spec.rb' + +# Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only Layout/EmptyLinesAroundClassBody: Exclude: - - 'lib/bugsnag/integrations/delayed_job.rb' - 'lib/bugsnag/integrations/mailman.rb' - 'lib/bugsnag/integrations/rack.rb' - 'lib/bugsnag/integrations/railtie.rb' - - 'lib/bugsnag/integrations/rake.rb' - 'lib/bugsnag/integrations/resque.rb' - 'lib/bugsnag/integrations/shoryuken.rb' - 'lib/bugsnag/integrations/sidekiq.rb' @@ -57,12 +128,6 @@ Layout/EmptyLinesAroundClassBody: - 'lib/bugsnag/session_tracker.rb' - 'lib/bugsnag/stacktrace.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundExceptionHandlingKeywords: - Exclude: - - 'lib/bugsnag/integrations/rake.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -71,26 +136,54 @@ Layout/EmptyLinesAroundModuleBody: Exclude: - 'lib/bugsnag/integrations/rails/controller_methods.rb' +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'lib/bugsnag/cleaner.rb' + # Offense count: 1 # Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'Rakefile' + +# Offense count: 7 +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/IndentArray: +Layout/FirstArrayElementIndentation: Exclude: - 'lib/bugsnag/middleware/classify_error.rb' + - 'spec/report_spec.rb' + - 'spec/stacktrace_spec.rb' -# Offense count: 12 +# Offense count: 164 # Cop supports --auto-correct. # Configuration parameters: IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/IndentHash: +Layout/FirstHashElementIndentation: EnforcedStyle: consistent +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/bugsnag/delivery/synchronous.rb' + - 'spec/integrations/rake_spec.rb' + # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: +# SupportedStyles: squiggly, active_support, powerpack, unindent +Layout/HeredocIndentation: Exclude: - 'lib/generators/bugsnag/bugsnag_generator.rb' @@ -101,11 +194,23 @@ Layout/IndentationWidth: Exclude: - 'lib/bugsnag/cleaner.rb' -# Offense count: 2 +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'spec/integration_spec.rb' + - 'spec/integrations/mailman_spec.rb' + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/resque_spec.rb' + +# Offense count: 4 # Cop supports --auto-correct. Layout/MultilineBlockLayout: Exclude: - 'lib/bugsnag/middleware/classify_error.rb' + - 'spec/integrations/mongo_spec.rb' + - 'spec/report_spec.rb' # Offense count: 3 # Cop supports --auto-correct. @@ -124,7 +229,13 @@ Layout/SpaceAfterComma: - 'lib/bugsnag/middleware_stack.rb' - 'lib/bugsnag/report.rb' -# Offense count: 5 +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterNot: + Exclude: + - 'features/steps/ruby_notifier_steps.rb' + +# Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: space, no_space @@ -136,7 +247,20 @@ Layout/SpaceAroundEqualsInParameterDefault: - 'lib/bugsnag/integrations/rake.rb' - 'lib/bugsnag/report.rb' -# Offense count: 2 +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'spec/bugsnag_spec.rb' + - 'spec/integrations/rake_spec.rb' + - 'spec/integrations/sidekiq_spec.rb' + - 'spec/report_spec.rb' + +# Offense count: 89 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space @@ -145,120 +269,178 @@ Layout/SpaceBeforeBlockBraces: Exclude: - 'lib/bugsnag/middleware/suggestion_data.rb' - 'lib/bugsnag/middleware_stack.rb' - -# Offense count: 23 + - 'spec/bugsnag_spec.rb' + - 'spec/configuration_spec.rb' + - 'spec/helper_spec.rb' + - 'spec/integration_spec.rb' + - 'spec/integrations/mailman_spec.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/integrations/rake_spec.rb' + - 'spec/integrations/sidekiq_spec.rb' + - 'spec/middleware_spec.rb' + - 'spec/report_spec.rb' + - 'spec/session_tracker_spec.rb' + - 'spec/stacktrace_spec.rb' + +# Offense count: 48 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # SupportedStyles: space, no_space # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/bugsnag.rb' - - 'lib/bugsnag/cleaner.rb' - - 'lib/bugsnag/helpers.rb' - - 'lib/bugsnag/integrations/shoryuken.rb' - - 'lib/bugsnag/middleware/callbacks.rb' - - 'lib/bugsnag/middleware/rack_request.rb' - - 'lib/bugsnag/middleware/warden_user.rb' - - 'lib/bugsnag/middleware_stack.rb' - - 'lib/bugsnag/report.rb' - - 'lib/bugsnag/stacktrace.rb' + Enabled: false -# Offense count: 22 +# Offense count: 162 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space, compact # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/bugsnag.rb' - - 'lib/bugsnag/cleaner.rb' - - 'lib/bugsnag/integrations/resque.rb' - - 'lib/bugsnag/middleware/exception_meta_data.rb' - - 'lib/bugsnag/middleware/mailman.rb' - - 'lib/bugsnag/middleware/suggestion_data.rb' - - 'lib/bugsnag/middleware/warden_user.rb' - - 'lib/bugsnag/report.rb' - - 'lib/bugsnag/session_tracker.rb' + Enabled: false -# Offense count: 2 +# Offense count: 3 # Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space Layout/SpaceInsideParens: Exclude: - 'lib/bugsnag/stacktrace.rb' + - 'spec/integrations/shoryuken_spec.rb' -# Offense count: 4 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: final_newline, final_blank_line -Layout/TrailingBlankLines: +Layout/TrailingEmptyLines: Exclude: - - 'lib/bugsnag/integrations/que.rb' - 'lib/bugsnag/session_tracker.rb' - 'lib/bugsnag/tasks.rb' - 'lib/bugsnag/version.rb' + - 'spec/breadcrumbs/breadcrumb_spec.rb' + - 'spec/breadcrumbs/validator_spec.rb' + - 'spec/middleware_stack_spec.rb' + - 'spec/spec_helper.rb' + - 'spec/utility/circular_buffer_spec.rb' -# Offense count: 2 +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'spec/integrations/clearance_user_spec.rb' + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/rake_spec.rb' + - 'spec/integrations/shoryuken_spec.rb' + - 'spec/integrations/warden_user_spec.rb' + +# Offense count: 90 Lint/AmbiguousBlockAssociation: Exclude: - 'lib/bugsnag/delivery/thread_queue.rb' - 'lib/bugsnag/middleware/suggestion_data.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/integrations/rails3_request_spec.rb' + - 'spec/integrations/sidekiq_spec.rb' + - 'spec/middleware_spec.rb' + - 'spec/report_spec.rb' + - 'spec/session_tracker_spec.rb' + - 'spec/stacktrace_spec.rb' -# Offense count: 4 +# Offense count: 3 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Exclude: - 'lib/bugsnag/delivery/thread_queue.rb' - 'lib/bugsnag/helpers.rb' - - 'lib/bugsnag/integrations/delayed_job.rb' # Offense count: 2 -Lint/DuplicateMethods: +# Cop supports --auto-correct. +Lint/BooleanSymbol: Exclude: - - 'lib/bugsnag/configuration.rb' + - 'spec/breadcrumbs/validator_spec.rb' -# Offense count: 2 +# Offense count: 15 +Lint/IneffectiveAccessModifier: + Exclude: + - 'lib/bugsnag/helpers.rb' + +# Offense count: 1 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Lint/EndAlignment: +# Configuration parameters: EnforcedStyle. +# SupportedStyles: runtime_error, standard_error +Lint/InheritException: Exclude: - - 'lib/bugsnag/cleaner.rb' + - 'spec/report_spec.rb' -# Offense count: 2 -Lint/HandleExceptions: +# Offense count: 1 +# Cop supports --auto-correct. +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/report_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Lint/RedundantRequireStatement: Exclude: - 'lib/bugsnag.rb' - - 'lib/bugsnag/tasks/bugsnag.rake' + - 'lib/bugsnag/delivery/thread_queue.rb' + - 'lib/bugsnag/session_tracker.rb' -# Offense count: 10 -Lint/IneffectiveAccessModifier: +# Offense count: 1 +# Cop supports --auto-correct. +Lint/RedundantStringCoercion: Exclude: - - 'lib/bugsnag/helpers.rb' + - 'features/support/env.rb' -# Offense count: 5 +# Offense count: 12 Lint/RescueException: Exclude: + - 'lib/bugsnag/integrations/delayed_job.rb' - 'lib/bugsnag/integrations/mailman.rb' - 'lib/bugsnag/integrations/rack.rb' - 'lib/bugsnag/integrations/rake.rb' - 'lib/bugsnag/integrations/shoryuken.rb' - 'lib/bugsnag/integrations/sidekiq.rb' - - 'lib/bugsnag/integrations/delayed_job.rb' + - 'spec/middleware_spec.rb' + - 'spec/report_spec.rb' + - 'spec/stacktrace_spec.rb' -# Offense count: 6 +# Offense count: 1 +# Cop supports --auto-correct. +Lint/SendWithMixinArgument: + Exclude: + - 'lib/bugsnag/integrations/rake.rb' + +# Offense count: 2 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'lib/bugsnag.rb' + - 'lib/bugsnag/tasks/bugsnag.rake' + +# Offense count: 103 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: + - 'features/support/env.rb' - 'lib/bugsnag/configuration.rb' - 'lib/bugsnag/helpers.rb' - 'lib/bugsnag/middleware_stack.rb' - 'lib/bugsnag/report.rb' + - 'spec/bugsnag_spec.rb' + - 'spec/helper_spec.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/integrations/rails3_request_spec.rb' + - 'spec/integrations/sidekiq_spec.rb' + - 'spec/middleware_spec.rb' + - 'spec/report_spec.rb' + - 'spec/session_tracker_spec.rb' + - 'spec/stacktrace_spec.rb' # Offense count: 3 # Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: - 'lib/bugsnag.rb' @@ -266,53 +448,59 @@ Lint/UnusedMethodArgument: - 'lib/bugsnag/integrations/sidekiq.rb' # Offense count: 1 +# Cop supports --auto-correct. # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. Lint/UselessAccessModifier: Exclude: - 'lib/bugsnag/helpers.rb' -# Offense count: 25 +# Offense count: 4 +Lint/UselessAssignment: + Exclude: + - 'features/steps/ruby_notifier_steps.rb' + - 'spec/breadcrumbs/breadcrumb_spec.rb' + - 'spec/session_tracker_spec.rb' + +# Offense count: 33 +# Configuration parameters: IgnoredMethods. Metrics/AbcSize: - Max: 86 + Max: 68 -# Offense count: 1 +# Offense count: 74 # Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: - Max: 30 + Max: 1026 -# Offense count: 2 +# Offense count: 1 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 4 -# Offense count: 3 +# Offense count: 4 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 149 - Exclude: - - 'lib/bugsnag/report.rb' - - 'lib/bugsnag/configuration.rb' + Max: 174 -# Offense count: 12 +# Offense count: 15 +# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: - Max: 19 + Max: 18 -# Offense count: 34 -# Configuration parameters: CountComments. +# Offense count: 42 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: - Max: 55 + Max: 54 -# Offense count: 1 +# Offense count: 3 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 125 - Exclude: - - 'lib/bugsnag/helpers.rb' - - 'lib/bugsnag.rb' + Max: 152 -# Offense count: 11 +# Offense count: 15 +# Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 21 + Max: 20 # Offense count: 2 Naming/AccessorMethodName: @@ -320,24 +508,57 @@ Naming/AccessorMethodName: - 'lib/bugsnag/session_tracker.rb' # Offense count: 1 -# Configuration parameters: Blacklist. -# Blacklist: END, (?-mix:EO[A-Z]{1}) +Naming/ConstantName: + Exclude: + - 'spec/integrations/que_spec.rb' + +# Offense count: 1 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: Exclude: - 'lib/generators/bugsnag/bugsnag_generator.rb' # Offense count: 1 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/bugsnag.rb' + +# Offense count: 1 +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. # NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? +# ForbiddenPrefixes: is_, has_, have_ +# AllowedMethods: is_a? # MethodDefinitionMacros: define_method, define_singleton_method Naming/PredicateName: Exclude: - 'spec/**/*' - 'lib/bugsnag/helpers.rb' -# Offense count: 5 +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'lib/bugsnag/integrations/delayed_job.rb' + - 'lib/bugsnag/integrations/mailman.rb' + - 'lib/bugsnag/integrations/rack.rb' + - 'lib/bugsnag/integrations/rails/active_record_rescue.rb' + - 'lib/bugsnag/integrations/rake.rb' + - 'lib/bugsnag/integrations/shoryuken.rb' + - 'lib/bugsnag/integrations/sidekiq.rb' + - 'lib/bugsnag/middleware/rack_request.rb' + +# Offense count: 3 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, normalcase, non_integer +Naming/VariableNumber: + Exclude: + - 'spec/breadcrumbs/validator_spec.rb' + +# Offense count: 20 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: prefer_alias, prefer_alias_method @@ -346,8 +567,14 @@ Style/Alias: - 'lib/bugsnag/configuration.rb' - 'lib/bugsnag/integrations/rake.rb' - 'lib/bugsnag/session_tracker.rb' + - 'spec/bugsnag_spec.rb' + - 'spec/integrations/mailman_spec.rb' + - 'spec/integrations/mongo_spec.rb' + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/resque_spec.rb' + - 'spec/integrations/shoryuken_spec.rb' -# Offense count: 2 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals @@ -355,35 +582,30 @@ Style/AndOr: Exclude: - 'lib/bugsnag.rb' - 'lib/bugsnag/helpers.rb' + - 'spec/spec_helper.rb' -# Offense count: 2 +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Exclude: + - 'features/steps/ruby_notifier_steps.rb' + +# Offense count: 5 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object # FunctionalMethods: let, let!, subject, watch # IgnoredMethods: lambda, proc, it Style/BlockDelimiters: Exclude: - 'lib/bugsnag/middleware/classify_error.rb' + - 'spec/integrations/mongo_spec.rb' + - 'spec/report_spec.rb' -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'lib/bugsnag/integrations/resque.rb' - - 'lib/bugsnag/integrations/shoryuken.rb' - - 'lib/bugsnag/integrations/sidekiq.rb' - - 'lib/bugsnag/middleware/mailman.rb' - - 'lib/bugsnag/middleware/rack_request.rb' - - 'lib/bugsnag/middleware/rails3_request.rb' - - 'lib/bugsnag/middleware/rake.rb' - - 'lib/bugsnag/middleware/suggestion_data.rb' - - 'lib/bugsnag/middleware/warden_user.rb' - -# Offense count: 16 +# Offense count: 27 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact @@ -398,19 +620,27 @@ Style/ClassCheck: Exclude: - 'lib/bugsnag/cleaner.rb' -# Offense count: 6 +# Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: + - 'features/steps/ruby_notifier_steps.rb' - 'lib/bugsnag.rb' - 'lib/bugsnag/cleaner.rb' - 'lib/bugsnag/delivery/synchronous.rb' - 'lib/bugsnag/middleware_stack.rb' - 'lib/bugsnag/report.rb' + - 'spec/report_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/Dir: + Exclude: + - 'spec/report_spec.rb' -# Offense count: 38 +# Offense count: 22 Style/Documentation: Enabled: false @@ -422,15 +652,55 @@ Style/EmptyElse: Exclude: - 'lib/bugsnag/stacktrace.rb' +# Offense count: 15 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'Rakefile' + - 'spec/breadcrumbs/breadcrumb_spec.rb' + - 'spec/breadcrumbs/validator_spec.rb' + - 'spec/bugsnag_spec.rb' + - 'spec/cleaner_spec.rb' + - 'spec/configuration_spec.rb' + - 'spec/helper_spec.rb' + - 'spec/integrations/mongo_spec.rb' + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/resque_spec.rb' + - 'spec/integrations/shoryuken_spec.rb' + - 'spec/middleware/exception_meta_data_spec.rb' + - 'spec/report_spec.rb' + - 'spec/session_tracker_spec.rb' + - 'spec/utility/circular_buffer_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'lib/generators/bugsnag/bugsnag_generator.rb' + +# Offense count: 80 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + # Offense count: 3 +# Configuration parameters: AllowedVariables. +Style/GlobalVars: + Exclude: + - 'features/steps/ruby_notifier_steps.rb' + - 'features/support/env.rb' + +# Offense count: 5 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - 'lib/bugsnag.rb' - - 'lib/bugsnag/integrations/delayed_job.rb' - 'lib/bugsnag/integrations/resque.rb' + - 'spec/spec_helper.rb' -# Offense count: 98 +# Offense count: 547 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys @@ -438,11 +708,12 @@ Style/HashSyntax: Enabled: false # Offense count: 1 +# Configuration parameters: AllowIfModifier. Style/IfInsideElse: Exclude: - 'lib/bugsnag/session_tracker.rb' -# Offense count: 15 +# Offense count: 14 # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: @@ -452,21 +723,38 @@ Style/IfUnlessModifier: - 'lib/bugsnag/integrations/rack.rb' - 'lib/bugsnag/integrations/resque.rb' - 'lib/bugsnag/middleware/callbacks.rb' - - 'lib/bugsnag/middleware/exception_meta_data.rb' - 'lib/bugsnag/middleware/rack_request.rb' - 'lib/bugsnag/session_tracker.rb' - 'lib/bugsnag/stacktrace.rb' + - 'spec/cleaner_spec.rb' -# Offense count: 6 +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'spec/integrations/rack_spec.rb' + - 'spec/middleware/exception_meta_data_spec.rb' + +# Offense count: 8 # Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. Style/MethodCallWithoutArgsParentheses: Exclude: - 'lib/bugsnag/delivery/synchronous.rb' - 'lib/bugsnag/report.rb' - 'lib/bugsnag/session_tracker.rb' + - 'spec/integrations/rake_spec.rb' + - 'spec/integrations/shoryuken_spec.rb' # Offense count: 1 -Style/MethodMissing: +Style/MethodMissingSuper: + Exclude: + - 'lib/bugsnag/middleware_stack.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: Exclude: - 'lib/bugsnag/middleware_stack.rb' @@ -481,8 +769,10 @@ Style/MultilineIfModifier: Exclude: - 'lib/bugsnag/integrations/rails/controller_methods.rb' -# Offense count: 29 +# Offense count: 53 # Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict Style/MutableConstant: Enabled: false @@ -492,8 +782,17 @@ Style/MutableConstant: # SupportedStyles: both, prefix, postfix Style/NegatedIf: Exclude: - - 'lib/bugsnag.rb' - 'lib/bugsnag/session_tracker.rb' + - 'spec/middleware_spec.rb' + - 'spec/stacktrace_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowedMethods. +# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with +Style/NestedParenthesizedCalls: + Exclude: + - 'spec/session_tracker_spec.rb' # Offense count: 2 # Cop supports --auto-correct. @@ -511,20 +810,23 @@ Style/NonNilCheck: Exclude: - 'lib/bugsnag/report.rb' -# Offense count: 1 +# Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: Strict. Style/NumericLiterals: MinDigits: 7 -# Offense count: 1 +# Offense count: 6 # Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. # SupportedStyles: predicate, comparison Style/NumericPredicate: Exclude: - 'spec/**/*' + - 'Rakefile' + - 'lib/bugsnag.rb' - 'lib/bugsnag/session_tracker.rb' + - 'lib/bugsnag/utility/circular_buffer.rb' # Offense count: 2 # Cop supports --auto-correct. @@ -532,19 +834,36 @@ Style/ParallelAssignment: Exclude: - 'lib/bugsnag/stacktrace.rb' +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'features/steps/ruby_notifier_steps.rb' + # Offense count: 6 # Cop supports --auto-correct. Style/PerlBackrefs: Exclude: - 'lib/bugsnag/stacktrace.rb' -# Offense count: 1 +# Offense count: 8 +# Cop supports --auto-correct. +Style/Proc: + Exclude: + - 'spec/bugsnag_spec.rb' + - 'spec/report_spec.rb' + +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: compact, exploded Style/RaiseArgs: Exclude: - 'lib/bugsnag/tasks/bugsnag.rake' + - 'spec/bugsnag_spec.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/integrations/rails3_request_spec.rb' # Offense count: 4 # Cop supports --auto-correct. @@ -553,7 +872,7 @@ Style/RedundantBegin: - 'lib/bugsnag/delivery/synchronous.rb' - 'lib/bugsnag/integrations/mailman.rb' - 'lib/bugsnag/integrations/shoryuken.rb' - - 'lib/bugsnag/integrations/sidekiq.rb' + - 'spec/bugsnag_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -561,32 +880,41 @@ Style/RedundantException: Exclude: - 'lib/bugsnag/tasks/bugsnag.rake' -# Offense count: 11 +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'spec/helper_spec.rb' + +# Offense count: 13 # Cop supports --auto-correct. Style/RedundantSelf: Exclude: - 'lib/bugsnag/configuration.rb' - - 'lib/bugsnag/integrations/railtie.rb' -# Offense count: 2 +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: + - 'features/steps/ruby_notifier_steps.rb' - 'lib/bugsnag/stacktrace.rb' + - 'spec/report_spec.rb' + - 'spec/stacktrace_spec.rb' -# Offense count: 6 +# Offense count: 11 # Cop supports --auto-correct. Style/RescueModifier: Exclude: - - 'lib/bugsnag/cleaner.rb' - 'lib/bugsnag/middleware/rack_request.rb' - 'lib/bugsnag/middleware/rails3_request.rb' - 'lib/bugsnag/middleware/warden_user.rb' - 'lib/bugsnag/stacktrace.rb' + - 'spec/integrations/rack_spec.rb' + - 'spec/stacktrace_spec.rb' -# Offense count: 5 +# Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit @@ -596,36 +924,65 @@ Style/RescueStandardError: - 'lib/bugsnag/integrations/railtie.rb' - 'lib/bugsnag/stacktrace.rb' - 'lib/bugsnag/tasks/bugsnag.rake' + - 'spec/bugsnag_spec.rb' + - 'spec/report_spec.rb' -# Offense count: 1 +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/bugsnag/middleware/callbacks.rb' + - 'spec/spec_helper.rb' + +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AllowAsExpressionSeparator. Style/Semicolon: Exclude: - 'lib/bugsnag/configuration.rb' + - 'spec/cleaner_spec.rb' + - 'spec/configuration_spec.rb' -# Offense count: 3 +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: only_raise, only_fail, semantic +Style/SignalException: + Exclude: + - 'spec/bugsnag_spec.rb' + +# Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: . # SupportedStyles: use_perl_names, use_english_names Style/SpecialGlobalVars: EnforcedStyle: use_perl_names -# Offense count: 176 +# Offense count: 1817 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Enabled: false -# Offense count: 5 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiteralsInInterpolation: + Exclude: + - 'features/support/env.rb' + +# Offense count: 14 # Cop supports --auto-correct. # Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets -# Offense count: 3 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. # IgnoredMethods: respond_to, define_method @@ -634,6 +991,7 @@ Style/SymbolProc: - 'lib/bugsnag/middleware/classify_error.rb' - 'lib/bugsnag/middleware/rack_request.rb' - 'lib/bugsnag/middleware/suggestion_data.rb' + - 'spec/report_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -643,37 +1001,56 @@ Style/TernaryParentheses: Exclude: - 'lib/bugsnag/report.rb' -# Offense count: 5 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArguments: Exclude: - - 'lib/bugsnag/integrations/delayed_job.rb' + - 'spec/report_spec.rb' # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. -# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'spec/stacktrace_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'spec/integrations/que_spec.rb' + - 'spec/integrations/rails3_request_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods. +# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym Style/TrivialAccessors: Exclude: - 'lib/bugsnag/configuration.rb' -# Offense count: 1 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: MinSize, WordRegex. # SupportedStyles: percent, brackets Style/WordArray: EnforcedStyle: brackets -# Offense count: 3 +# Offense count: 4 # Cop supports --auto-correct. Style/ZeroLengthPredicate: Exclude: + - 'Rakefile' - 'lib/bugsnag/session_tracker.rb' -# Offense count: 92 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 371 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https -Metrics/LineLength: - Max: 162 +Layout/LineLength: + Max: 175 diff --git a/Gemfile b/Gemfile index 74a298c81..cd9633ade 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ group :coverage, optional: true do end group :rubocop, optional: true do - gem 'rubocop', '~> 0.52.1' + gem 'rubocop', '~> 0.83' end group :sidekiq, optional: true do From 51f5959fc613b8519144e258d14c07d4e2c78afa Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Fri, 15 May 2020 11:39:52 +0100 Subject: [PATCH 02/44] Disable mutable constants as its a BC break --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 9 +-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 90207c269..d8da878af 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,6 +7,11 @@ AllCops: - 'spec/fixtures/**/*' - 'features/fixtures/**/*' +# We can't use ".freeze" on our constants in case users are monkey patching +# them — this would be a BC break +Style/MutableConstant: + Enabled: false + Layout/EmptyLinesAroundAttributeAccessor: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 56e603421..fcb383927 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-05-15 11:04:08 +0100 using RuboCop version 0.83.0. +# on 2020-05-15 11:35:58 +0100 using RuboCop version 0.83.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -769,13 +769,6 @@ Style/MultilineIfModifier: Exclude: - 'lib/bugsnag/integrations/rails/controller_methods.rb' -# Offense count: 53 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. From 611716913f526f1299d3ac1b445abf6fe838fed5 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Fri, 15 May 2020 10:09:03 +0100 Subject: [PATCH 03/44] Tidy up existing ignore_classes tests --- spec/report_spec.rb | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 3d4b8530f..c22cc1c4b 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -710,38 +710,35 @@ def gloops expect(Bugsnag).not_to have_sent_notification end - it "does not notify if the exception class is in the default ignore_classes list" do - Bugsnag.configuration.ignore_classes << ActiveRecord::RecordNotFound - Bugsnag.notify(ActiveRecord::RecordNotFound.new("It crashed")) + context "ignore_classes" do + context "as a constant" do + it "ignores exception when its class is ignored" do + Bugsnag.configuration.ignore_classes << BugsnagTestException - expect(Bugsnag).not_to have_sent_notification - end - - it "does not notify if the non-default exception class is added to the ignore_classes" do - Bugsnag.configuration.ignore_classes << BugsnagTestException - - Bugsnag.notify(BugsnagTestException.new("It crashed")) + Bugsnag.notify(BugsnagTestException.new("It crashed")) - expect(Bugsnag).not_to have_sent_notification - end + expect(Bugsnag).not_to have_sent_notification + end - it "does not notify if exception's ancestor is an ignored class" do - Bugsnag.configuration.ignore_classes << BugsnagTestException + it "ignores exception when its ancestor is ignored" do + Bugsnag.configuration.ignore_classes << BugsnagTestException - Bugsnag.notify(BugsnagSubclassTestException.new("It crashed")) + Bugsnag.notify(BugsnagSubclassTestException.new("It crashed")) - expect(Bugsnag).not_to have_sent_notification - end + expect(Bugsnag).not_to have_sent_notification + end - it "does not notify if any caused exception is an ignored class" do - Bugsnag.configuration.ignore_classes << NestedException + it "ignores exception when the original exception is ignored" do + Bugsnag.configuration.ignore_classes << BugsnagTestException - ex = NestedException.new("Self-referential exception") - ex.original_exception = BugsnagTestException.new("It crashed") + ex = NestedException.new("Self-referential exception") + ex.original_exception = BugsnagTestException.new("It crashed") - Bugsnag.notify(ex) + Bugsnag.notify(ex) - expect(Bugsnag).not_to have_sent_notification + expect(Bugsnag).not_to have_sent_notification + end + end end it "sends the cause of the exception" do From b9802fc372be8f114bfe540bfbd47a98e1367002 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Fri, 15 May 2020 10:09:20 +0100 Subject: [PATCH 04/44] Add tests for when ignore_classes includes a Proc --- spec/report_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/report_spec.rb b/spec/report_spec.rb index c22cc1c4b..3e479fdfc 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -739,6 +739,29 @@ def gloops expect(Bugsnag).not_to have_sent_notification end end + + context "as a proc" do + it "ignores exception when the proc returns true" do + Bugsnag.configuration.ignore_classes << ->(exception) { true } + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).not_to have_sent_notification + end + + it "does not ignore exception when proc returns false" do + Bugsnag.configuration.ignore_classes << ->(exception) { false } + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).to have_sent_notification { |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["errorClass"]).to eq("BugsnagTestException") + expect(exception["message"]).to eq("It crashed") + } + end + end end it "sends the cause of the exception" do From 48f25c44e62e7351516a1088045b68e141bd1376 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 10:09:55 +0100 Subject: [PATCH 05/44] Add new discard_classes option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This accepts Strings and Regexps rather than Classes and Procs, which is more inline with other Bugsnag notifiers It also doesn't walk the ancestor chain, which should lead to less false positives — with regexps especailly, this could be very dangerous! --- lib/bugsnag.rb | 1 + lib/bugsnag/configuration.rb | 4 + lib/bugsnag/middleware/discard_error_class.rb | 30 +++++++ spec/configuration_spec.rb | 6 +- spec/report_spec.rb | 81 ++++++++++++++++++- 5 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 lib/bugsnag/middleware/discard_error_class.rb diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index b20f3c5e0..608a6edf6 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -147,6 +147,7 @@ def at_exit_handler_installed? # Configuration getters ## # Returns the client's Configuration object, or creates one if not yet created. + # @return [Configuration] def configuration @configuration = nil unless defined?(@configuration) @configuration || LOCK.synchronize { @configuration ||= Bugsnag::Configuration.new } diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index 90a3fa2fb..9dd256b99 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -3,6 +3,7 @@ require "logger" require "bugsnag/middleware_stack" require "bugsnag/middleware/callbacks" +require "bugsnag/middleware/discard_error_class" require "bugsnag/middleware/exception_meta_data" require "bugsnag/middleware/ignore_error_class" require "bugsnag/middleware/suggestion_data" @@ -36,6 +37,7 @@ class Configuration attr_accessor :hostname attr_accessor :runtime_versions attr_accessor :ignore_classes + attr_accessor :discard_classes attr_accessor :auto_capture_sessions ## @@ -123,6 +125,7 @@ def initialize # SystemExit and SignalException are common Exception types seen with # successful exits and are not automatically reported to Bugsnag self.ignore_classes = Set.new([SystemExit, SignalException]) + self.discard_classes = Set.new(["SystemExit", "SignalException"]) # Read the API key from the environment self.api_key = ENV["BUGSNAG_API_KEY"] @@ -147,6 +150,7 @@ def initialize # Configure the bugsnag middleware stack self.internal_middleware = Bugsnag::MiddlewareStack.new self.internal_middleware.use Bugsnag::Middleware::ExceptionMetaData + self.internal_middleware.use Bugsnag::Middleware::DiscardErrorClass self.internal_middleware.use Bugsnag::Middleware::IgnoreErrorClass self.internal_middleware.use Bugsnag::Middleware::SuggestionData self.internal_middleware.use Bugsnag::Middleware::ClassifyError diff --git a/lib/bugsnag/middleware/discard_error_class.rb b/lib/bugsnag/middleware/discard_error_class.rb new file mode 100644 index 000000000..0e60619e3 --- /dev/null +++ b/lib/bugsnag/middleware/discard_error_class.rb @@ -0,0 +1,30 @@ +module Bugsnag::Middleware + ## + # Determines if the exception should be ignored based on the configured + # `discard_classes` + class DiscardErrorClass + ## + # @param middleware [#call] The next middleware to call + def initialize(middleware) + @middleware = middleware + end + + ## + # @param report [Report] + def call(report) + ignore_error_class = report.raw_exceptions.any? do |ex| + report.configuration.discard_classes.any? do |to_ignore| + case to_ignore + when String then to_ignore == ex.class.name + when Regexp then to_ignore =~ ex.class.name + else false + end + end + end + + report.ignore! if ignore_error_class + + @middleware.call(report) + end + end +end diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 5db5e5f23..56a31e78d 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -332,10 +332,14 @@ def debug(name, &block) end end - it "should have exit exception classes ignored by default" do + it "should have exit exception classes in ignore_classes by default" do expect(subject.ignore_classes).to eq(Set.new([SystemExit, SignalException])) end + it "should have exit exception classes in discard_classes by default" do + expect(subject.discard_classes).to eq(Set.new(["SystemExit", "SignalException"])) + end + describe "#breadcrumbs" do it "first returns a new circular buffer" do buffer = subject.breadcrumbs diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 3e479fdfc..3f2af2ca3 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -27,6 +27,7 @@ def gloops end end +# rubocop:disable Metrics/BlockLength describe Bugsnag::Report do it "should contain an api_key if one is set" do Bugsnag.notify(BugsnagTestException.new("It crashed")) @@ -147,12 +148,16 @@ def gloops it "sets correct severity and reason for specific error classes" do original_ignore_classes = Bugsnag.configuration.ignore_classes + original_discard_classes = Bugsnag.configuration.discard_classes begin - # The default ignore_classes includes SignalException, so we need to - # temporarily set it to something else. + # The default ignore/discard classes includes SignalException, so we need + # to temporarily set them to something else. Bugsnag.configuration.ignore_classes = Set[SystemExit] + Bugsnag.configuration.discard_classes = Set["SystemExit"] + Bugsnag.notify(SignalException.new("TERM")) + expect(Bugsnag).to have_sent_notification{ |payload, headers| event = get_event_from_payload(payload) expect(event["unhandled"]).to be false @@ -166,6 +171,7 @@ def gloops } ensure Bugsnag.configuration.ignore_classes = original_ignore_classes + Bugsnag.configuration.discard_classes = original_discard_classes end end @@ -764,6 +770,76 @@ def gloops end end + context "discard_classes" do + context "as a string" do + it "discards exception when its class should be discarded" do + Bugsnag.configuration.discard_classes << "BugsnagTestException" + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).not_to have_sent_notification + end + + it "discards exception when the original exception should be discarded" do + Bugsnag.configuration.discard_classes << "BugsnagTestException" + + ex = NestedException.new("Self-referential exception") + ex.original_exception = BugsnagTestException.new("It crashed") + + Bugsnag.notify(ex) + + expect(Bugsnag).not_to have_sent_notification + end + + it "does not discard exception with a typo" do + Bugsnag.configuration.discard_classes << "BugsnagToastException" + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).to have_sent_notification { |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["errorClass"]).to eq("BugsnagTestException") + expect(exception["message"]).to eq("It crashed") + } + end + end + + context "as a regexp" do + it "discards exception when its class should be discarded" do + Bugsnag.configuration.discard_classes << /^BugsnagTest.*/ + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).not_to have_sent_notification + end + + it "discards exception when the original exception should be discarded" do + Bugsnag.configuration.discard_classes << /^BugsnagTest.*/ + + ex = NestedException.new("Self-referential exception") + ex.original_exception = BugsnagTestException.new("It crashed") + + Bugsnag.notify(ex) + + expect(Bugsnag).not_to have_sent_notification + end + + it "does not discard exception when regexp does not match" do + Bugsnag.configuration.discard_classes << /^NotBugsnag.*/ + + Bugsnag.notify(BugsnagTestException.new("It crashed")) + + expect(Bugsnag).to have_sent_notification { |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["errorClass"]).to eq("BugsnagTestException") + expect(exception["message"]).to eq("It crashed") + } + end + end + end + it "sends the cause of the exception" do begin begin @@ -1300,3 +1376,4 @@ def gloops } end end +# rubocop:enable Metrics/BlockLength From 7d1c30f0236143bcd929de1871a4747a710957c9 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 10:11:01 +0100 Subject: [PATCH 06/44] Deprecate ignore_classes --- lib/bugsnag/configuration.rb | 5 ++++- lib/bugsnag/middleware/ignore_error_class.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index 9dd256b99..af12162d1 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -36,10 +36,13 @@ class Configuration attr_accessor :timeout attr_accessor :hostname attr_accessor :runtime_versions - attr_accessor :ignore_classes attr_accessor :discard_classes attr_accessor :auto_capture_sessions + ## + # @deprecated Use {#discard_classes} instead + attr_accessor :ignore_classes + ## # @return [String] URL error notifications will be delivered to attr_reader :notify_endpoint diff --git a/lib/bugsnag/middleware/ignore_error_class.rb b/lib/bugsnag/middleware/ignore_error_class.rb index 5d21a7d08..3ef5c996a 100644 --- a/lib/bugsnag/middleware/ignore_error_class.rb +++ b/lib/bugsnag/middleware/ignore_error_class.rb @@ -2,6 +2,8 @@ module Bugsnag::Middleware ## # Determines if the exception should be ignored based on the configured # `ignore_classes` + # + # @deprecated Use {DiscardErrorClass} instead class IgnoreErrorClass def initialize(bugsnag) @bugsnag = bugsnag From 33733d5d1e9f5303f91d6d6eaed4963b678b913d Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 11:20:23 +0100 Subject: [PATCH 07/44] Add changelog entry --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 256cb4f57..99a95ef45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ Changelog ========= +## TBD + +### Enhancements + +* Add configurable `discard_classes` option to allow filtering errors using either a `String` or `Regexp` matched against the error's class name + | [#597](https://github.com/bugsnag/bugsnag-ruby/pull/597) + +### Deprecated +* The `ignore_classes` configuration option has been deprecated in favour of `discard_classes`. `ignore_classes` will be removed in the next major release + ## 6.13.1 (11 May 2020) ### Fixes From b2aa7d05cc7f04e554afeb6b839fc257501a816a Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 11:29:02 +0100 Subject: [PATCH 08/44] Add tests to ensure the ancestor chain is ignored --- spec/report_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 3f2af2ca3..36d335d74 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -803,6 +803,19 @@ def gloops expect(exception["message"]).to eq("It crashed") } end + + it "does not discard exception when its ancestor is discarded" do + Bugsnag.configuration.discard_classes << "BugsnagTestException" + + Bugsnag.notify(BugsnagSubclassTestException.new("It crashed")) + + expect(Bugsnag).to have_sent_notification { |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["errorClass"]).to eq("BugsnagSubclassTestException") + expect(exception["message"]).to eq("It crashed") + } + end end context "as a regexp" do @@ -837,6 +850,19 @@ def gloops expect(exception["message"]).to eq("It crashed") } end + + it "does not discard exception when its ancestor is discarded" do + Bugsnag.configuration.discard_classes << /^BugsnagTest.*/ + + Bugsnag.notify(BugsnagSubclassTestException.new("It crashed")) + + expect(Bugsnag).to have_sent_notification { |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["errorClass"]).to eq("BugsnagSubclassTestException") + expect(exception["message"]).to eq("It crashed") + } + end end end From 791a1d79687d9279d6bd500e362627948d94f8a1 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 16:51:20 +0100 Subject: [PATCH 09/44] Rename from ignore -> discard --- lib/bugsnag/middleware/discard_error_class.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bugsnag/middleware/discard_error_class.rb b/lib/bugsnag/middleware/discard_error_class.rb index 0e60619e3..1dff08ed6 100644 --- a/lib/bugsnag/middleware/discard_error_class.rb +++ b/lib/bugsnag/middleware/discard_error_class.rb @@ -12,7 +12,7 @@ def initialize(middleware) ## # @param report [Report] def call(report) - ignore_error_class = report.raw_exceptions.any? do |ex| + should_discard = report.raw_exceptions.any? do |ex| report.configuration.discard_classes.any? do |to_ignore| case to_ignore when String then to_ignore == ex.class.name @@ -22,7 +22,7 @@ def call(report) end end - report.ignore! if ignore_error_class + report.ignore! if should_discard @middleware.call(report) end From 4cced91b54b891f598b8a35d1196c439508a11ad Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 18 May 2020 17:21:11 +0100 Subject: [PATCH 10/44] Remove defaults from discard_classes Having defaults here is problematic for a few reasons, mainly that if someone is emptying `ignore_classes` then we'll break their app by re-adding those defaults to `discard_classes` We can move the values over when `ignore_classes` is removed --- lib/bugsnag/configuration.rb | 4 +++- spec/configuration_spec.rb | 4 ++-- spec/report_spec.rb | 7 ++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index af12162d1..0a8e5aded 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -127,8 +127,10 @@ def initialize # SystemExit and SignalException are common Exception types seen with # successful exits and are not automatically reported to Bugsnag + # TODO move these defaults into `discard_classes` when `ignore_classes` + # is removed self.ignore_classes = Set.new([SystemExit, SignalException]) - self.discard_classes = Set.new(["SystemExit", "SignalException"]) + self.discard_classes = Set.new([]) # Read the API key from the environment self.api_key = ENV["BUGSNAG_API_KEY"] diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index 56a31e78d..9bc1d5345 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -336,8 +336,8 @@ def debug(name, &block) expect(subject.ignore_classes).to eq(Set.new([SystemExit, SignalException])) end - it "should have exit exception classes in discard_classes by default" do - expect(subject.discard_classes).to eq(Set.new(["SystemExit", "SignalException"])) + it "should have nothing in discard_classes by default" do + expect(subject.discard_classes).to eq(Set.new([])) end describe "#breadcrumbs" do diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 36d335d74..701b985bf 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -148,13 +148,11 @@ def gloops it "sets correct severity and reason for specific error classes" do original_ignore_classes = Bugsnag.configuration.ignore_classes - original_discard_classes = Bugsnag.configuration.discard_classes begin - # The default ignore/discard classes includes SignalException, so we need - # to temporarily set them to something else. + # The default ignore classes includes SignalException, so we need to + # temporarily set it to something else. Bugsnag.configuration.ignore_classes = Set[SystemExit] - Bugsnag.configuration.discard_classes = Set["SystemExit"] Bugsnag.notify(SignalException.new("TERM")) @@ -171,7 +169,6 @@ def gloops } ensure Bugsnag.configuration.ignore_classes = original_ignore_classes - Bugsnag.configuration.discard_classes = original_discard_classes end end From 0962b6b3b029b4660fc2604a93119b96bb950332 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 15:23:41 +0100 Subject: [PATCH 11/44] WIP Rails 6.0 example TODO: 1. Sidekiq 2. Que 3. Resque 4. README --- example/rails-60/.browserslistrc | 1 + example/rails-60/.gitignore | 45 +++++++ example/rails-60/Gemfile | 55 +++++++++ example/rails-60/README.md | 24 ++++ example/rails-60/Rakefile | 6 + .../rails-60/app/assets/config/manifest.js | 2 + example/rails-60/app/assets/images/.keep | 0 .../app/assets/stylesheets/application.css | 39 ++++++ .../app/channels/application_cable/channel.rb | 4 + .../channels/application_cable/connection.rb | 4 + .../app/controllers/application_controller.rb | 50 ++++++++ .../rails-60/app/controllers/concerns/.keep | 0 .../app/helpers/application_helper.rb | 2 + .../app/javascript/channels/consumer.js | 6 + .../rails-60/app/javascript/channels/index.js | 5 + .../app/javascript/packs/application.js | 17 +++ example/rails-60/app/jobs/application_job.rb | 7 ++ .../app/mailers/application_mailer.rb | 4 + .../rails-60/app/models/application_record.rb | 3 + example/rails-60/app/models/concerns/.keep | 0 .../app/views/application/data.html.erb | 10 ++ .../app/views/application/index.html.erb | 70 +++++++++++ .../app/views/application/notify.html.erb | 8 ++ .../app/views/application/severity.html.erb | 5 + .../app/views/layouts/application.html.erb | 17 +++ .../app/views/layouts/mailer.html.erb | 13 ++ .../app/views/layouts/mailer.text.erb | 1 + example/rails-60/babel.config.js | 72 +++++++++++ example/rails-60/config.ru | 5 + example/rails-60/config/application.rb | 19 +++ example/rails-60/config/boot.rb | 4 + example/rails-60/config/cable.yml | 10 ++ example/rails-60/config/credentials.yml.enc | 1 + example/rails-60/config/database.yml | 25 ++++ example/rails-60/config/environment.rb | 5 + .../config/environments/development.rb | 62 ++++++++++ .../config/environments/production.rb | 112 ++++++++++++++++++ example/rails-60/config/environments/test.rb | 49 ++++++++ .../application_controller_renderer.rb | 8 ++ .../rails-60/config/initializers/assets.rb | 14 +++ .../initializers/backtrace_silencers.rb | 7 ++ .../rails-60/config/initializers/bugsnag.rb | 3 + .../initializers/content_security_policy.rb | 30 +++++ .../config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 16 +++ .../config/initializers/mime_types.rb | 4 + .../config/initializers/wrap_parameters.rb | 14 +++ example/rails-60/config/locales/en.yml | 33 ++++++ example/rails-60/config/puma.rb | 38 ++++++ example/rails-60/config/routes.rb | 26 ++++ example/rails-60/config/spring.rb | 6 + example/rails-60/config/storage.yml | 34 ++++++ .../rails-60/config/webpack/development.js | 5 + .../rails-60/config/webpack/environment.js | 3 + example/rails-60/config/webpack/production.js | 5 + example/rails-60/config/webpack/test.js | 5 + example/rails-60/config/webpacker.yml | 96 +++++++++++++++ example/rails-60/db/seeds.rb | 7 ++ example/rails-60/lib/assets/.keep | 0 example/rails-60/lib/tasks/.keep | 0 example/rails-60/log/.keep | 0 example/rails-60/package.json | 15 +++ example/rails-60/postcss.config.js | 12 ++ example/rails-60/public/404.html | 67 +++++++++++ example/rails-60/public/422.html | 67 +++++++++++ example/rails-60/public/500.html | 66 +++++++++++ .../public/apple-touch-icon-precomposed.png | 0 example/rails-60/public/apple-touch-icon.png | 0 example/rails-60/public/favicon.ico | 0 example/rails-60/public/robots.txt | 1 + example/rails-60/storage/.keep | 0 example/rails-60/tmp/.keep | 0 example/rails-60/tmp/pids/.keep | 0 74 files changed, 1353 insertions(+) create mode 100644 example/rails-60/.browserslistrc create mode 100644 example/rails-60/.gitignore create mode 100644 example/rails-60/Gemfile create mode 100644 example/rails-60/README.md create mode 100644 example/rails-60/Rakefile create mode 100644 example/rails-60/app/assets/config/manifest.js create mode 100644 example/rails-60/app/assets/images/.keep create mode 100644 example/rails-60/app/assets/stylesheets/application.css create mode 100644 example/rails-60/app/channels/application_cable/channel.rb create mode 100644 example/rails-60/app/channels/application_cable/connection.rb create mode 100644 example/rails-60/app/controllers/application_controller.rb create mode 100644 example/rails-60/app/controllers/concerns/.keep create mode 100644 example/rails-60/app/helpers/application_helper.rb create mode 100644 example/rails-60/app/javascript/channels/consumer.js create mode 100644 example/rails-60/app/javascript/channels/index.js create mode 100644 example/rails-60/app/javascript/packs/application.js create mode 100644 example/rails-60/app/jobs/application_job.rb create mode 100644 example/rails-60/app/mailers/application_mailer.rb create mode 100644 example/rails-60/app/models/application_record.rb create mode 100644 example/rails-60/app/models/concerns/.keep create mode 100644 example/rails-60/app/views/application/data.html.erb create mode 100644 example/rails-60/app/views/application/index.html.erb create mode 100644 example/rails-60/app/views/application/notify.html.erb create mode 100644 example/rails-60/app/views/application/severity.html.erb create mode 100644 example/rails-60/app/views/layouts/application.html.erb create mode 100644 example/rails-60/app/views/layouts/mailer.html.erb create mode 100644 example/rails-60/app/views/layouts/mailer.text.erb create mode 100644 example/rails-60/babel.config.js create mode 100644 example/rails-60/config.ru create mode 100644 example/rails-60/config/application.rb create mode 100644 example/rails-60/config/boot.rb create mode 100644 example/rails-60/config/cable.yml create mode 100644 example/rails-60/config/credentials.yml.enc create mode 100644 example/rails-60/config/database.yml create mode 100644 example/rails-60/config/environment.rb create mode 100644 example/rails-60/config/environments/development.rb create mode 100644 example/rails-60/config/environments/production.rb create mode 100644 example/rails-60/config/environments/test.rb create mode 100644 example/rails-60/config/initializers/application_controller_renderer.rb create mode 100644 example/rails-60/config/initializers/assets.rb create mode 100644 example/rails-60/config/initializers/backtrace_silencers.rb create mode 100644 example/rails-60/config/initializers/bugsnag.rb create mode 100644 example/rails-60/config/initializers/content_security_policy.rb create mode 100644 example/rails-60/config/initializers/cookies_serializer.rb create mode 100644 example/rails-60/config/initializers/filter_parameter_logging.rb create mode 100644 example/rails-60/config/initializers/inflections.rb create mode 100644 example/rails-60/config/initializers/mime_types.rb create mode 100644 example/rails-60/config/initializers/wrap_parameters.rb create mode 100644 example/rails-60/config/locales/en.yml create mode 100644 example/rails-60/config/puma.rb create mode 100644 example/rails-60/config/routes.rb create mode 100644 example/rails-60/config/spring.rb create mode 100644 example/rails-60/config/storage.yml create mode 100644 example/rails-60/config/webpack/development.js create mode 100644 example/rails-60/config/webpack/environment.js create mode 100644 example/rails-60/config/webpack/production.js create mode 100644 example/rails-60/config/webpack/test.js create mode 100644 example/rails-60/config/webpacker.yml create mode 100644 example/rails-60/db/seeds.rb create mode 100644 example/rails-60/lib/assets/.keep create mode 100644 example/rails-60/lib/tasks/.keep create mode 100644 example/rails-60/log/.keep create mode 100644 example/rails-60/package.json create mode 100644 example/rails-60/postcss.config.js create mode 100644 example/rails-60/public/404.html create mode 100644 example/rails-60/public/422.html create mode 100644 example/rails-60/public/500.html create mode 100644 example/rails-60/public/apple-touch-icon-precomposed.png create mode 100644 example/rails-60/public/apple-touch-icon.png create mode 100644 example/rails-60/public/favicon.ico create mode 100644 example/rails-60/public/robots.txt create mode 100644 example/rails-60/storage/.keep create mode 100644 example/rails-60/tmp/.keep create mode 100644 example/rails-60/tmp/pids/.keep diff --git a/example/rails-60/.browserslistrc b/example/rails-60/.browserslistrc new file mode 100644 index 000000000..e94f8140c --- /dev/null +++ b/example/rails-60/.browserslistrc @@ -0,0 +1 @@ +defaults diff --git a/example/rails-60/.gitignore b/example/rails-60/.gitignore new file mode 100644 index 000000000..f3c55eb4f --- /dev/null +++ b/example/rails-60/.gitignore @@ -0,0 +1,45 @@ +/.ruby-version +/Gemfile.lock +/yarn.lock + +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal +/db/*.sqlite3-* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore uploaded files in development. +/storage/* +!/storage/.keep + +/public/assets +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key + +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity diff --git a/example/rails-60/Gemfile b/example/rails-60/Gemfile new file mode 100644 index 000000000..ea8532f35 --- /dev/null +++ b/example/rails-60/Gemfile @@ -0,0 +1,55 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +# Install Bugsnag +gem "bugsnag", path: "../../" + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 6.0.3', '>= 6.0.3.1' +# Use sqlite3 as the database for Active Record +gem 'sqlite3', '~> 1.4' +# Use Puma as the app server +gem 'puma', '~> 4.1' +# Use SCSS for stylesheets +gem 'sass-rails', '>= 6' +# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker +gem 'webpacker', '~> 4.0' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.7' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use Active Model has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Active Storage variant +# gem 'image_processing', '~> 1.2' + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.4.2', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '~> 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of web drivers to run system tests with browsers + gem 'webdrivers' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/example/rails-60/README.md b/example/rails-60/README.md new file mode 100644 index 000000000..7db80e4ca --- /dev/null +++ b/example/rails-60/README.md @@ -0,0 +1,24 @@ +# README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... diff --git a/example/rails-60/Rakefile b/example/rails-60/Rakefile new file mode 100644 index 000000000..e85f91391 --- /dev/null +++ b/example/rails-60/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/example/rails-60/app/assets/config/manifest.js b/example/rails-60/app/assets/config/manifest.js new file mode 100644 index 000000000..591819335 --- /dev/null +++ b/example/rails-60/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/example/rails-60/app/assets/images/.keep b/example/rails-60/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/app/assets/stylesheets/application.css b/example/rails-60/app/assets/stylesheets/application.css new file mode 100644 index 000000000..74b4724f8 --- /dev/null +++ b/example/rails-60/app/assets/stylesheets/application.css @@ -0,0 +1,39 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ + +body { + font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji; + max-width: 80ch; + margin: 0 auto; +} + +pre, +code { + font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; +} + +a:link, +a:visited { + color: #536eec; +} + +a:hover { + opacity: .7; +} + +.upper { + text-transform: uppercase; +} diff --git a/example/rails-60/app/channels/application_cable/channel.rb b/example/rails-60/app/channels/application_cable/channel.rb new file mode 100644 index 000000000..d67269728 --- /dev/null +++ b/example/rails-60/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/example/rails-60/app/channels/application_cable/connection.rb b/example/rails-60/app/channels/application_cable/connection.rb new file mode 100644 index 000000000..0ff5442f4 --- /dev/null +++ b/example/rails-60/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/example/rails-60/app/controllers/application_controller.rb b/example/rails-60/app/controllers/application_controller.rb new file mode 100644 index 000000000..4be69567f --- /dev/null +++ b/example/rails-60/app/controllers/application_controller.rb @@ -0,0 +1,50 @@ +class ApplicationController < ActionController::Base + def crash + raise 'Bugsnag Rails demo says: It crashed! ' \ + 'Go check bugsnag.com for a new notification' + end + + def callback + Bugsnag.before_notify_callbacks << proc { |report| + report.add_tab(:diagnostics, { + message: 'Rails v6.0 demo says: Everything is great', + code: 200 + }) + } + + raise 'Bugsnag Rails demo says: It crashed! But, due to the attached callback' \ + 'the exception has meta information. Go check ' \ + 'bugsnag.com for a new notification (see the Diagnostics tab)!' + end + + def notify + Bugsnag.notify(RuntimeError.new("Bugsnag Rails demo says: False alarm, your application didn't crash")) + end + + def data + error = RuntimeError.new("Bugsnag Rails demo says: False alarm, your application didn't crash") + + Bugsnag.notify(error) do |report| + report.add_tab(:user, { + username: 'bob-hoskins', + email: 'bugsnag@bugsnag.com', + registered_user: true + }) + + report.add_tab(:diagnostics, { + message: 'Rails demo says: Everything is great', + code: 200 + }) + end + end + + def severity + error = RuntimeError.new( + "Bugsnag Rails demo says: Look at the circle on the right side — it's different!" + ) + + Bugsnag.notify(error) do |report| + report.severity = 'info' + end + end +end diff --git a/example/rails-60/app/controllers/concerns/.keep b/example/rails-60/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/app/helpers/application_helper.rb b/example/rails-60/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/example/rails-60/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/example/rails-60/app/javascript/channels/consumer.js b/example/rails-60/app/javascript/channels/consumer.js new file mode 100644 index 000000000..0eceb59b1 --- /dev/null +++ b/example/rails-60/app/javascript/channels/consumer.js @@ -0,0 +1,6 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. + +import { createConsumer } from "@rails/actioncable" + +export default createConsumer() diff --git a/example/rails-60/app/javascript/channels/index.js b/example/rails-60/app/javascript/channels/index.js new file mode 100644 index 000000000..0cfcf7491 --- /dev/null +++ b/example/rails-60/app/javascript/channels/index.js @@ -0,0 +1,5 @@ +// Load all the channels within this directory and all subdirectories. +// Channel files must be named *_channel.js. + +const channels = require.context('.', true, /_channel\.js$/) +channels.keys().forEach(channels) diff --git a/example/rails-60/app/javascript/packs/application.js b/example/rails-60/app/javascript/packs/application.js new file mode 100644 index 000000000..9cd55d4b9 --- /dev/null +++ b/example/rails-60/app/javascript/packs/application.js @@ -0,0 +1,17 @@ +// This file is automatically compiled by Webpack, along with any other files +// present in this directory. You're encouraged to place your actual application logic in +// a relevant structure within app/javascript and only use these pack files to reference +// that code so it'll be compiled. + +require("@rails/ujs").start() +require("turbolinks").start() +require("@rails/activestorage").start() +require("channels") + + +// Uncomment to copy all static images under ../images to the output folder and reference +// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) +// or the `imagePath` JavaScript helper below. +// +// const images = require.context('../images', true) +// const imagePath = (name) => images(name, true) diff --git a/example/rails-60/app/jobs/application_job.rb b/example/rails-60/app/jobs/application_job.rb new file mode 100644 index 000000000..d394c3d10 --- /dev/null +++ b/example/rails-60/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/example/rails-60/app/mailers/application_mailer.rb b/example/rails-60/app/mailers/application_mailer.rb new file mode 100644 index 000000000..286b2239d --- /dev/null +++ b/example/rails-60/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/example/rails-60/app/models/application_record.rb b/example/rails-60/app/models/application_record.rb new file mode 100644 index 000000000..10a4cba84 --- /dev/null +++ b/example/rails-60/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/example/rails-60/app/models/concerns/.keep b/example/rails-60/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/app/views/application/data.html.erb b/example/rails-60/app/views/application/data.html.erb new file mode 100644 index 000000000..3c050280e --- /dev/null +++ b/example/rails-60/app/views/application/data.html.erb @@ -0,0 +1,10 @@ +

Bugsnag Rails demo says: It didn't crash!

+ +

+ But still go check your Bugsnag dashboard + for a new notification. +

+ +

Check out the user tab to see the metadata.

+ +

← return to examples

diff --git a/example/rails-60/app/views/application/index.html.erb b/example/rails-60/app/views/application/index.html.erb new file mode 100644 index 000000000..098615448 --- /dev/null +++ b/example/rails-60/app/views/application/index.html.erb @@ -0,0 +1,70 @@ +

This application demonstrates the use of Bugsnag with the Rails web framework.

+ +

For other examples within this application see the following pages:

+ + + +

+ While testing the examples open + your Bugsnag dashboard + in order to see the example errors and exceptions being received. +

+ +
    +
  1. +

    Crash

    +

    + Raises an error within the framework, generating a report in the + Bugsnag dashboard. +

    +
  2. + +
  3. +

    Crash and use callbacks

    +

    + Raises an exception within the framework, but with additional data + attached to the report. By registering a callback before the error + occurs useful data can be attached as a tab in the Bugsnag dashboard. +

    +
  4. + +
  5. +

    Notify

    +

    + Sends Bugsnag a report on demand using bugsnag.notify. + Allows details of handled errors or information to be sent to the + Bugsnag dashboard without crashing your code. +

    +
  6. + +
  7. +

    Notify with data

    +

    + Same as notify but allows you to attach additional data + within a block, similar to the + before_notify_callbacks example above. +

    +

    + In this case we're adding information about the user to go into the + user tab, and additional diagnostics as a + diagnostics tab. +

    +
  8. + +
  9. +

    Set the severity

    +

    + This uses the same mechanism as adding meta-data, but allows you to + set the severity when notifying Bugsnag of the error. +

    +

    + Valid severities are error, warning, and + info. Have a look on the dashboard to see the + difference in these severities. +

  10. + +
diff --git a/example/rails-60/app/views/application/notify.html.erb b/example/rails-60/app/views/application/notify.html.erb new file mode 100644 index 000000000..40b7904fe --- /dev/null +++ b/example/rails-60/app/views/application/notify.html.erb @@ -0,0 +1,8 @@ +

Bugsnag Rails demo says: It didn't crash!

+ +

+ But still go check your Bugsnag dashboard + for a new notification. +

+ +

← return to examples

diff --git a/example/rails-60/app/views/application/severity.html.erb b/example/rails-60/app/views/application/severity.html.erb new file mode 100644 index 000000000..5954e03ee --- /dev/null +++ b/example/rails-60/app/views/application/severity.html.erb @@ -0,0 +1,5 @@ +

+ Bugsnag Rails demo says: Look at the circle on the right side — it's different! +

+ +

← return to examples

diff --git a/example/rails-60/app/views/layouts/application.html.erb b/example/rails-60/app/views/layouts/application.html.erb new file mode 100644 index 000000000..912f5f852 --- /dev/null +++ b/example/rails-60/app/views/layouts/application.html.erb @@ -0,0 +1,17 @@ + + + + Bugsnag Rails v6.0 demo + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + + + +

Bugsnag Rails v6.0 demo

+ + <%= yield %> + + diff --git a/example/rails-60/app/views/layouts/mailer.html.erb b/example/rails-60/app/views/layouts/mailer.html.erb new file mode 100644 index 000000000..cbd34d2e9 --- /dev/null +++ b/example/rails-60/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/example/rails-60/app/views/layouts/mailer.text.erb b/example/rails-60/app/views/layouts/mailer.text.erb new file mode 100644 index 000000000..37f0bddbd --- /dev/null +++ b/example/rails-60/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/example/rails-60/babel.config.js b/example/rails-60/babel.config.js new file mode 100644 index 000000000..12f98da5a --- /dev/null +++ b/example/rails-60/babel.config.js @@ -0,0 +1,72 @@ +module.exports = function(api) { + var validEnv = ['development', 'test', 'production'] + var currentEnv = api.env() + var isDevelopmentEnv = api.env('development') + var isProductionEnv = api.env('production') + var isTestEnv = api.env('test') + + if (!validEnv.includes(currentEnv)) { + throw new Error( + 'Please specify a valid `NODE_ENV` or ' + + '`BABEL_ENV` environment variables. Valid values are "development", ' + + '"test", and "production". Instead, received: ' + + JSON.stringify(currentEnv) + + '.' + ) + } + + return { + presets: [ + isTestEnv && [ + '@babel/preset-env', + { + targets: { + node: 'current' + } + } + ], + (isProductionEnv || isDevelopmentEnv) && [ + '@babel/preset-env', + { + forceAllTransforms: true, + useBuiltIns: 'entry', + corejs: 3, + modules: false, + exclude: ['transform-typeof-symbol'] + } + ] + ].filter(Boolean), + plugins: [ + 'babel-plugin-macros', + '@babel/plugin-syntax-dynamic-import', + isTestEnv && 'babel-plugin-dynamic-import-node', + '@babel/plugin-transform-destructuring', + [ + '@babel/plugin-proposal-class-properties', + { + loose: true + } + ], + [ + '@babel/plugin-proposal-object-rest-spread', + { + useBuiltIns: true + } + ], + [ + '@babel/plugin-transform-runtime', + { + helpers: false, + regenerator: true, + corejs: false + } + ], + [ + '@babel/plugin-transform-regenerator', + { + async: false + } + ] + ].filter(Boolean) + } +} diff --git a/example/rails-60/config.ru b/example/rails-60/config.ru new file mode 100644 index 000000000..f7ba0b527 --- /dev/null +++ b/example/rails-60/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/example/rails-60/config/application.rb b/example/rails-60/config/application.rb new file mode 100644 index 000000000..7606973a3 --- /dev/null +++ b/example/rails-60/config/application.rb @@ -0,0 +1,19 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Rails60 + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.0 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end diff --git a/example/rails-60/config/boot.rb b/example/rails-60/config/boot.rb new file mode 100644 index 000000000..b9e460cef --- /dev/null +++ b/example/rails-60/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/example/rails-60/config/cable.yml b/example/rails-60/config/cable.yml new file mode 100644 index 000000000..e168aa54b --- /dev/null +++ b/example/rails-60/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: rails_60_production diff --git a/example/rails-60/config/credentials.yml.enc b/example/rails-60/config/credentials.yml.enc new file mode 100644 index 000000000..e015aa824 --- /dev/null +++ b/example/rails-60/config/credentials.yml.enc @@ -0,0 +1 @@ +KQhHHa39d1cmOiryTxmJvb3odw1lJYakJGSiQ8FJQGokXbkGPDUpG8UPuuvdKdwvh2O03jgdRlZ5ZeGtDgUeEVgSeWdGsvAXH9mwKfLxqm5lQuq5DfEnOOEpzAoReLpu4Hp7kmdJEwz/APbiEZ74NEFz94nDyWFkZwKsH1NSATVicP3gvGO0fgY0/ADOGcezOLcMrHCckCIap1oe4Fr68R0YbQxUhaNfZzsQN2RPHCw4fvQARYZcEPiTpoPRMwZsxkFdWQCpUUuQASdMFuu3+Cq//+Q57V+k3F353s52pQ1qCX/Oq0pBe8XXTzzQVK+x35xD7puFsz3N7wa2RtkmdUR0SsS/b92MRHMB94KjnQWLn7FS8/rYtDaiv6WnrXSGzwhOOtW8M3vOi35F1yoiUuM6bfIW68sCR3LR--hk5vbvf0FXhi6gl0--1WNlajBXqT6SQsGjKFHIlQ== \ No newline at end of file diff --git a/example/rails-60/config/database.yml b/example/rails-60/config/database.yml new file mode 100644 index 000000000..4a8a1b26f --- /dev/null +++ b/example/rails-60/config/database.yml @@ -0,0 +1,25 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/example/rails-60/config/environment.rb b/example/rails-60/config/environment.rb new file mode 100644 index 000000000..426333bb4 --- /dev/null +++ b/example/rails-60/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/example/rails-60/config/environments/development.rb b/example/rails-60/config/environments/development.rb new file mode 100644 index 000000000..66df51f6f --- /dev/null +++ b/example/rails-60/config/environments/development.rb @@ -0,0 +1,62 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/example/rails-60/config/environments/production.rb b/example/rails-60/config/environments/production.rb new file mode 100644 index 000000000..244c22e00 --- /dev/null +++ b/example/rails-60/config/environments/production.rb @@ -0,0 +1,112 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "rails_60_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session +end diff --git a/example/rails-60/config/environments/test.rb b/example/rails-60/config/environments/test.rb new file mode 100644 index 000000000..0cb24249b --- /dev/null +++ b/example/rails-60/config/environments/test.rb @@ -0,0 +1,49 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.cache_classes = false + config.action_view.cache_template_loading = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true +end diff --git a/example/rails-60/config/initializers/application_controller_renderer.rb b/example/rails-60/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/example/rails-60/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/example/rails-60/config/initializers/assets.rb b/example/rails-60/config/initializers/assets.rb new file mode 100644 index 000000000..4b828e80c --- /dev/null +++ b/example/rails-60/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/example/rails-60/config/initializers/backtrace_silencers.rb b/example/rails-60/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/example/rails-60/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/example/rails-60/config/initializers/bugsnag.rb b/example/rails-60/config/initializers/bugsnag.rb new file mode 100644 index 000000000..58c57fbf6 --- /dev/null +++ b/example/rails-60/config/initializers/bugsnag.rb @@ -0,0 +1,3 @@ +Bugsnag.configure do |config| + config.api_key = "YOUR_API_KEY_HERE" +end diff --git a/example/rails-60/config/initializers/content_security_policy.rb b/example/rails-60/config/initializers/content_security_policy.rb new file mode 100644 index 000000000..35d0f26fc --- /dev/null +++ b/example/rails-60/config/initializers/content_security_policy.rb @@ -0,0 +1,30 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # If you are using webpack-dev-server then specify webpack-dev-server host +# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/example/rails-60/config/initializers/cookies_serializer.rb b/example/rails-60/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..5a6a32d37 --- /dev/null +++ b/example/rails-60/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/example/rails-60/config/initializers/filter_parameter_logging.rb b/example/rails-60/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/example/rails-60/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/example/rails-60/config/initializers/inflections.rb b/example/rails-60/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/example/rails-60/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/example/rails-60/config/initializers/mime_types.rb b/example/rails-60/config/initializers/mime_types.rb new file mode 100644 index 000000000..dc1899682 --- /dev/null +++ b/example/rails-60/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/example/rails-60/config/initializers/wrap_parameters.rb b/example/rails-60/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..bbfc3961b --- /dev/null +++ b/example/rails-60/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/example/rails-60/config/locales/en.yml b/example/rails-60/config/locales/en.yml new file mode 100644 index 000000000..cf9b342d0 --- /dev/null +++ b/example/rails-60/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/example/rails-60/config/puma.rb b/example/rails-60/config/puma.rb new file mode 100644 index 000000000..5ed443774 --- /dev/null +++ b/example/rails-60/config/puma.rb @@ -0,0 +1,38 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/example/rails-60/config/routes.rb b/example/rails-60/config/routes.rb new file mode 100644 index 000000000..1bb035f6a --- /dev/null +++ b/example/rails-60/config/routes.rb @@ -0,0 +1,26 @@ +Rails.application.routes.draw do + # Vanilla rails routing + get '/', to: 'application#index' + get '/crash', to: 'application#crash' + get '/crash_with_callback', to: 'application#callback' + get '/notify', to: 'application#notify' + get '/notify_data', to: 'application#data' + get '/notify_severity', to: 'application#severity' + + # Sidekiq routing + get '/sidekiq', to: 'sidekiq#index' + get '/sidekiq/crash', to: 'sidekiq#crash' + get '/sidekiq/notify_data', to: 'sidekiq#metadata' + get '/sidekiq/crash_with_callback', to: 'sidekiq#callbacks' + + # Que routing + get '/que', to: 'que#index' + get '/que/crash', to: 'que#crash' + get '/que/notify_data', to: 'que#metadata' + get '/que/crash_with_callback', to: 'que#callbacks' + + # Resque routing + get '/resque', to: 'resque#index' + get '/resque/crash', to: 'resque#crash' + get '/resque/crash_with_callback', to: 'resque#callbacks' +end diff --git a/example/rails-60/config/spring.rb b/example/rails-60/config/spring.rb new file mode 100644 index 000000000..db5bf1307 --- /dev/null +++ b/example/rails-60/config/spring.rb @@ -0,0 +1,6 @@ +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/example/rails-60/config/storage.yml b/example/rails-60/config/storage.yml new file mode 100644 index 000000000..d32f76e8f --- /dev/null +++ b/example/rails-60/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/example/rails-60/config/webpack/development.js b/example/rails-60/config/webpack/development.js new file mode 100644 index 000000000..c5edff94a --- /dev/null +++ b/example/rails-60/config/webpack/development.js @@ -0,0 +1,5 @@ +process.env.NODE_ENV = process.env.NODE_ENV || 'development' + +const environment = require('./environment') + +module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpack/environment.js b/example/rails-60/config/webpack/environment.js new file mode 100644 index 000000000..d16d9af74 --- /dev/null +++ b/example/rails-60/config/webpack/environment.js @@ -0,0 +1,3 @@ +const { environment } = require('@rails/webpacker') + +module.exports = environment diff --git a/example/rails-60/config/webpack/production.js b/example/rails-60/config/webpack/production.js new file mode 100644 index 000000000..be0f53aac --- /dev/null +++ b/example/rails-60/config/webpack/production.js @@ -0,0 +1,5 @@ +process.env.NODE_ENV = process.env.NODE_ENV || 'production' + +const environment = require('./environment') + +module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpack/test.js b/example/rails-60/config/webpack/test.js new file mode 100644 index 000000000..c5edff94a --- /dev/null +++ b/example/rails-60/config/webpack/test.js @@ -0,0 +1,5 @@ +process.env.NODE_ENV = process.env.NODE_ENV || 'development' + +const environment = require('./environment') + +module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpacker.yml b/example/rails-60/config/webpacker.yml new file mode 100644 index 000000000..8581ac047 --- /dev/null +++ b/example/rails-60/config/webpacker.yml @@ -0,0 +1,96 @@ +# Note: You must restart bin/webpack-dev-server for changes to take effect + +default: &default + source_path: app/javascript + source_entry_path: packs + public_root_path: public + public_output_path: packs + cache_path: tmp/cache/webpacker + check_yarn_integrity: false + webpack_compile_output: true + + # Additional paths webpack should lookup modules + # ['app/assets', 'engine/foo/app/assets'] + resolved_paths: [] + + # Reload manifest.json on all requests so we reload latest compiled packs + cache_manifest: false + + # Extract and emit a css file + extract_css: false + + static_assets_extensions: + - .jpg + - .jpeg + - .png + - .gif + - .tiff + - .ico + - .svg + - .eot + - .otf + - .ttf + - .woff + - .woff2 + + extensions: + - .mjs + - .js + - .sass + - .scss + - .css + - .module.sass + - .module.scss + - .module.css + - .png + - .svg + - .gif + - .jpeg + - .jpg + +development: + <<: *default + compile: true + + # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules + check_yarn_integrity: true + + # Reference: https://webpack.js.org/configuration/dev-server/ + dev_server: + https: false + host: localhost + port: 3035 + public: localhost:3035 + hmr: false + # Inline should be set to true if using HMR + inline: true + overlay: true + compress: true + disable_host_check: true + use_local_ip: false + quiet: false + pretty: false + headers: + 'Access-Control-Allow-Origin': '*' + watch_options: + ignored: '**/node_modules/**' + + +test: + <<: *default + compile: true + + # Compile test packs to a separate directory + public_output_path: packs-test + +production: + <<: *default + + # Production depends on precompilation of packs prior to booting for performance. + compile: false + + # Extract and emit a css file + extract_css: true + + # Cache manifest.json for performance + cache_manifest: true diff --git a/example/rails-60/db/seeds.rb b/example/rails-60/db/seeds.rb new file mode 100644 index 000000000..1beea2acc --- /dev/null +++ b/example/rails-60/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/example/rails-60/lib/assets/.keep b/example/rails-60/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/lib/tasks/.keep b/example/rails-60/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/log/.keep b/example/rails-60/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/package.json b/example/rails-60/package.json new file mode 100644 index 000000000..4b504698a --- /dev/null +++ b/example/rails-60/package.json @@ -0,0 +1,15 @@ +{ + "name": "rails_60", + "private": true, + "dependencies": { + "@rails/actioncable": "^6.0.0", + "@rails/activestorage": "^6.0.0", + "@rails/ujs": "^6.0.0", + "@rails/webpacker": "4.2.2", + "turbolinks": "^5.2.0" + }, + "version": "0.1.0", + "devDependencies": { + "webpack-dev-server": "^3.11.0" + } +} diff --git a/example/rails-60/postcss.config.js b/example/rails-60/postcss.config.js new file mode 100644 index 000000000..aa5998a80 --- /dev/null +++ b/example/rails-60/postcss.config.js @@ -0,0 +1,12 @@ +module.exports = { + plugins: [ + require('postcss-import'), + require('postcss-flexbugs-fixes'), + require('postcss-preset-env')({ + autoprefixer: { + flexbox: 'no-2009' + }, + stage: 3 + }) + ] +} diff --git a/example/rails-60/public/404.html b/example/rails-60/public/404.html new file mode 100644 index 000000000..2be3af26f --- /dev/null +++ b/example/rails-60/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/example/rails-60/public/422.html b/example/rails-60/public/422.html new file mode 100644 index 000000000..c08eac0d1 --- /dev/null +++ b/example/rails-60/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/example/rails-60/public/500.html b/example/rails-60/public/500.html new file mode 100644 index 000000000..78a030af2 --- /dev/null +++ b/example/rails-60/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/example/rails-60/public/apple-touch-icon-precomposed.png b/example/rails-60/public/apple-touch-icon-precomposed.png new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/public/apple-touch-icon.png b/example/rails-60/public/apple-touch-icon.png new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/public/favicon.ico b/example/rails-60/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/public/robots.txt b/example/rails-60/public/robots.txt new file mode 100644 index 000000000..c19f78ab6 --- /dev/null +++ b/example/rails-60/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/example/rails-60/storage/.keep b/example/rails-60/storage/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/tmp/.keep b/example/rails-60/tmp/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/example/rails-60/tmp/pids/.keep b/example/rails-60/tmp/pids/.keep new file mode 100644 index 000000000..e69de29bb From 9ccdeaab86dcd0a0dec02e94be3612b70653f22e Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 16:12:37 +0100 Subject: [PATCH 12/44] Add Sidekiq examples --- example/rails-60/Gemfile | 3 ++ .../app/controllers/sidekiq_controller.rb | 17 +++++++ .../app/views/sidekiq/callbacks.html.erb | 12 +++++ .../rails-60/app/views/sidekiq/crash.html.erb | 8 ++++ .../rails-60/app/views/sidekiq/index.html.erb | 47 +++++++++++++++++++ .../app/views/sidekiq/metadata.html.erb | 12 +++++ .../rails-60/app/workers/sidekiq_workers.rb | 47 +++++++++++++++++++ 7 files changed, 146 insertions(+) create mode 100644 example/rails-60/app/controllers/sidekiq_controller.rb create mode 100644 example/rails-60/app/views/sidekiq/callbacks.html.erb create mode 100644 example/rails-60/app/views/sidekiq/crash.html.erb create mode 100644 example/rails-60/app/views/sidekiq/index.html.erb create mode 100644 example/rails-60/app/views/sidekiq/metadata.html.erb create mode 100644 example/rails-60/app/workers/sidekiq_workers.rb diff --git a/example/rails-60/Gemfile b/example/rails-60/Gemfile index ea8532f35..408c63fa5 100644 --- a/example/rails-60/Gemfile +++ b/example/rails-60/Gemfile @@ -4,6 +4,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Install Bugsnag gem "bugsnag", path: "../../" +# Example task queues +gem "sidekiq" + # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.3', '>= 6.0.3.1' # Use sqlite3 as the database for Active Record diff --git a/example/rails-60/app/controllers/sidekiq_controller.rb b/example/rails-60/app/controllers/sidekiq_controller.rb new file mode 100644 index 000000000..b925be414 --- /dev/null +++ b/example/rails-60/app/controllers/sidekiq_controller.rb @@ -0,0 +1,17 @@ +require './app/workers/sidekiq_workers' + +class SidekiqController < ActionController::Base + layout "application" + + def crash + SidekiqWorkers::CrashWorker.perform_async + end + + def metadata + SidekiqWorkers::MetadataWorker.perform_async + end + + def callbacks + SidekiqWorkers::CallbackWorker.perform_async + end +end diff --git a/example/rails-60/app/views/sidekiq/callbacks.html.erb b/example/rails-60/app/views/sidekiq/callbacks.html.erb new file mode 100644 index 000000000..14bb48406 --- /dev/null +++ b/example/rails-60/app/views/sidekiq/callbacks.html.erb @@ -0,0 +1,12 @@ +

Sidekiq

+ +

+ Sidekiq is performing a task that will crash, but registers a callback + before this to attach additional metadata. +

+ +

+ Check your Bugsnag dashboard for the result! +

+ +

← return to Sidekiq examples

diff --git a/example/rails-60/app/views/sidekiq/crash.html.erb b/example/rails-60/app/views/sidekiq/crash.html.erb new file mode 100644 index 000000000..010630a2a --- /dev/null +++ b/example/rails-60/app/views/sidekiq/crash.html.erb @@ -0,0 +1,8 @@ +

Sidekiq

+ +

+ Sidekiq is performing a task that will crash, so check + your Bugsnag dashboard for the result! +

+ +

← return to Sidekiq examples

diff --git a/example/rails-60/app/views/sidekiq/index.html.erb b/example/rails-60/app/views/sidekiq/index.html.erb new file mode 100644 index 000000000..110b6746c --- /dev/null +++ b/example/rails-60/app/views/sidekiq/index.html.erb @@ -0,0 +1,47 @@ +

Sidekiq

+ +

This route demonstrates how to use Bugsnag with Sidekiq.

+ +

+ While testing the examples open + your Bugsnag dashboard + in order to see the example errors and exceptions being received. +

+ +

+ Make sure you have a Redis instance running that your test application can + connect to before running these examples. +

+ +
    +
  1. +

    Crash

    + +

    Raises an error within the framework, generating a report in the Bugsnag dashboard.

    +
  2. + +
  3. +

    Crash and use callbacks

    + +

    + Raises an exception within the framework, but with additional data + attached to the report. By registering a callback before the error + occurs useful data can be attached as a tab in the Bugsnag dashboard. +

    +
  4. + +
  5. +

    Notify with data

    + +

    + Sends Bugsnag a report on demand using bugsnag.notify + and attaches additional data within a block, similar to + the "Crash and use callbacks" example above. In this case we're + adding information about the function being called to go into the + function tab, and additional diagnostics + as a diagnostics tab. +

    +
  6. +
+ +

← return home

diff --git a/example/rails-60/app/views/sidekiq/metadata.html.erb b/example/rails-60/app/views/sidekiq/metadata.html.erb new file mode 100644 index 000000000..78f0c218f --- /dev/null +++ b/example/rails-60/app/views/sidekiq/metadata.html.erb @@ -0,0 +1,12 @@ +

Sidekiq

+ +

+ Sidekiq is performing a task that will notify an error with some metadata + without crashing. +

+ +

+ Check your Bugsnag dashboard for the result! +

+ +

← return to Sidekiq examples

diff --git a/example/rails-60/app/workers/sidekiq_workers.rb b/example/rails-60/app/workers/sidekiq_workers.rb new file mode 100644 index 000000000..59bfddef1 --- /dev/null +++ b/example/rails-60/app/workers/sidekiq_workers.rb @@ -0,0 +1,47 @@ +module SidekiqWorkers + class CallbackWorker + include Sidekiq::Worker + + sidekiq_options :retry => false + + def perform + Bugsnag.before_notify_callbacks << proc { |report| + report.add_tab(:diagnostics, { + message: 'Sidekiq demo says: Everything is great', + code: 200 + }) + } + + raise 'Sidekiq crashed, but the callback added metadata - Check your Bugsnag dashboard' + end + end + + class CrashWorker + include Sidekiq::Worker + sidekiq_options :retry => false + + def perform + raise 'Sidekiq crashed - Check your Bugsnag dashboard' + end + end + + class MetadataWorker + include Sidekiq::Worker + sidekiq_options :retry => false + + def perform + error = Exception.new('Sidekiq notified with metadata - Check your Bugsnag dashboard') + + Bugsnag.notify(error) do |report| + report.add_tab(:function, { + name: 'Metadata', + fatal: false + }) + + report.add_tab(:diagnostics, { + message: 'Sidekiq demo says: Everything is great', + }) + end + end + end +end From e7ca457371b8320f17cdb383cb51144f1a437793 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 16:57:35 +0100 Subject: [PATCH 13/44] Add Que examples --- example/rails-60/Gemfile | 7 ++- .../app/controllers/que_controller.rb | 14 +++++ example/rails-60/app/jobs/que_callback.rb | 14 +++++ example/rails-60/app/jobs/que_crash.rb | 7 +++ .../rails-60/app/views/que/callbacks.html.erb | 8 +++ example/rails-60/app/views/que/crash.html.erb | 8 +++ example/rails-60/app/views/que/index.html.erb | 41 ++++++++++++ .../app/views/resque/callbacks.html.erb | 1 + .../rails-60/app/views/resque/crash.html.erb | 1 + .../rails-60/app/views/resque/index.html.erb | 1 + .../app/views/resque/metadata.html.erb | 1 + example/rails-60/config/database.yml | 7 +++ example/rails-60/config/environments/que.rb | 62 +++++++++++++++++++ example/rails-60/config/webpacker.yml | 4 +- 14 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 example/rails-60/app/controllers/que_controller.rb create mode 100644 example/rails-60/app/jobs/que_callback.rb create mode 100644 example/rails-60/app/jobs/que_crash.rb create mode 100644 example/rails-60/app/views/que/callbacks.html.erb create mode 100644 example/rails-60/app/views/que/crash.html.erb create mode 100644 example/rails-60/app/views/que/index.html.erb create mode 100644 example/rails-60/app/views/resque/callbacks.html.erb create mode 100644 example/rails-60/app/views/resque/crash.html.erb create mode 100644 example/rails-60/app/views/resque/index.html.erb create mode 100644 example/rails-60/app/views/resque/metadata.html.erb create mode 100644 example/rails-60/config/environments/que.rb diff --git a/example/rails-60/Gemfile b/example/rails-60/Gemfile index 408c63fa5..f74885537 100644 --- a/example/rails-60/Gemfile +++ b/example/rails-60/Gemfile @@ -5,12 +5,15 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem "bugsnag", path: "../../" # Example task queues +gem "que" gem "sidekiq" # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.3', '>= 6.0.3.1' -# Use sqlite3 as the database for Active Record -gem 'sqlite3', '~> 1.4' +# Use sqlite3 and pg as the database for Active Record +gem 'pg' +gem 'sqlite3' + # Use Puma as the app server gem 'puma', '~> 4.1' # Use SCSS for stylesheets diff --git a/example/rails-60/app/controllers/que_controller.rb b/example/rails-60/app/controllers/que_controller.rb new file mode 100644 index 000000000..eb7529196 --- /dev/null +++ b/example/rails-60/app/controllers/que_controller.rb @@ -0,0 +1,14 @@ +require './app/jobs/que_crash' +require './app/jobs/que_callback' + +class QueController < ActionController::Base + layout "application" + + def crash + QueCrash.enqueue + end + + def callbacks + QueCallback.enqueue + end +end diff --git a/example/rails-60/app/jobs/que_callback.rb b/example/rails-60/app/jobs/que_callback.rb new file mode 100644 index 000000000..34efe9a48 --- /dev/null +++ b/example/rails-60/app/jobs/que_callback.rb @@ -0,0 +1,14 @@ +class QueCallback < Que::Job + @run_at = proc { 5.seconds.from_now } + + def run(_options = {}) + Bugsnag.before_notify_callbacks << proc { |report| + report.add_tab(:diagnostics, { + message: 'Que demo says: Everything is great', + code: 200 + }) + } + + raise 'Oh no!' + end +end diff --git a/example/rails-60/app/jobs/que_crash.rb b/example/rails-60/app/jobs/que_crash.rb new file mode 100644 index 000000000..b6f2a3b04 --- /dev/null +++ b/example/rails-60/app/jobs/que_crash.rb @@ -0,0 +1,7 @@ +class QueCrash < Que::Job + @run_at = proc { 5.seconds.from_now } + + def run(_options = {}) + raise "Oh no" + end +end diff --git a/example/rails-60/app/views/que/callbacks.html.erb b/example/rails-60/app/views/que/callbacks.html.erb new file mode 100644 index 000000000..d7e5095f1 --- /dev/null +++ b/example/rails-60/app/views/que/callbacks.html.erb @@ -0,0 +1,8 @@ +

Que

+ +

+ Que has queued the callbacks task, check + your Bugsnag dashboard for the result! +

+ +

← return to Que examples

diff --git a/example/rails-60/app/views/que/crash.html.erb b/example/rails-60/app/views/que/crash.html.erb new file mode 100644 index 000000000..d3d004644 --- /dev/null +++ b/example/rails-60/app/views/que/crash.html.erb @@ -0,0 +1,8 @@ +

Que

+ +

+ Que has queued the crash task, check + your Bugsnag dashboard for the result! +

+ +

← return to Que examples

diff --git a/example/rails-60/app/views/que/index.html.erb b/example/rails-60/app/views/que/index.html.erb new file mode 100644 index 000000000..369fa2ebb --- /dev/null +++ b/example/rails-60/app/views/que/index.html.erb @@ -0,0 +1,41 @@ +

Bugsnag Que demo

+ +

This route demonstrates how to use Bugsnag with Que.

+ +

+ While testing the examples open + your Bugsnag dashboard + in order to see the example errors and exceptions being received. +

+ +

+ Make sure you have a PostgreSQL instance running that your test application + can connect to before running these examples. +

+ +
    +
  1. +

    Crash

    + +

    + Raises an error within the framework, generating a report in the + Bugsnag dashboard. +

    +
  2. + +
  3. + Crash and use callbacks + +

    + Raises an exception within the framework, but with additional data + attached to the report. +

    + +

    + By registering a callback before the error occurs useful data can + be attached as a tab in the Bugsnag dashboard. +

    +
  4. +
+ +

← return home

diff --git a/example/rails-60/app/views/resque/callbacks.html.erb b/example/rails-60/app/views/resque/callbacks.html.erb new file mode 100644 index 000000000..aa2786a7d --- /dev/null +++ b/example/rails-60/app/views/resque/callbacks.html.erb @@ -0,0 +1 @@ +<%= markdown(@text)%> \ No newline at end of file diff --git a/example/rails-60/app/views/resque/crash.html.erb b/example/rails-60/app/views/resque/crash.html.erb new file mode 100644 index 000000000..aa2786a7d --- /dev/null +++ b/example/rails-60/app/views/resque/crash.html.erb @@ -0,0 +1 @@ +<%= markdown(@text)%> \ No newline at end of file diff --git a/example/rails-60/app/views/resque/index.html.erb b/example/rails-60/app/views/resque/index.html.erb new file mode 100644 index 000000000..aa2786a7d --- /dev/null +++ b/example/rails-60/app/views/resque/index.html.erb @@ -0,0 +1 @@ +<%= markdown(@text)%> \ No newline at end of file diff --git a/example/rails-60/app/views/resque/metadata.html.erb b/example/rails-60/app/views/resque/metadata.html.erb new file mode 100644 index 000000000..aa2786a7d --- /dev/null +++ b/example/rails-60/app/views/resque/metadata.html.erb @@ -0,0 +1 @@ +<%= markdown(@text)%> \ No newline at end of file diff --git a/example/rails-60/config/database.yml b/example/rails-60/config/database.yml index 4a8a1b26f..832c7883a 100644 --- a/example/rails-60/config/database.yml +++ b/example/rails-60/config/database.yml @@ -9,6 +9,13 @@ default: &default pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 +que: + adapter: postgresql + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: localhost + timeout: 5000 + database: quedb + development: <<: *default database: db/development.sqlite3 diff --git a/example/rails-60/config/environments/que.rb b/example/rails-60/config/environments/que.rb new file mode 100644 index 000000000..66df51f6f --- /dev/null +++ b/example/rails-60/config/environments/que.rb @@ -0,0 +1,62 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/example/rails-60/config/webpacker.yml b/example/rails-60/config/webpacker.yml index 8581ac047..e9806ed84 100644 --- a/example/rails-60/config/webpacker.yml +++ b/example/rails-60/config/webpacker.yml @@ -48,7 +48,7 @@ default: &default - .jpeg - .jpg -development: +development: &development <<: *default compile: true @@ -75,6 +75,8 @@ development: watch_options: ignored: '**/node_modules/**' +que: + <<: *development test: <<: *default From ebb6faea54c34d39f6a7b3d176f6149fac73e691 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 17:30:31 +0100 Subject: [PATCH 14/44] Add Resque examples --- example/rails-60/Gemfile | 1 + .../app/assets/stylesheets/application.css | 10 +++ .../app/controllers/resque_controller.rb | 15 +++++ .../app/views/resque/callbacks.html.erb | 18 ++++- .../rails-60/app/views/resque/crash.html.erb | 18 ++++- .../rails-60/app/views/resque/index.html.erb | 65 ++++++++++++++++++- .../app/views/resque/metadata.html.erb | 18 ++++- .../rails-60/app/workers/resque_workers.rb | 47 ++++++++++++++ example/rails-60/config/routes.rb | 1 + example/rails-60/lib/tasks/.keep | 0 example/rails-60/lib/tasks/resque:setup.rake | 5 ++ 11 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 example/rails-60/app/controllers/resque_controller.rb create mode 100644 example/rails-60/app/workers/resque_workers.rb delete mode 100644 example/rails-60/lib/tasks/.keep create mode 100644 example/rails-60/lib/tasks/resque:setup.rake diff --git a/example/rails-60/Gemfile b/example/rails-60/Gemfile index f74885537..48a19fc08 100644 --- a/example/rails-60/Gemfile +++ b/example/rails-60/Gemfile @@ -6,6 +6,7 @@ gem "bugsnag", path: "../../" # Example task queues gem "que" +gem "resque" gem "sidekiq" # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' diff --git a/example/rails-60/app/assets/stylesheets/application.css b/example/rails-60/app/assets/stylesheets/application.css index 74b4724f8..de36540b2 100644 --- a/example/rails-60/app/assets/stylesheets/application.css +++ b/example/rails-60/app/assets/stylesheets/application.css @@ -25,6 +25,16 @@ code { font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; } +pre { + background: rgba(0, 0, 0, .05); + border: 1px solid rgba(0, 0, 0, .1); + padding: 1rem; +} + +pre.shell::before { + content: '$ '; +} + a:link, a:visited { color: #536eec; diff --git a/example/rails-60/app/controllers/resque_controller.rb b/example/rails-60/app/controllers/resque_controller.rb new file mode 100644 index 000000000..2bdea9196 --- /dev/null +++ b/example/rails-60/app/controllers/resque_controller.rb @@ -0,0 +1,15 @@ +class ResqueController < ActionController::Base + layout "application" + + def crash + Resque.enqueue(ResqueWorkers::Crash) + end + + def metadata + Resque.enqueue(ResqueWorkers::Metadata) + end + + def callbacks + Resque.enqueue(ResqueWorkers::Callback) + end +end diff --git a/example/rails-60/app/views/resque/callbacks.html.erb b/example/rails-60/app/views/resque/callbacks.html.erb index aa2786a7d..d730810d8 100644 --- a/example/rails-60/app/views/resque/callbacks.html.erb +++ b/example/rails-60/app/views/resque/callbacks.html.erb @@ -1 +1,17 @@ -<%= markdown(@text)%> \ No newline at end of file +

Resque

+ +

+ The callback task has been queued. +

+ +

+ This can be executed by running: +

+ +
QUEUE=callback bundle exec rake resque:work
+ +

+ Check your Bugsnag dashboard for the result! +

+ +

← return to Resque examples

diff --git a/example/rails-60/app/views/resque/crash.html.erb b/example/rails-60/app/views/resque/crash.html.erb index aa2786a7d..2d28f986e 100644 --- a/example/rails-60/app/views/resque/crash.html.erb +++ b/example/rails-60/app/views/resque/crash.html.erb @@ -1 +1,17 @@ -<%= markdown(@text)%> \ No newline at end of file +

Resque

+ +

+ The crash task has been queued. +

+ +

+ This can be executed by running: +

+ +
QUEUE=crash bundle exec rake resque:work
+ +

+ Check your Bugsnag dashboard for the result! +

+ +

← return to Resque examples

diff --git a/example/rails-60/app/views/resque/index.html.erb b/example/rails-60/app/views/resque/index.html.erb index aa2786a7d..7f5e4d763 100644 --- a/example/rails-60/app/views/resque/index.html.erb +++ b/example/rails-60/app/views/resque/index.html.erb @@ -1 +1,64 @@ -<%= markdown(@text)%> \ No newline at end of file +

Rescue

+ +

This route demonstrates how to use Bugsnag with Rescue.

+ +

+ While testing the examples open + your Bugsnag dashboard + in order to see the example errors and exceptions being received. +

+ +

+ Make sure you have a Redis instance running that your test application can + connect to before running these examples. +

+ +

+ While each queue can be run individually, to run Resque so that it + automatically executes each task, use: +

+ +
QUEUE=crash,callback,metadata bundle exec rake resque:work
+ +
    +
  1. +

    Crash

    + +

    + Raises an error within the framework, generating a report in the + Bugsnag dashboard. +

    +
  2. + +
  3. +

    Crash and use callbacks

    + +

    + Raises an exception within the framework, but with additional data + attached to the report. +

    + +

    + By registering a callback before the error occurs useful data can + be attached as a tab in the Bugsnag dashboard. +

    +
  4. + +
  5. +

    Notify with data

    + +

    + Same as notify but allows you to attach additional data + within a block, similar to the + "crash and use callbacks" example above. +

    + +

    + In this case we're adding information about the queue to go into the + queue tab, and additional diagnostics as a + diagnostics tab. +

    +
  6. +
+ +

← return home

diff --git a/example/rails-60/app/views/resque/metadata.html.erb b/example/rails-60/app/views/resque/metadata.html.erb index aa2786a7d..c35532cad 100644 --- a/example/rails-60/app/views/resque/metadata.html.erb +++ b/example/rails-60/app/views/resque/metadata.html.erb @@ -1 +1,17 @@ -<%= markdown(@text)%> \ No newline at end of file +

Resque

+ +

+ The metadata task has been queued. +

+ +

+ This can be executed by running: +

+ +
QUEUE=metadata bundle exec rake resque:work
+ +

+ Check your Bugsnag dashboard for the result! +

+ +

← return to Resque examples

diff --git a/example/rails-60/app/workers/resque_workers.rb b/example/rails-60/app/workers/resque_workers.rb new file mode 100644 index 000000000..1b0feee35 --- /dev/null +++ b/example/rails-60/app/workers/resque_workers.rb @@ -0,0 +1,47 @@ +module ResqueWorkers + class Crash + @queue = :crash + + def self.perform + raise 'Crashed - Check your Bugsnag dashboard' + end + end + + # Unhandled with callback Exception example + class Callback + @queue = :callback + + def self.perform + Bugsnag.before_notify_callbacks << proc { |report| + report.add_tab(:diagnostics, { + message: 'Resque demo says: Everything is great', + code: 200 + }) + } + + raise 'Crashed - Check the Bugsnag dashboard for diagnostic data' + end + end + + # Handled example with additional data + class Metadata + @queue = :metadata + + def self.perform + error = Exception.new "Didn't crash, but sent a notification anyway" + + Bugsnag.notify(error) do |report| + report.add_tab(:queue, { + :name => "metadata", + :fatal => false + }) + + report.add_tab(:diagnostics, { + :message => 'Resque demo says: Everything is great' + }) + end + + puts "The Resque worker hasn't crashed, but it has sent a notification, with additional data to the dashboard" + end + end +end diff --git a/example/rails-60/config/routes.rb b/example/rails-60/config/routes.rb index 1bb035f6a..b5f1747c3 100644 --- a/example/rails-60/config/routes.rb +++ b/example/rails-60/config/routes.rb @@ -23,4 +23,5 @@ get '/resque', to: 'resque#index' get '/resque/crash', to: 'resque#crash' get '/resque/crash_with_callback', to: 'resque#callbacks' + get '/resque/notify_data', to: 'resque#metadata' end diff --git a/example/rails-60/lib/tasks/.keep b/example/rails-60/lib/tasks/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/example/rails-60/lib/tasks/resque:setup.rake b/example/rails-60/lib/tasks/resque:setup.rake new file mode 100644 index 000000000..1c97b45ea --- /dev/null +++ b/example/rails-60/lib/tasks/resque:setup.rake @@ -0,0 +1,5 @@ +require 'resque/tasks' + +task 'resque:setup' => :environment do + require './app/workers/resque_workers' +end From 3ef251dec90102aeda76f11e386722fa11d1c134 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 17:33:37 +0100 Subject: [PATCH 15/44] Disable pointer events on '$' in shell examples --- example/rails-60/app/assets/stylesheets/application.css | 1 + 1 file changed, 1 insertion(+) diff --git a/example/rails-60/app/assets/stylesheets/application.css b/example/rails-60/app/assets/stylesheets/application.css index de36540b2..c22e35561 100644 --- a/example/rails-60/app/assets/stylesheets/application.css +++ b/example/rails-60/app/assets/stylesheets/application.css @@ -33,6 +33,7 @@ pre { pre.shell::before { content: '$ '; + pointer-events: none; } a:link, From a0fa06204c0994ec6434a8bc4604c0f91351f177 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 17:36:06 +0100 Subject: [PATCH 16/44] Add README for rails 6.0 example --- example/rails-60/README.md | 138 +++++++++++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 13 deletions(-) diff --git a/example/rails-60/README.md b/example/rails-60/README.md index 7db80e4ca..e23db7d73 100644 --- a/example/rails-60/README.md +++ b/example/rails-60/README.md @@ -1,24 +1,136 @@ -# README +# Bugsnag Rails v6.0 demo -This README would normally document whatever steps are necessary to get the -application up and running. +This Rails application demonstrates how to use Bugsnag with Rails v6.0, as well as integrating it into Sidekiq, Que, and Resque. +Further details about integrating Bugsnag with Rails applications can be found [here.](https://docs.bugsnag.com/platforms/ruby/rails/) -Things you may want to cover: +Install dependencies -* Ruby version +```shell +bundle install +``` -* System dependencies +Install local binaries (if needed): -* Configuration +```shell +bundle exec rake app:update:bin +``` -* Database creation +## Rails v6.0 -* Database initialization +### Configuration -* How to run the test suite +There are two methods of configuring Bugsnag within a Rails application: -* Services (job queues, cache servers, search engines, etc.) +1. Your `API_KEY` can be exported as an environment variable `BUGSNAG_API_KEY`. -* Deployment instructions +2. Generate a bugsnag configuration file at ```config/initializers/bugsnag.rb``` which can be populated with the [available configuration options](https://docs.bugsnag.com/platforms/ruby/rails/configuration-options/) by running the rails command: + ```shell + bundle exec bin/rails generate bugsnag YOUR_API_KEY_HERE + ``` -* ... +This is sufficient to start reporting unhandled exceptions to Bugsnag. + +### Running the example + +Run the example using: + +```shell +bundle exec bin/rails server +``` + +Once the server is running, head to the default path for more information on Bugsnag logging examples. + +## Sidekiq in Rails + +Sidekiq requires a datastore to run, this example uses [redis](https://redis.io/), installation instructions for which can be found [here](https://redis.io/topics/quickstart) and an official docker image can be found [here](https://hub.docker.com/_/redis/). + +### Configuration + +Once the configuration has been added to the Rails environment there is no need to further configure Sidekiq. + +### Running the examples + +Start the Rails server as mentioned above. + +Navigate to the `/sidekiq` page and run any of the examples using the links provided. + +The worker code can be found in `app/workers/sidekiq_workers.rb`. + +To process the jobs, run Sidekiq using the following command: + +```shell +bundle exec sidekiq +``` + +## Que in Rails + +Que requires a database backend in order to queue jobs. By default this database will be PostgreSQL although this can be changed via options as detailed in [the que documentation](https://github.com/chanks/que). + +Once PostgreSQL is set up as detailed using [the PostgreSQL documentation](https://www.postgresql.org/docs/), ensure Que can connect correctly before running any of the following examples which reference a `quedb` that can be created with the following command: + +```shell +createdb quedb +``` + +You can configure your connection in the `config/database.yml` file. + +### Configuration + +All tasks run with Que should set the rails environment to `que`. This ensures that the correct database and connection settings are used. +Do this by prepending `RAILS_ENV=que` before each command, or run: + +```shell +export RAILS_ENV=que +``` + +Ensure that the initial Que setup is complete by running: + +```shell +bundle exec bin/rails generate que:install +``` + +and + +```shell +bundle exec bin/rake db:migrate +``` + +Further configuration will be taken from the Rails environment. + +### Running the examples + +Start the Rails server as mentioned above. + +Navigate to the `/que` page and queue jobs for any of the examples using links provided. + +To process the jobs, run Que using the cli command: + +```shell +bundle exec que ./config/environment.rb +``` + +## Resque in Rails + +Resque requires a datastore to run, this example uses [redis](https://redis.io/), installation instructions for which can be found [here](https://redis.io/topics/quickstart) and an official docker image can be found [here](https://hub.docker.com/_/redis/). + +### Configuration + +Resque can be configured by using the Rails environment by making sure it depends on the `environment` task. This can be achieved when running the worker: + +```shell +QUEUE=crash bundle exec rake environment resque:work +``` + +Or by creating a task, `resque:setup`, that depends on the `environment` task. An example of this can be found in `lib/tasks/resque:setup.rake`. + +### Running the examples + +Start the Rails server as mentioned above. + +Navigate to the `/resque` page and queue any of the examples using links provided. + +To process the queues, run the `resque:work` task as stated in the example webpage. In order to process any of the queues on a single thread start the resque worker using the command: + +```shell +QUEUE=crash,callback,metadata bundle exec rake resque:work +``` From f9eb3b5ab0840dfe5aaf844bb0ae34a1cb1f4a3b Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 20 May 2020 17:38:43 +0100 Subject: [PATCH 17/44] Add missing paragraph tag --- example/rails-60/app/views/que/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/rails-60/app/views/que/index.html.erb b/example/rails-60/app/views/que/index.html.erb index 369fa2ebb..2568880cc 100644 --- a/example/rails-60/app/views/que/index.html.erb +++ b/example/rails-60/app/views/que/index.html.erb @@ -24,7 +24,7 @@
  • - Crash and use callbacks +

    Crash and use callbacks

    Raises an exception within the framework, but with additional data From 115cf93ace3ce6ebdb3b798f62b25a7d3c624430 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 18 Jun 2020 13:51:25 +0100 Subject: [PATCH 18/44] Remove the length limit on breadcrumb names --- CHANGELOG.md | 3 +++ lib/bugsnag/breadcrumbs/breadcrumbs.rb | 2 -- lib/bugsnag/breadcrumbs/validator.rb | 6 ------ spec/breadcrumbs/breadcrumb_spec.rb | 2 +- spec/breadcrumbs/validator_spec.rb | 27 +------------------------- spec/bugsnag_spec.rb | 4 ++-- 6 files changed, 7 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a95ef45..053bbfeac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Changelog * Add configurable `discard_classes` option to allow filtering errors using either a `String` or `Regexp` matched against the error's class name | [#597](https://github.com/bugsnag/bugsnag-ruby/pull/597) +* The Breadcrumb name limit of 30 characters has been removed + | [#600](https://github.com/bugsnag/bugsnag-ruby/pull/600) + ### Deprecated * The `ignore_classes` configuration option has been deprecated in favour of `discard_classes`. `ignore_classes` will be removed in the next major release diff --git a/lib/bugsnag/breadcrumbs/breadcrumbs.rb b/lib/bugsnag/breadcrumbs/breadcrumbs.rb index 24f140e1d..69506d29d 100644 --- a/lib/bugsnag/breadcrumbs/breadcrumbs.rb +++ b/lib/bugsnag/breadcrumbs/breadcrumbs.rb @@ -1,6 +1,4 @@ module Bugsnag::Breadcrumbs - MAX_NAME_LENGTH = 30 - VALID_BREADCRUMB_TYPES = [ ERROR_BREADCRUMB_TYPE = "error", MANUAL_BREADCRUMB_TYPE = "manual", diff --git a/lib/bugsnag/breadcrumbs/validator.rb b/lib/bugsnag/breadcrumbs/validator.rb index c6893b50a..d1f559492 100644 --- a/lib/bugsnag/breadcrumbs/validator.rb +++ b/lib/bugsnag/breadcrumbs/validator.rb @@ -15,12 +15,6 @@ def initialize(configuration) # # @param breadcrumb [Bugsnag::Breadcrumbs::Breadcrumb] the breadcrumb to be validated def validate(breadcrumb) - # Check name length - if breadcrumb.name.size > Bugsnag::Breadcrumbs::MAX_NAME_LENGTH - @configuration.debug("Breadcrumb name trimmed to length #{Bugsnag::Breadcrumbs::MAX_NAME_LENGTH}. Original name: #{breadcrumb.name}") - breadcrumb.name = breadcrumb.name.slice(0...Bugsnag::Breadcrumbs::MAX_NAME_LENGTH) - end - # Check meta_data hash doesn't contain complex values breadcrumb.meta_data = breadcrumb.meta_data.select do |k, v| if valid_meta_data_type?(v) diff --git a/spec/breadcrumbs/breadcrumb_spec.rb b/spec/breadcrumbs/breadcrumb_spec.rb index 3f315b327..acd3f72c2 100644 --- a/spec/breadcrumbs/breadcrumb_spec.rb +++ b/spec/breadcrumbs/breadcrumb_spec.rb @@ -90,4 +90,4 @@ ) end end -end \ No newline at end of file +end diff --git a/spec/breadcrumbs/validator_spec.rb b/spec/breadcrumbs/validator_spec.rb index 07e7b2c5b..581b243c3 100644 --- a/spec/breadcrumbs/validator_spec.rb +++ b/spec/breadcrumbs/validator_spec.rb @@ -31,31 +31,6 @@ validator.validate(breadcrumb) end - it "trims long messages to length and warns" do - config = instance_double(Bugsnag::Configuration) - allow(config).to receive(:enabled_automatic_breadcrumb_types).and_return(enabled_automatic_breadcrumb_types) - validator = Bugsnag::Breadcrumbs::Validator.new(config) - - name = "1234567890123456789012345678901234567890" - - breadcrumb = instance_double(Bugsnag::Breadcrumbs::Breadcrumb, { - :auto => auto, - :name => name, - :type => type, - :meta_data => meta_data, - :meta_data= => nil - }) - - expect(breadcrumb).to_not receive(:ignore!) - expect(breadcrumb).to receive(:name=).with("123456789012345678901234567890") - expected_string = "Breadcrumb name trimmed to length 30. Original name: #{name}" - expect(config).to receive(:debug).with(expected_string) - - validator.validate(breadcrumb) - # Check the original message has not been modified - expect(name).to eq("1234567890123456789012345678901234567890") - end - describe "tests meta_data types" do it "accepts Strings, Numerics, Booleans, & nil" do config = instance_double(Bugsnag::Configuration) @@ -198,4 +173,4 @@ class TestClass end end end -end \ No newline at end of file +end diff --git a/spec/bugsnag_spec.rb b/spec/bugsnag_spec.rb index 73e4b1237..07cc6121d 100644 --- a/spec/bugsnag_spec.rb +++ b/spec/bugsnag_spec.rb @@ -268,7 +268,7 @@ module Kernel ) expect(breadcrumbs.to_a.size).to eq(1) expect(breadcrumbs.first.to_h).to match({ - :name => "123123123123123123123123123123", + :name => "123123123123123123123123123123456456456456456456456456456456", :type => Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, :metaData => { :a => 1 @@ -311,7 +311,7 @@ module Kernel Bugsnag.leave_breadcrumb("TestName") expect(breadcrumbs.to_a.size).to eq(1) expect(breadcrumbs.first.to_h).to match({ - :name => "123123123123123123123123123123", + :name => "123123123123123123123123123123456456456456456", :type => Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE, :metaData => { :int => 1 From 56feeb0c55f09b521afe39507e76e1b04207d89d Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 18 Jun 2020 14:30:39 +0100 Subject: [PATCH 19/44] Install earlier version of rack on Ruby 2.2 --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index cd9633ade..93e21543b 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ group :sidekiq, optional: true do gem 'sidekiq', '~> 5.2.7' # redis 4.1.2 dropped support for Ruby 2.2 gem 'redis', ruby_version < Gem::Version.new('2.3.0') ? '4.1.1' : '>= 4.1.2' + # rack 2.2.0 dropped support for Ruby 2.2 + gem 'rack', ruby_version < Gem::Version.new('2.3.0') ? '< 2.2.0' : '~> 2.2' end group :doc, optional: true do From 9f404dc7ed6b44a6f7298bd2bebecc670d77103f Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Tue, 23 Jun 2020 17:53:30 +0100 Subject: [PATCH 20/44] Improve performance of cleaning objects This is a first iteration of improving how we clean objects when preparing to JSON encode them Currently we iterate over the payload multiple times; sometimes to clean up encoding errors/recursion and other times to filter sensitive data Ideally we should be iterating over the payload once, which is slightly complicated because we should only be filtering parts of the payload (the metadata and breadcrumb metadata) --- lib/bugsnag.rb | 9 ++++++++- lib/bugsnag/cleaner.rb | 7 +++++++ lib/bugsnag/helpers.rb | 6 ++---- lib/bugsnag/report.rb | 16 +++------------- spec/cleaner_spec.rb | 2 ++ spec/helper_spec.rb | 9 +++++++-- spec/report_spec.rb | 31 +++++++++++++++++++++++++++---- spec/spec_helper.rb | 2 +- 8 files changed, 57 insertions(+), 25 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 608a6edf6..f78d67a02 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -114,7 +114,14 @@ def notify(exception, auto_notify=false, &block) # Deliver configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}") options = {:headers => report.headers} - payload = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(report.as_json)) + + cleaner = Cleaner.new(configuration.meta_data_filters) + + cleaned = cleaner.clean_object(report.as_json) + trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) + + payload = ::JSON.dump(trimmed) + Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.notify_endpoint, payload, configuration, options) report_summary = report.summary leave_breadcrumb(report_summary[:error_class], report_summary, Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE, :auto) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index ea7539d86..737b129ea 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -128,6 +128,13 @@ def filters_match?(key) # If someone has a Rails filter like /^stuff\.secret/, it won't match "request.params.stuff.secret", # so we try it both with and without the "request.params." bit. def filters_match_deeply?(key, scope) + # FIXME: This is a hack! + # We don't want to apply filters to places outside of 'events.metaData' + # and 'events.breadcrumbs.metaData' as then we could redact things + # like our stacktraces, which is bad. We should implement this in a + # better way, but this makes the tests pass + return false unless scope.nil? || scope.start_with?('events.metaData') || scope.start_with?('events.breadcrumbs.metaData') + return true if filters_match?(key) return false unless @deep_filters diff --git a/lib/bugsnag/helpers.rb b/lib/bugsnag/helpers.rb index 99a3c2f21..21223f74a 100644 --- a/lib/bugsnag/helpers.rb +++ b/lib/bugsnag/helpers.rb @@ -17,12 +17,10 @@ module Helpers def self.trim_if_needed(value) value = "" if value.nil? - # Sanitize object - sanitized_value = Bugsnag::Cleaner.clean_object_encoding(value) - return sanitized_value unless payload_too_long?(sanitized_value) + return value unless payload_too_long?(value) # Trim metadata - reduced_value = trim_metadata(sanitized_value) + reduced_value = trim_metadata(value) return reduced_value unless payload_too_long?(reduced_value) # Trim code from stacktrace diff --git a/lib/bugsnag/report.rb b/lib/bugsnag/report.rb index c3b1e54aa..66b3ed7fd 100644 --- a/lib/bugsnag/report.rb +++ b/lib/bugsnag/report.rb @@ -97,6 +97,7 @@ def as_json releaseStage: release_stage, type: app_type }, + breadcrumbs: breadcrumbs.map(&:to_h), context: context, device: { hostname: hostname, @@ -104,6 +105,7 @@ def as_json }, exceptions: exceptions, groupingHash: grouping_hash, + metaData: meta_data, session: session, severity: severity, severityReason: severity_reason, @@ -111,19 +113,7 @@ def as_json user: user } - # cleanup character encodings - payload_event = Bugsnag::Cleaner.clean_object_encoding(payload_event) - - # filter out sensitive values in (and cleanup encodings) metaData - filter_cleaner = Bugsnag::Cleaner.new(configuration.meta_data_filters) - payload_event[:metaData] = filter_cleaner.clean_object(meta_data) - payload_event[:breadcrumbs] = breadcrumbs.map do |breadcrumb| - breadcrumb_hash = breadcrumb.to_h - breadcrumb_hash[:metaData] = filter_cleaner.clean_object(breadcrumb_hash[:metaData]) - breadcrumb_hash - end - - payload_event.reject! {|k,v| v.nil? } + payload_event.reject! {|k, v| v.nil? } # return the payload hash { diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index b40c657f2..3cc0ff0a3 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -166,11 +166,13 @@ def to_s end it "filters deeply nested keys" do + skip "this will not work until we implement scopes to filter" params = {:foo => {:bar => "baz"}} expect(described_class.new([/^foo\.bar/]).clean_object(params)).to eq({:foo => {:bar => '[FILTERED]'}}) end it "filters deeply nested request parameters" do + skip "this will not work until we implement scopes to filter" params = {:request => {:params => {:foo => {:bar => "baz"}}}} expect(described_class.new([/^foo\.bar/]).clean_object(params)).to eq({:request => {:params => {:foo => {:bar => '[FILTERED]'}}}}) end diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 57089afbe..e59acaa19 100644 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -8,6 +8,7 @@ describe "trim_if_needed" do it "breaks recursion" do + skip "TODO reimplement elsewhere (report_spec?)" a = [1, 2, 3] b = [2, a] a << b @@ -47,11 +48,13 @@ def to_s end it "uses the string '[RAISED]' instead" do + skip "TODO reimplement elsewhere (report_spec?)" value = Bugsnag::Helpers.trim_if_needed([1, 3, StringRaiser.new]) expect(value[2]).to eq "[RAISED]" end it "replaces hash key with '[RAISED]'" do + skip "TODO reimplement elsewhere (report_spec?)" a = {} a[StringRaiser.new] = 1 @@ -60,6 +63,7 @@ def to_s end it "uses a single '[RAISED]'key when multiple keys raise" do + skip "TODO reimplement elsewhere (report_spec?)" a = {} a[StringRaiser.new] = 1 a[StringRaiser.new] = 2 @@ -79,6 +83,7 @@ def to_s end it "uses the string '[RECURSION]' instead" do + skip "TODO reimplement elsewhere (report_spec?)" skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby value = Bugsnag::Helpers.trim_if_needed([1, 3, StringRecurser.new]) @@ -86,6 +91,7 @@ def to_s end it "replaces hash key with '[RECURSION]'" do + skip "TODO reimplement elsewhere (report_spec?)" skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby a = {} @@ -96,6 +102,7 @@ def to_s end it "uses a single '[RECURSION]'key when multiple keys recurse" do + skip "TODO reimplement elsewhere (report_spec?)" skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby a = {} @@ -108,7 +115,6 @@ def to_s end context "payload length is less than allowed" do - it "does not change strings" do value = SecureRandom.hex(4096) expect(Bugsnag::Helpers.trim_if_needed(value)).to eq value @@ -126,7 +132,6 @@ def to_s end context "payload length is greater than allowed" do - it "trims metadata strings" do payload = { :events => [{ diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 701b985bf..90488abac 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -592,7 +592,6 @@ def gloops end it "filters params from all payload hashes if they are set in default meta_data_filters" do - Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| report.meta_data.merge!({ :request => { @@ -638,7 +637,6 @@ def gloops end it "filters params from all payload hashes if they are added to meta_data_filters" do - Bugsnag.configuration.meta_data_filters << "other_data" Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| report.meta_data.merge!({:request => {:params => {:password => "1234", :other_password => "123456", :other_data => "123456"}}}) @@ -656,7 +654,6 @@ def gloops end it "filters params from all payload hashes if they are added to meta_data_filters as regex" do - Bugsnag.configuration.meta_data_filters << /other_data/ Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| report.meta_data.merge!({:request => {:params => {:password => "1234", :other_password => "123456", :other_data => "123456"}}}) @@ -674,7 +671,6 @@ def gloops end it "filters params from all payload hashes if they are added to meta_data_filters as partial regex" do - Bugsnag.configuration.meta_data_filters << /r_data/ Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| report.meta_data.merge!({:request => {:params => {:password => "1234", :other_password => "123456", :other_data => "123456"}}}) @@ -705,6 +701,33 @@ def gloops } end + it "does not apply filters outside of report.meta_data" do + Bugsnag.configuration.meta_data_filters << "data" + + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.meta_data = { + xyz: "abc", + data: "123456" + } + + report.user = { + id: 123, + data: "hello" + } + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + + expect(event["metaData"]).not_to be_nil + expect(event["metaData"]["xyz"]).to eq("abc") + expect(event["metaData"]["data"]).to eq("[FILTERED]") + + expect(event["user"]).not_to be_nil + expect(event["user"]["data"]).to eq("hello") + } + end + it "does not notify if report ignored" do Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| report.ignore! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6584fd1ea..2f6061dab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -83,4 +83,4 @@ def have_sent_notification(&matcher) raise "no matcher provided to have_sent_notification (did you use { })" end end -end \ No newline at end of file +end From 3888357fe6f55105c4925ac36950bd7cbc333e93 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 10:46:22 +0100 Subject: [PATCH 21/44] Move some tests to report_spec Helper no longer breaks recursion in 'trim_if_needed', so these tests no longer apply there. However we are still breaking recursion and so can test the same thing elsewhere --- spec/helper_spec.rb | 91 ------------------------- spec/report_spec.rb | 157 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 156 insertions(+), 92 deletions(-) diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index e59acaa19..11323c932 100644 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -4,24 +4,7 @@ require 'set' describe Bugsnag::Helpers do - describe "trim_if_needed" do - - it "breaks recursion" do - skip "TODO reimplement elsewhere (report_spec?)" - a = [1, 2, 3] - b = [2, a] - a << b - value = Bugsnag::Helpers.trim_if_needed(a) - expect(value).to eq([1, 2, 3, [2, "[RECURSION]"]]) - end - - it "does not break equal objects without recursion" do - data = [1, [1, 2], [1, 2], "a"] - value = Bugsnag::Helpers.trim_if_needed(data) - expect(value).to eq data - end - it "preserves bool types" do value = Bugsnag::Helpers.trim_if_needed([1, 3, true, "NO", "2", false]) expect(value[2]).to be_a(TrueClass) @@ -40,80 +23,6 @@ expect(value[4]).to be_a(String) end - context "an object will throw if `to_s` is called" do - class StringRaiser - def to_s - raise 'Oh no you do not!' - end - end - - it "uses the string '[RAISED]' instead" do - skip "TODO reimplement elsewhere (report_spec?)" - value = Bugsnag::Helpers.trim_if_needed([1, 3, StringRaiser.new]) - expect(value[2]).to eq "[RAISED]" - end - - it "replaces hash key with '[RAISED]'" do - skip "TODO reimplement elsewhere (report_spec?)" - a = {} - a[StringRaiser.new] = 1 - - value = Bugsnag::Helpers.trim_if_needed(a) - expect(value).to eq({ "[RAISED]" => "[FILTERED]" }) - end - - it "uses a single '[RAISED]'key when multiple keys raise" do - skip "TODO reimplement elsewhere (report_spec?)" - a = {} - a[StringRaiser.new] = 1 - a[StringRaiser.new] = 2 - - value = Bugsnag::Helpers.trim_if_needed(a) - expect(value).to eq({ "[RAISED]" => "[FILTERED]" }) - end - end - - context "an object will infinitely recurse if `to_s` is called" do - is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' - - class StringRecurser - def to_s - to_s - end - end - - it "uses the string '[RECURSION]' instead" do - skip "TODO reimplement elsewhere (report_spec?)" - skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby - - value = Bugsnag::Helpers.trim_if_needed([1, 3, StringRecurser.new]) - expect(value[2]).to eq "[RECURSION]" - end - - it "replaces hash key with '[RECURSION]'" do - skip "TODO reimplement elsewhere (report_spec?)" - skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby - - a = {} - a[StringRecurser.new] = 1 - - value = Bugsnag::Helpers.trim_if_needed(a) - expect(value).to eq({ "[RECURSION]" => "[FILTERED]" }) - end - - it "uses a single '[RECURSION]'key when multiple keys recurse" do - skip "TODO reimplement elsewhere (report_spec?)" - skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby - - a = {} - a[StringRecurser.new] = 1 - a[StringRecurser.new] = 2 - - value = Bugsnag::Helpers.trim_if_needed(a) - expect(value).to eq({ "[RECURSION]" => "[FILTERED]" }) - end - end - context "payload length is less than allowed" do it "does not change strings" do value = SecureRandom.hex(4096) diff --git a/spec/report_spec.rb b/spec/report_spec.rb index 90488abac..91126274d 100644 --- a/spec/report_spec.rb +++ b/spec/report_spec.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -require 'spec_helper' +require_relative './spec_helper' require 'securerandom' require 'ostruct' @@ -1131,6 +1131,161 @@ def gloops } end + it "should handle recursive metadata" do + a = [1, 2, 3] + b = [2, a] + a << b + c = [1, 2, 3] + + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + a: a, + b: b, + c: c + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "a" => [1, 2, 3, [2, "[RECURSION]"]], + "b" => [2, "[RECURSION]"], + "c" => [1, 2, 3] + }) + } + end + + it "does not detect two equal objects as recursion" do + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + data: [1, [1, 2], [1, 2], "a"] + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "data" => [1, [1, 2], [1, 2], "a"] + }) + } + end + + context "an object that throws if `to_s` is called" do + class StringRaiser + def to_s + raise 'Oh no you do not!' + end + end + + it "uses the string '[RAISED]' instead" do + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + data: [1, 2, StringRaiser.new] + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "data" => [1, 2, "[RAISED]"] + }) + } + end + + it "replaces hash key with '[RAISED]'" do + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + StringRaiser.new => 1 + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "[RAISED]" => "[FILTERED]" + }) + } + end + + it "uses a single '[RAISED]'key when multiple keys raise" do + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + StringRaiser.new => 1, + StringRaiser.new => 2 + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "[RAISED]" => "[FILTERED]" + }) + } + end + end + + context "an object that infinitely recurse if `to_s` is called" do + is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' + + class StringRecurser + def to_s + to_s + end + end + + it "uses the string '[RECURSION]' instead" do + skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby + + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + data: [1, 2, StringRecurser.new] + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "data" => [1, 2, "[RECURSION]"] + }) + } + end + + it "replaces hash key with '[RECURSION]'" do + skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby + + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + StringRecurser.new => 1 + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "[RECURSION]" => "[FILTERED]" + }) + } + end + + it "uses a single '[RECURSION]'key when multiple keys recurse" do + skip "JRuby doesn't allow recovery from SystemStackErrors" if is_jruby + + Bugsnag.notify(BugsnagTestException.new("It crashed")) do |report| + report.add_tab(:some_tab, { + StringRecurser.new => 1, + StringRecurser.new => 2 + }) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + event = get_event_from_payload(payload) + expect(event["metaData"]["some_tab"]).to eq({ + "[RECURSION]" => "[FILTERED]" + }) + } + end + end + it 'should handle exceptions with empty backtrace' do begin err = RuntimeError.new From 6907d598887ed59dd98f0d2a0e3516d8f5727e39 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 10:47:03 +0100 Subject: [PATCH 22/44] Tidy report delivery --- lib/bugsnag.rb | 62 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index f78d67a02..456ef3ec3 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -63,7 +63,7 @@ def notify(exception, auto_notify=false, &block) auto_notify = false end - return unless deliver_notification?(exception, auto_notify) + return unless should_deliver_notification?(exception, auto_notify) exception = NIL_EXCEPTION_DESCRIPTION if exception.nil? @@ -71,6 +71,7 @@ def notify(exception, auto_notify=false, &block) # If this is an auto_notify we yield the block before the any middleware is run yield(report) if block_given? && auto_notify + if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in auto_notify block") return @@ -97,6 +98,7 @@ def notify(exception, auto_notify=false, &block) # If this is not an auto_notify then the block was provided by the user. This should be the last # block that is run as it is the users "most specific" block. yield(report) if block_given? && !auto_notify + if report.ignore? configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in user provided block") return @@ -111,20 +113,7 @@ def notify(exception, auto_notify=false, &block) report.severity_reason = initial_reason end - # Deliver - configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}") - options = {:headers => report.headers} - - cleaner = Cleaner.new(configuration.meta_data_filters) - - cleaned = cleaner.clean_object(report.as_json) - trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) - - payload = ::JSON.dump(trimmed) - - Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.notify_endpoint, payload, configuration, options) - report_summary = report.summary - leave_breadcrumb(report_summary[:error_class], report_summary, Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE, :auto) + deliver_notification(report) end end @@ -257,6 +246,32 @@ def abort_reason(exception, auto_notify) end end + ## + # Deliver the notification to Bugsnag + # + # @param report [Report] + # @return void + def deliver_notification(report) + configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}") + + payload = report_to_json(report) + options = {:headers => report.headers} + + Bugsnag::Delivery[configuration.delivery_method].deliver( + configuration.notify_endpoint, + payload, + configuration, + options + ) + + leave_breadcrumb( + report.summary[:error_class], + report.summary, + Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE, + :auto + ) + end + # Check if the API key is valid and warn (once) if it is not def check_key_valid @key_warning = false unless defined?(@key_warning) @@ -281,6 +296,23 @@ def check_endpoint_setup raise ArgumentError, "The session endpoint cannot be modified without the notify endpoint" end end + + ## + # Convert the Report object to JSON + # + # We ensure the report is safe to send by removing recursion, fixing + # encoding errors and redacting metadata according to "meta_data_filters" + # + # @param report [Report] + # @return string + def report_to_json(report) + cleaner = Cleaner.new(configuration.meta_data_filters) + + cleaned = cleaner.clean_object(report.as_json) + trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) + + ::JSON.dump(trimmed) + end end end From 4d5f7b53657e4794652b19f11618c8322659ffb9 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 10:47:15 +0100 Subject: [PATCH 23/44] Tidy nesting in leave_breadcrumb --- lib/bugsnag.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 456ef3ec3..cb02edf6f 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -208,27 +208,27 @@ def leave_breadcrumb(name, meta_data={}, type=Bugsnag::Breadcrumbs::MANUAL_BREAD validator.validate(breadcrumb) # Skip if it's already invalid - unless breadcrumb.ignore? - # Run callbacks - configuration.before_breadcrumb_callbacks.each do |c| - c.arity > 0 ? c.call(breadcrumb) : c.call - break if breadcrumb.ignore? - end + return if breadcrumb.ignore? - # Return early if ignored - return if breadcrumb.ignore? + # Run callbacks + configuration.before_breadcrumb_callbacks.each do |c| + c.arity > 0 ? c.call(breadcrumb) : c.call + break if breadcrumb.ignore? + end - # Validate again in case of callback alteration - validator.validate(breadcrumb) + # Return early if ignored + return if breadcrumb.ignore? - # Add to breadcrumbs buffer if still valid - configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore? - end + # Validate again in case of callback alteration + validator.validate(breadcrumb) + + # Add to breadcrumbs buffer if still valid + configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore? end private - def deliver_notification?(exception, auto_notify) + def should_deliver_notification?(exception, auto_notify) reason = abort_reason(exception, auto_notify) configuration.debug(reason) unless reason.nil? reason.nil? From 3275fe6a493625cc89395cb41df15f1567897d5a Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 11:50:31 +0100 Subject: [PATCH 24/44] Provide Cleaner with scopes that it should filter For example, in this hash: { a: { b: 'c' } } 'c' lives in scope 'a.b' and so should only be filtered if Cleaner is given 'a.b' in its 'scopes_to_filter' --- lib/bugsnag.rb | 6 ++- lib/bugsnag/cleaner.rb | 45 +++++++++++----- lib/bugsnag/middleware/rack_request.rb | 2 +- spec/cleaner_spec.rb | 72 +++++++++++++++++++++----- spec/integrations/rack_spec.rb | 2 +- 5 files changed, 97 insertions(+), 30 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index cb02edf6f..c7eb51539 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -38,6 +38,7 @@ module Bugsnag INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo] NIL_EXCEPTION_DESCRIPTION = "'nil' was notified as an exception" + SCOPES_TO_FILTER = ['events.metaData', 'events.breadcrumbs.metaData'].freeze class << self ## @@ -306,7 +307,10 @@ def check_endpoint_setup # @param report [Report] # @return string def report_to_json(report) - cleaner = Cleaner.new(configuration.meta_data_filters) + cleaner = Cleaner.new( + configuration.meta_data_filters, + SCOPES_TO_FILTER + ) cleaned = cleaner.clean_object(report.as_json) trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index 737b129ea..f65bfa749 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -7,9 +7,13 @@ class Cleaner OBJECT = '[OBJECT]'.freeze RAISED = '[RAISED]'.freeze - def initialize(filters) + ## + # @param filters [Set] + # @param scopes_to_filter [Array] + def initialize(filters, scopes_to_filter) @filters = Array(filters) @deep_filters = @filters.any? {|f| f.kind_of?(Regexp) && f.to_s.include?("\\.".freeze) } + @scopes_to_filter = scopes_to_filter end def clean_object(obj) @@ -28,12 +32,14 @@ def traverse_object(obj, seen, scope) value = case obj when Hash clean_hash = {} - obj.each do |k,v| + obj.each do |k, v| begin - if filters_match_deeply?(k, scope) + current_scope = [scope, k].compact.join('.') + + if filters_match_deeply?(k, current_scope) clean_hash[k] = FILTERED else - clean_hash[k] = traverse_object(v, seen, [scope, k].compact.join('.')) + clean_hash[k] = traverse_object(v, seen, current_scope) end # If we get an error here, we assume the key needs to be filtered # to avoid leaking things we shouldn't. We also remove the key itself @@ -88,7 +94,7 @@ def clean_string(str) end def self.clean_object_encoding(obj) - new(nil).clean_object(obj) + new(Set.new, []).clean_object(obj) end def clean_url(url) @@ -112,6 +118,9 @@ def clean_url(url) private + ## + # @param key [String, #to_s] + # @return [Boolean] def filters_match?(key) str = key.to_s @@ -125,22 +134,30 @@ def filters_match?(key) end end + ## # If someone has a Rails filter like /^stuff\.secret/, it won't match "request.params.stuff.secret", # so we try it both with and without the "request.params." bit. + # + # @param key [String, #to_s] + # @param scope [String] + # @return [Boolean] def filters_match_deeply?(key, scope) - # FIXME: This is a hack! - # We don't want to apply filters to places outside of 'events.metaData' - # and 'events.breadcrumbs.metaData' as then we could redact things - # like our stacktraces, which is bad. We should implement this in a - # better way, but this makes the tests pass - return false unless scope.nil? || scope.start_with?('events.metaData') || scope.start_with?('events.breadcrumbs.metaData') + return false unless scope_should_be_filtered?(scope) return true if filters_match?(key) return false unless @deep_filters - long = [scope, key].compact.join('.') - short = long.sub(/^request\.params\./, '') - filters_match?(long) || filters_match?(short) + short = scope.sub(/^request\.params\./, '') + filters_match?(scope) || filters_match?(short) + end + + ## + # Should the given scope be filtered according to our 'scopes_to_filter'? + # + # @param scope [String] + # @return [Boolean] + def scope_should_be_filtered?(scope) + @scopes_to_filter.any? {|scope_to_filter| scope.start_with?(scope_to_filter) } end end end diff --git a/lib/bugsnag/middleware/rack_request.rb b/lib/bugsnag/middleware/rack_request.rb index 3a2a39719..1f1694eb7 100644 --- a/lib/bugsnag/middleware/rack_request.rb +++ b/lib/bugsnag/middleware/rack_request.rb @@ -28,7 +28,7 @@ def call(report) url = "#{request.scheme}://#{request.host}" url << ":#{request.port}" unless [80, 443].include?(request.port) - cleaner = Bugsnag::Cleaner.new(report.configuration.meta_data_filters) + cleaner = Bugsnag::Cleaner.new(report.configuration.meta_data_filters, []) # If app is passed a bad URL, this code will crash attempting to clean it begin diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index 3cc0ff0a3..4732059f7 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Bugsnag::Cleaner do - subject { described_class.new(nil) } + subject { described_class.new(Set.new, []) } describe "#clean_object" do is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' @@ -156,25 +156,71 @@ def to_s end it "filters by string inclusion" do - expect(described_class.new(['f']).clean_object({ :foo => 'bar' })).to eq({ :foo => '[FILTERED]' }) - expect(described_class.new(['b']).clean_object({ :foo => 'bar' })).to eq({ :foo => 'bar' }) + object = { foo: 'bar' } + + cleaner = Bugsnag::Cleaner.new(Set.new(['f']), ['foo']) + expect(cleaner.clean_object(object)).to eq({ foo: '[FILTERED]' }) + + cleaner = Bugsnag::Cleaner.new(Set.new(['b']), ['foo']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) end it "filters by regular expression" do - expect(described_class.new([/fb?/]).clean_object({ :foo => 'bar' })).to eq({ :foo => '[FILTERED]' }) - expect(described_class.new([/fb+/]).clean_object({ :foo => 'bar' })).to eq({ :foo => 'bar' }) + object = { foo: 'bar' } + + cleaner = Bugsnag::Cleaner.new(Set.new([/fb?/]), ['foo']) + expect(cleaner.clean_object(object)).to eq({ foo: '[FILTERED]' }) + + cleaner = Bugsnag::Cleaner.new(Set.new([/fb+/]), ['foo']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) end it "filters deeply nested keys" do - skip "this will not work until we implement scopes to filter" - params = {:foo => {:bar => "baz"}} - expect(described_class.new([/^foo\.bar/]).clean_object(params)).to eq({:foo => {:bar => '[FILTERED]'}}) + params = { foo: { bar: 'baz' } } + cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['foo']) + + expect(cleaner.clean_object(params)).to eq({ foo: { bar: '[FILTERED]' } }) end it "filters deeply nested request parameters" do - skip "this will not work until we implement scopes to filter" - params = {:request => {:params => {:foo => {:bar => "baz"}}}} - expect(described_class.new([/^foo\.bar/]).clean_object(params)).to eq({:request => {:params => {:foo => {:bar => '[FILTERED]'}}}}) + params = { request: { params: { foo: { bar: 'baz' } } } } + cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['request']) + + expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: '[FILTERED]' } } } }) + end + + it "doesn't filter by string inclusion when the scope is not in 'scopes_to_filter'" do + object = { foo: 'bar' } + + cleaner = Bugsnag::Cleaner.new(Set.new(['f']), ['bar']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + + cleaner = Bugsnag::Cleaner.new(Set.new(['b']), ['bar']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + end + + it "doesn't filter by regular expression when the scope is not in 'scopes_to_filter'" do + object = { foo: 'bar' } + + cleaner = Bugsnag::Cleaner.new(Set.new([/fb?/]), ['bar']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + + cleaner = Bugsnag::Cleaner.new(Set.new([/fb+/]), ['bar']) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + end + + it "doesn't filter deeply nested keys when the scope is not in 'scopes_to_filter'" do + params = { foo: { bar: 'baz' } } + cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['baz']) + + expect(cleaner.clean_object(params)).to eq({ foo: { bar: 'baz' } }) + end + + it "doesn't filter deeply nested request parameters when the scope is not in 'scopes_to_filter'" do + params = { request: { params: { foo: { bar: 'baz' } } } } + cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['baz']) + + expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: 'baz' } } } }) end it "filters objects which can't be stringified" do @@ -188,8 +234,8 @@ def to_s end describe "#clean_url" do - let(:filters) { [] } - subject { described_class.new(filters).clean_url(url) } + let(:filters) { Set.new } + subject { described_class.new(filters, []).clean_url(url) } context "with no filters configured" do let(:url) { "/dir/page?param1=value1¶m2=value2" } diff --git a/spec/integrations/rack_spec.rb b/spec/integrations/rack_spec.rb index 95cc9f013..025dcb269 100644 --- a/spec/integrations/rack_spec.rb +++ b/spec/integrations/rack_spec.rb @@ -189,7 +189,7 @@ class Request config = double allow(config).to receive(:send_environment).and_return(true) - allow(config).to receive(:meta_data_filters).and_return(nil) + allow(config).to receive(:meta_data_filters).and_return(Set.new) allow(report).to receive(:configuration).and_return(config) expect(report).to receive(:add_tab).once.with(:environment, rack_env) expect(report).to receive(:add_tab).once.with(:request, { From 5762b38b2ea982362efade31635ca94af922a13c Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 12:03:33 +0100 Subject: [PATCH 25/44] Bump Maze Runner to latest --- dockerfiles/Dockerfile.ruby-maze-runner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile.ruby-maze-runner b/dockerfiles/Dockerfile.ruby-maze-runner index 3b72c15b8..de09d813c 100644 --- a/dockerfiles/Dockerfile.ruby-maze-runner +++ b/dockerfiles/Dockerfile.ruby-maze-runner @@ -20,7 +20,7 @@ COPY spec ./spec RUN gem build bugsnag.gemspec # The maze-runner node tests -FROM 855461928731.dkr.ecr.us-west-1.amazonaws.com/maze-runner:v2-cli as ruby-maze-runner +FROM 855461928731.dkr.ecr.us-west-1.amazonaws.com/maze-runner:latest-cli as ruby-maze-runner WORKDIR /app/ COPY features ./features COPY --from=ruby-package-builder /app/bugsnag-*.gem bugsnag.gem From 7d9b8c62efcaec4d732ce8f3b515bf5ab4adf09d Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 13:30:03 +0100 Subject: [PATCH 26/44] Add pending rubocop cops --- .rubocop.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d8da878af..aa916e963 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,12 +24,27 @@ Lint/RaiseException: Lint/StructNewOverride: Enabled: true +Lint/DeprecatedOpenSSLConstant: + Enabled: true + +Lint/MixedRegexpCaptureTypes: + Enabled: true + +Style/RedundantFetchBlock: + Enabled: true + Style/ExponentialNotation: Enabled: false Style/HashEachMethods: Enabled: true +Style/RedundantRegexpCharacterClass: + Enabled: true + +Style/RedundantRegexpEscape: + Enabled: true + # These require newer version of Ruby than our minimum supported version, so # have to be disabled Style/HashTransformKeys: # Requires Ruby 2.5 From 0699f905dd145977b8d7a7cc6f990f4d5b68f8a7 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 13:30:33 +0100 Subject: [PATCH 27/44] Add todos for rubocop violations --- lib/bugsnag.rb | 2 ++ lib/bugsnag/stacktrace.rb | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index c7eb51539..ccdbb5c31 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -33,6 +33,7 @@ require "bugsnag/breadcrumbs/breadcrumb" require "bugsnag/breadcrumbs/breadcrumbs" +# rubocop:todo Metrics/ModuleLength module Bugsnag LOCK = Mutex.new INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo] @@ -319,5 +320,6 @@ def report_to_json(report) end end end +# rubocop:enable Metrics/ModuleLength Bugsnag.load_integrations unless ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"] diff --git a/lib/bugsnag/stacktrace.rb b/lib/bugsnag/stacktrace.rb index 1eb0259e0..c147935df 100644 --- a/lib/bugsnag/stacktrace.rb +++ b/lib/bugsnag/stacktrace.rb @@ -9,6 +9,8 @@ class Stacktrace ## # Process a backtrace and the configuration into a parsed stacktrace. + # + # rubocop:todo Metrics/CyclomaticComplexity def initialize(backtrace, configuration) @configuration = configuration @@ -64,6 +66,7 @@ def initialize(backtrace, configuration) end end.compact end + # rubocop:enable Metrics/CyclomaticComplexity ## # Returns the processed backtrace From 1203022dc3819a29cd4940fff7c02508befcd752 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 13:30:50 +0100 Subject: [PATCH 28/44] Fix unnecessary regex escapes --- lib/bugsnag/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index 0a8e5aded..bb6209967 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -91,7 +91,7 @@ class Configuration DEFAULT_MAX_BREADCRUMBS = 25 # Path to vendored code. Used to mark file paths as out of project. - DEFAULT_VENDOR_PATH = %r{^(vendor\/|\.bundle\/)} + DEFAULT_VENDOR_PATH = %r{^(vendor/|\.bundle/)} alias :track_sessions :auto_capture_sessions alias :track_sessions= :auto_capture_sessions= From e87761b7c16bc40a3fa9e8e9f0f4e5402b9009d9 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 15:11:23 +0100 Subject: [PATCH 29/44] Add changelog entry for #601 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 053bbfeac..08799dd3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,11 @@ Changelog * The Breadcrumb name limit of 30 characters has been removed | [#600](https://github.com/bugsnag/bugsnag-ruby/pull/600) +* Improve performance of payload cleaning + | [#601](https://github.com/bugsnag/bugsnag-ruby/pull/601) + ### Deprecated + * The `ignore_classes` configuration option has been deprecated in favour of `discard_classes`. `ignore_classes` will be removed in the next major release ## 6.13.1 (11 May 2020) From 97d602950d1d3d14a14595fc9d64c9fbee898f89 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 15:46:55 +0100 Subject: [PATCH 30/44] Remove webpacker as we don't need to use it --- example/rails-60/Gemfile | 6 -- .../app/assets/stylesheets/application.css | 50 ---------- .../app/views/layouts/application.html.erb | 3 +- .../rails-60/config/webpack/development.js | 5 - .../rails-60/config/webpack/environment.js | 3 - example/rails-60/config/webpack/production.js | 5 - example/rails-60/config/webpack/test.js | 5 - example/rails-60/config/webpacker.yml | 98 ------------------- example/rails-60/package.json | 15 --- example/rails-60/postcss.config.js | 12 --- example/rails-60/public/style.css | 34 +++++++ 11 files changed, 35 insertions(+), 201 deletions(-) delete mode 100644 example/rails-60/app/assets/stylesheets/application.css delete mode 100644 example/rails-60/config/webpack/development.js delete mode 100644 example/rails-60/config/webpack/environment.js delete mode 100644 example/rails-60/config/webpack/production.js delete mode 100644 example/rails-60/config/webpack/test.js delete mode 100644 example/rails-60/config/webpacker.yml delete mode 100644 example/rails-60/package.json delete mode 100644 example/rails-60/postcss.config.js create mode 100644 example/rails-60/public/style.css diff --git a/example/rails-60/Gemfile b/example/rails-60/Gemfile index 48a19fc08..2a8f4d30e 100644 --- a/example/rails-60/Gemfile +++ b/example/rails-60/Gemfile @@ -17,12 +17,6 @@ gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 4.1' -# Use SCSS for stylesheets -gem 'sass-rails', '>= 6' -# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker -gem 'webpacker', '~> 4.0' -# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production diff --git a/example/rails-60/app/assets/stylesheets/application.css b/example/rails-60/app/assets/stylesheets/application.css deleted file mode 100644 index c22e35561..000000000 --- a/example/rails-60/app/assets/stylesheets/application.css +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's - * vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS - * files in this directory. Styles in this file should be added after the last require_* statement. - * It is generally better to create a new file per style scope. - * - *= require_tree . - *= require_self - */ - -body { - font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji; - max-width: 80ch; - margin: 0 auto; -} - -pre, -code { - font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; -} - -pre { - background: rgba(0, 0, 0, .05); - border: 1px solid rgba(0, 0, 0, .1); - padding: 1rem; -} - -pre.shell::before { - content: '$ '; - pointer-events: none; -} - -a:link, -a:visited { - color: #536eec; -} - -a:hover { - opacity: .7; -} - -.upper { - text-transform: uppercase; -} diff --git a/example/rails-60/app/views/layouts/application.html.erb b/example/rails-60/app/views/layouts/application.html.erb index 912f5f852..6a2702144 100644 --- a/example/rails-60/app/views/layouts/application.html.erb +++ b/example/rails-60/app/views/layouts/application.html.erb @@ -5,8 +5,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + diff --git a/example/rails-60/config/webpack/development.js b/example/rails-60/config/webpack/development.js deleted file mode 100644 index c5edff94a..000000000 --- a/example/rails-60/config/webpack/development.js +++ /dev/null @@ -1,5 +0,0 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'development' - -const environment = require('./environment') - -module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpack/environment.js b/example/rails-60/config/webpack/environment.js deleted file mode 100644 index d16d9af74..000000000 --- a/example/rails-60/config/webpack/environment.js +++ /dev/null @@ -1,3 +0,0 @@ -const { environment } = require('@rails/webpacker') - -module.exports = environment diff --git a/example/rails-60/config/webpack/production.js b/example/rails-60/config/webpack/production.js deleted file mode 100644 index be0f53aac..000000000 --- a/example/rails-60/config/webpack/production.js +++ /dev/null @@ -1,5 +0,0 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'production' - -const environment = require('./environment') - -module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpack/test.js b/example/rails-60/config/webpack/test.js deleted file mode 100644 index c5edff94a..000000000 --- a/example/rails-60/config/webpack/test.js +++ /dev/null @@ -1,5 +0,0 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'development' - -const environment = require('./environment') - -module.exports = environment.toWebpackConfig() diff --git a/example/rails-60/config/webpacker.yml b/example/rails-60/config/webpacker.yml deleted file mode 100644 index e9806ed84..000000000 --- a/example/rails-60/config/webpacker.yml +++ /dev/null @@ -1,98 +0,0 @@ -# Note: You must restart bin/webpack-dev-server for changes to take effect - -default: &default - source_path: app/javascript - source_entry_path: packs - public_root_path: public - public_output_path: packs - cache_path: tmp/cache/webpacker - check_yarn_integrity: false - webpack_compile_output: true - - # Additional paths webpack should lookup modules - # ['app/assets', 'engine/foo/app/assets'] - resolved_paths: [] - - # Reload manifest.json on all requests so we reload latest compiled packs - cache_manifest: false - - # Extract and emit a css file - extract_css: false - - static_assets_extensions: - - .jpg - - .jpeg - - .png - - .gif - - .tiff - - .ico - - .svg - - .eot - - .otf - - .ttf - - .woff - - .woff2 - - extensions: - - .mjs - - .js - - .sass - - .scss - - .css - - .module.sass - - .module.scss - - .module.css - - .png - - .svg - - .gif - - .jpeg - - .jpg - -development: &development - <<: *default - compile: true - - # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules - check_yarn_integrity: true - - # Reference: https://webpack.js.org/configuration/dev-server/ - dev_server: - https: false - host: localhost - port: 3035 - public: localhost:3035 - hmr: false - # Inline should be set to true if using HMR - inline: true - overlay: true - compress: true - disable_host_check: true - use_local_ip: false - quiet: false - pretty: false - headers: - 'Access-Control-Allow-Origin': '*' - watch_options: - ignored: '**/node_modules/**' - -que: - <<: *development - -test: - <<: *default - compile: true - - # Compile test packs to a separate directory - public_output_path: packs-test - -production: - <<: *default - - # Production depends on precompilation of packs prior to booting for performance. - compile: false - - # Extract and emit a css file - extract_css: true - - # Cache manifest.json for performance - cache_manifest: true diff --git a/example/rails-60/package.json b/example/rails-60/package.json deleted file mode 100644 index 4b504698a..000000000 --- a/example/rails-60/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "rails_60", - "private": true, - "dependencies": { - "@rails/actioncable": "^6.0.0", - "@rails/activestorage": "^6.0.0", - "@rails/ujs": "^6.0.0", - "@rails/webpacker": "4.2.2", - "turbolinks": "^5.2.0" - }, - "version": "0.1.0", - "devDependencies": { - "webpack-dev-server": "^3.11.0" - } -} diff --git a/example/rails-60/postcss.config.js b/example/rails-60/postcss.config.js deleted file mode 100644 index aa5998a80..000000000 --- a/example/rails-60/postcss.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - plugins: [ - require('postcss-import'), - require('postcss-flexbugs-fixes'), - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009' - }, - stage: 3 - }) - ] -} diff --git a/example/rails-60/public/style.css b/example/rails-60/public/style.css new file mode 100644 index 000000000..253bee2aa --- /dev/null +++ b/example/rails-60/public/style.css @@ -0,0 +1,34 @@ +body { + font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji; + max-width: 80ch; + margin: 0 auto; +} + +pre, +code { + font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; +} + +pre { + background: rgba(0, 0, 0, .05); + border: 1px solid rgba(0, 0, 0, .1); + padding: 1rem; +} + +pre.shell::before { + content: '$ '; + pointer-events: none; +} + +a:link, +a:visited { + color: #536eec; +} + +a:hover { + opacity: .7; +} + +.upper { + text-transform: uppercase; +} From fce9d0ea7cf84a6c68c9dee8e60688134c8c5e61 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 15:47:09 +0100 Subject: [PATCH 31/44] Fix indentation of code block --- example/rails-60/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/example/rails-60/README.md b/example/rails-60/README.md index e23db7d73..2eaa10f01 100644 --- a/example/rails-60/README.md +++ b/example/rails-60/README.md @@ -9,7 +9,7 @@ Install dependencies bundle install ``` -Install local binaries (if needed): +Install local binaries ```shell bundle exec rake app:update:bin @@ -23,10 +23,11 @@ There are two methods of configuring Bugsnag within a Rails application: 1. Your `API_KEY` can be exported as an environment variable `BUGSNAG_API_KEY`. -2. Generate a bugsnag configuration file at ```config/initializers/bugsnag.rb``` which can be populated with the [available configuration options](https://docs.bugsnag.com/platforms/ruby/rails/configuration-options/) by running the rails command: - ```shell - bundle exec bin/rails generate bugsnag YOUR_API_KEY_HERE - ``` +2. Generate a bugsnag configuration file at `config/initializers/bugsnag.rb` which can be populated with the [available configuration options](https://docs.bugsnag.com/platforms/ruby/rails/configuration-options/) by running the rails command: + + ```shell + bundle exec bin/rails generate bugsnag YOUR_API_KEY_HERE + ``` This is sufficient to start reporting unhandled exceptions to Bugsnag. From 86d7ce1e05dc98081a0b1581b8054cfc2d07eef9 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 6 Jul 2020 16:39:57 +0100 Subject: [PATCH 32/44] Remove unused method --- lib/bugsnag/cleaner.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index f65bfa749..01b887e7d 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -93,10 +93,6 @@ def clean_string(str) end end - def self.clean_object_encoding(obj) - new(Set.new, []).clean_object(obj) - end - def clean_url(url) return url if @filters.empty? From 8c669ae107acbac15fa04450610dcbbd884f3f40 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Tue, 7 Jul 2020 11:59:35 +0100 Subject: [PATCH 33/44] Make Cleaner a shared instance This exposed a pretty big regression where filters wouldn't match when they should have. This was caused by us filtering the entire report object in one go, which means the scopes were nested deeper than they were before Previously we filtered the events.metaData directly, so scopes would not include 'events.metaData' and therefore a filter of 'foo' would match 'events.metaData.foo'. Now that we filter the entire report, if a filter relied on 'deep_filters', it would apply and so things that should be redacted wouldn't have been To solve this, we strip each 'scope_to_filter' from the scope before matching it, if deep_filters are enabled The tests passed before this change because we set 'scopes_to_filter' in each test. Now that the instance is shared, the scopes are fetched from the Configuration so this isn't possible and it exposed the bug The tests now cover this case, because they can't set 'scopes_to_filter' directly anymore, so they are testing that the filters they're using match with the Configuration's 'scopes_to_filter' --- lib/bugsnag.rb | 19 ++-- lib/bugsnag/cleaner.rb | 133 +++++++++++++++---------- lib/bugsnag/configuration.rb | 9 ++ lib/bugsnag/middleware/rack_request.rb | 6 +- spec/cleaner_spec.rb | 97 +++++++++++++----- spec/integrations/rack_spec.rb | 14 +-- spec/spec_helper.rb | 5 + 7 files changed, 189 insertions(+), 94 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index ccdbb5c31..1be5d084a 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -39,7 +39,6 @@ module Bugsnag INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo] NIL_EXCEPTION_DESCRIPTION = "'nil' was notified as an exception" - SCOPES_TO_FILTER = ['events.metaData', 'events.breadcrumbs.metaData'].freeze class << self ## @@ -228,6 +227,19 @@ def leave_breadcrumb(name, meta_data={}, type=Bugsnag::Breadcrumbs::MANUAL_BREAD configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore? end + ## + # Returns the client's Cleaner object, or creates one if not yet created. + # + # @api private + # + # @return [Cleaner] + def cleaner + @cleaner = nil unless defined?(@cleaner) + @cleaner || LOCK.synchronize do + @cleaner ||= Bugsnag::Cleaner.new(configuration) + end + end + private def should_deliver_notification?(exception, auto_notify) @@ -308,11 +320,6 @@ def check_endpoint_setup # @param report [Report] # @return string def report_to_json(report) - cleaner = Cleaner.new( - configuration.meta_data_filters, - SCOPES_TO_FILTER - ) - cleaned = cleaner.clean_object(report.as_json) trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index 01b887e7d..25ca20508 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -1,6 +1,7 @@ require 'uri' module Bugsnag + # @api private class Cleaner FILTERED = '[FILTERED]'.freeze RECURSION = '[RECURSION]'.freeze @@ -8,16 +9,67 @@ class Cleaner RAISED = '[RAISED]'.freeze ## - # @param filters [Set] - # @param scopes_to_filter [Array] - def initialize(filters, scopes_to_filter) - @filters = Array(filters) - @deep_filters = @filters.any? {|f| f.kind_of?(Regexp) && f.to_s.include?("\\.".freeze) } - @scopes_to_filter = scopes_to_filter + # @param configuration [Configuration] + def initialize(configuration) + @configuration = configuration end - def clean_object(obj) - traverse_object(obj, {}, nil) + def clean_object(object) + @deep_filters = deep_filters? + + traverse_object(object, {}, nil) + end + + ## + # @param url [String] + # @return [String] + def clean_url(url) + return url if @configuration.meta_data_filters.empty? + + uri = URI(url) + return url unless uri.query + + query_params = uri.query.split('&').map { |pair| pair.split('=') } + query_params.map! do |key, val| + if filters_match?(key) + "#{key}=#{FILTERED}" + else + "#{key}=#{val}" + end + end + + uri.query = query_params.join('&') + uri.to_s + end + + private + + ## + # This method calculates whether we need to filter deeply or not; i.e. whether + # we should match both with and without 'request.params' + # + # This is cached on the instance variable '@deep_filters' for performance + # reasons + # + # @return [Boolean] + def deep_filters? + @configuration.meta_data_filters.any? do |filter| + filter.is_a?(Regexp) && filter.to_s.include?("\\.".freeze) + end + end + + def clean_string(str) + if defined?(str.encoding) && defined?(Encoding::UTF_8) + if str.encoding == Encoding::UTF_8 + str.valid_encoding? ? str : str.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8') + else + str.encode('utf-8', invalid: :replace, undef: :replace) + end + elsif defined?(Iconv) + Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str + else + str + end end def traverse_object(obj, seen, scope) @@ -79,60 +131,26 @@ def traverse_object(obj, seen, scope) value end - def clean_string(str) - if defined?(str.encoding) && defined?(Encoding::UTF_8) - if str.encoding == Encoding::UTF_8 - str.valid_encoding? ? str : str.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8') - else - str.encode('utf-8', invalid: :replace, undef: :replace) - end - elsif defined?(Iconv) - Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str - else - str - end - end - - def clean_url(url) - return url if @filters.empty? - - uri = URI(url) - return url unless uri.query - - query_params = uri.query.split('&').map { |pair| pair.split('=') } - query_params.map! do |key, val| - if filters_match?(key) - "#{key}=#{FILTERED}" - else - "#{key}=#{val}" - end - end - - uri.query = query_params.join('&') - uri.to_s - end - - private - ## # @param key [String, #to_s] # @return [Boolean] def filters_match?(key) str = key.to_s - @filters.any? do |f| - case f + @configuration.meta_data_filters.any? do |filter| + case filter when Regexp - str.match(f) + str.match(filter) else - str.include?(f.to_s) + str.include?(filter.to_s) end end end ## - # If someone has a Rails filter like /^stuff\.secret/, it won't match "request.params.stuff.secret", - # so we try it both with and without the "request.params." bit. + # If someone has a Rails filter like /^stuff\.secret/, it won't match + # "request.params.stuff.secret", so we try it both with and without the + # "request.params." bit. # # @param key [String, #to_s] # @param scope [String] @@ -143,17 +161,26 @@ def filters_match_deeply?(key, scope) return true if filters_match?(key) return false unless @deep_filters - short = scope.sub(/^request\.params\./, '') - filters_match?(scope) || filters_match?(short) + return true if filters_match?(scope) + + @configuration.scopes_to_filter.any? do |scope_to_filter| + if scope.start_with?("#{scope_to_filter}.request.params.") + filters_match?(scope.sub("#{scope_to_filter}.request.params.", '')) + else + filters_match?(scope.sub("#{scope_to_filter}.", '')) + end + end end ## - # Should the given scope be filtered according to our 'scopes_to_filter'? + # Should the given scope be filtered? # # @param scope [String] # @return [Boolean] def scope_should_be_filtered?(scope) - @scopes_to_filter.any? {|scope_to_filter| scope.start_with?(scope_to_filter) } + @configuration.scopes_to_filter.any? do |scope_to_filter| + scope.start_with?("#{scope_to_filter}.") + end end end end diff --git a/lib/bugsnag/configuration.rb b/lib/bugsnag/configuration.rb index bb6209967..d017c111e 100644 --- a/lib/bugsnag/configuration.rb +++ b/lib/bugsnag/configuration.rb @@ -72,6 +72,10 @@ class Configuration # @return [Regexp] matching file paths out of project attr_accessor :vendor_path + ## + # @return [Array] + attr_reader :scopes_to_filter + API_KEY_REGEX = /[0-9a-f]{32}/i THREAD_LOCAL_NAME = "bugsnag_req_data" @@ -93,6 +97,8 @@ class Configuration # Path to vendored code. Used to mark file paths as out of project. DEFAULT_VENDOR_PATH = %r{^(vendor/|\.bundle/)} + DEFAULT_SCOPES_TO_FILTER = ['events.metaData', 'events.breadcrumbs.metaData'].freeze + alias :track_sessions :auto_capture_sessions alias :track_sessions= :auto_capture_sessions= @@ -104,6 +110,7 @@ def initialize self.send_environment = false self.send_code = true self.meta_data_filters = Set.new(DEFAULT_META_DATA_FILTERS) + self.scopes_to_filter = DEFAULT_SCOPES_TO_FILTER self.hostname = default_hostname self.runtime_versions = {} self.runtime_versions["ruby"] = RUBY_VERSION @@ -313,6 +320,8 @@ def disable_sessions private + attr_writer :scopes_to_filter + PROG_NAME = "[Bugsnag]" def default_hostname diff --git a/lib/bugsnag/middleware/rack_request.rb b/lib/bugsnag/middleware/rack_request.rb index 1f1694eb7..6825ccf21 100644 --- a/lib/bugsnag/middleware/rack_request.rb +++ b/lib/bugsnag/middleware/rack_request.rb @@ -28,18 +28,16 @@ def call(report) url = "#{request.scheme}://#{request.host}" url << ":#{request.port}" unless [80, 443].include?(request.port) - cleaner = Bugsnag::Cleaner.new(report.configuration.meta_data_filters, []) - # If app is passed a bad URL, this code will crash attempting to clean it begin - url << cleaner.clean_url(request.fullpath) + url << Bugsnag.cleaner.clean_url(request.fullpath) rescue StandardError => stde Bugsnag.configuration.warn "RackRequest - Rescued error while cleaning request.fullpath: #{stde}" end referer = nil begin - referer = cleaner.clean_url(request.referer) if request.referer + referer = Bugsnag.cleaner.clean_url(request.referer) if request.referer rescue StandardError => stde Bugsnag.configuration.warn "RackRequest - Rescued error while cleaning request.referer: #{stde}" end diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index 4732059f7..3f207a0e7 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Bugsnag::Cleaner do - subject { described_class.new(Set.new, []) } + subject { Bugsnag::Cleaner.new(Bugsnag::Configuration.new) } describe "#clean_object" do is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' @@ -156,69 +156,111 @@ def to_s end it "filters by string inclusion" do - object = { foo: 'bar' } + object = { events: { metaData: { foo: 'bar' } } } - cleaner = Bugsnag::Cleaner.new(Set.new(['f']), ['foo']) - expect(cleaner.clean_object(object)).to eq({ foo: '[FILTERED]' }) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = ['f'] - cleaner = Bugsnag::Cleaner.new(Set.new(['b']), ['foo']) - expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: '[FILTERED]' } } }) + + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = ['b'] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: 'bar' } } }) end it "filters by regular expression" do - object = { foo: 'bar' } + object = { events: { metaData: { foo: 'bar' } } } - cleaner = Bugsnag::Cleaner.new(Set.new([/fb?/]), ['foo']) - expect(cleaner.clean_object(object)).to eq({ foo: '[FILTERED]' }) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/fb?/] - cleaner = Bugsnag::Cleaner.new(Set.new([/fb+/]), ['foo']) - expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: '[FILTERED]' } } }) + + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/fb+/] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: 'bar' } } }) end it "filters deeply nested keys" do - params = { foo: { bar: 'baz' } } - cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['foo']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/^foo\.bar/] + + cleaner = Bugsnag::Cleaner.new(configuration) - expect(cleaner.clean_object(params)).to eq({ foo: { bar: '[FILTERED]' } }) + params = { events: { metaData: { foo: { bar: 'baz' } } } } + expect(cleaner.clean_object(params)).to eq({ events: { metaData: { foo: { bar: '[FILTERED]' } } } }) end it "filters deeply nested request parameters" do - params = { request: { params: { foo: { bar: 'baz' } } } } - cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['request']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/^foo\.bar/] + + cleaner = Bugsnag::Cleaner.new(configuration) - expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: '[FILTERED]' } } } }) + params = { events: { metaData: { request: { params: { foo: { bar: 'baz' } } } } } } + expect(cleaner.clean_object(params)).to eq({ events: { metaData: { request: { params: { foo: { bar: '[FILTERED]' } } } } } }) end it "doesn't filter by string inclusion when the scope is not in 'scopes_to_filter'" do object = { foo: 'bar' } - cleaner = Bugsnag::Cleaner.new(Set.new(['f']), ['bar']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = ['f'] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) - cleaner = Bugsnag::Cleaner.new(Set.new(['b']), ['bar']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = ['b'] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) end it "doesn't filter by regular expression when the scope is not in 'scopes_to_filter'" do object = { foo: 'bar' } - cleaner = Bugsnag::Cleaner.new(Set.new([/fb?/]), ['bar']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/fb?/] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) - cleaner = Bugsnag::Cleaner.new(Set.new([/fb+/]), ['bar']) + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/fb+/] + + cleaner = Bugsnag::Cleaner.new(configuration) + expect(cleaner.clean_object(object)).to eq({ foo: 'bar' }) end it "doesn't filter deeply nested keys when the scope is not in 'scopes_to_filter'" do params = { foo: { bar: 'baz' } } - cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['baz']) + + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/^foo\.bar/] + + cleaner = Bugsnag::Cleaner.new(configuration) expect(cleaner.clean_object(params)).to eq({ foo: { bar: 'baz' } }) end it "doesn't filter deeply nested request parameters when the scope is not in 'scopes_to_filter'" do params = { request: { params: { foo: { bar: 'baz' } } } } - cleaner = Bugsnag::Cleaner.new(Set.new([/^foo\.bar/]), ['baz']) + + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = [/^foo\.bar/] + + cleaner = Bugsnag::Cleaner.new(configuration) expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: 'baz' } } } }) end @@ -234,8 +276,13 @@ def to_s end describe "#clean_url" do - let(:filters) { Set.new } - subject { described_class.new(filters, []).clean_url(url) } + let(:filters) { [] } + + subject do + configuration = Bugsnag::Configuration.new + configuration.meta_data_filters = filters + described_class.new(configuration).clean_url(url) + end context "with no filters configured" do let(:url) { "/dir/page?param1=value1¶m2=value2" } diff --git a/spec/integrations/rack_spec.rb b/spec/integrations/rack_spec.rb index 025dcb269..57847efa4 100644 --- a/spec/integrations/rack_spec.rb +++ b/spec/integrations/rack_spec.rb @@ -127,9 +127,10 @@ class Request expect(report).to receive(:context=).with("TEST /TEST_PATH") expect(report).to receive(:user).and_return({}) - config = double - allow(config).to receive(:send_environment).and_return(true) - allow(config).to receive(:meta_data_filters).and_return(['email']) + config = Bugsnag.configuration + config.send_environment = true + config.meta_data_filters = ['email'] + allow(report).to receive(:configuration).and_return(config) expect(report).to receive(:add_tab).once.with(:request, { :url => "http://test_host/TEST_PATH?email=[FILTERED]&another_param=thing", @@ -187,9 +188,10 @@ class Request expect(report).to receive(:context=).with("TEST /TEST_PATH") expect(report).to receive(:user).and_return({}) - config = double - allow(config).to receive(:send_environment).and_return(true) - allow(config).to receive(:meta_data_filters).and_return(Set.new) + config = Bugsnag.configuration + config.send_environment = true + config.meta_data_filters = [] + allow(report).to receive(:configuration).and_return(config) expect(report).to receive(:add_tab).once.with(:environment, rack_env) expect(report).to receive(:add_tab).once.with(:request, { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f6061dab..b172d183b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ require 'bugsnag' +require 'tmpdir' require 'webmock/rspec' require 'rspec/expectations' require 'rspec/mocks' @@ -43,12 +44,16 @@ def ruby_version_greater_equal?(version) RSpec.configure do |config| config.order = "random" + config.example_status_persistence_file_path = "#{Dir.tmpdir}/rspec_status" config.before(:each) do WebMock.stub_request(:post, "https://notify.bugsnag.com/") WebMock.stub_request(:post, "https://sessions.bugsnag.com/") Bugsnag.instance_variable_set(:@configuration, Bugsnag::Configuration.new) + Bugsnag.instance_variable_set(:@session_tracker, Bugsnag::SessionTracker.new) + Bugsnag.instance_variable_set(:@cleaner, Bugsnag::Cleaner.new(Bugsnag.configuration)) + Bugsnag.configure do |bugsnag| bugsnag.api_key = "c9d60ae4c7e70c4b6c4ebd3e8056d2b8" bugsnag.release_stage = "production" From 5700938edf083afb119cec99c1c0292cde9e4221 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Tue, 7 Jul 2020 14:09:46 +0100 Subject: [PATCH 34/44] Add a Maze Runner test for 'deep filtering' --- TESTING.md | 6 +++--- features/fixtures/rails3/app/config/initializers/bugsnag.rb | 3 ++- features/fixtures/rails4/app/config/initializers/bugsnag.rb | 1 + features/fixtures/rails5/app/config/initializers/bugsnag.rb | 1 + features/fixtures/rails6/app/config/initializers/bugsnag.rb | 1 + features/rails_features/meta_data_filters.feature | 6 ++++-- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/TESTING.md b/TESTING.md index f5fe99e87..513d83588 100644 --- a/TESTING.md +++ b/TESTING.md @@ -42,7 +42,7 @@ aws configure --profile=opensource Subsequently you'll need to run the following commmand to authenticate with the registry: ``` -$(aws ecr get-login --profile=opensource --no-include-email) +aws ecr get-login-password --profile=opensource | docker login --username AWS --password-stdin 855461928731.dkr.ecr.us-west-1.amazonaws.com ``` __Your session will periodically expire__, so you'll need to run this command to re-authenticate when that happens. @@ -64,7 +64,7 @@ Configure the tests to be run in the following way: When running the end-to-end tests, you'll want to restrict the feature files run to the specific test features for the platform. This is done using the Cucumber CLI syntax at the end of the `docker-compose run ruby-maze-runner` command, i.e: ``` -RUBY_TEST_VERSION=2.6 RAILS_VERSION=6 docker-compose run ruby-maze-runner features/rails_features --tags "@rails6" +RUBY_TEST_VERSION=2.6 RAILS_VERSION=6 docker-compose run --use-aliases ruby-maze-runner features/rails_features --tags "@rails6" ``` - Plain ruby tests should target `features/plain_features` @@ -75,7 +75,7 @@ RUBY_TEST_VERSION=2.6 RAILS_VERSION=6 docker-compose run ruby-maze-runner featur In order to target specific features the exact `.feature` file can be specified, i.e: ``` -RUBY_TEST_VERSION=2.6 RAILS_VERSION=6 docker-compose run ruby-maze-runner features/rails_features/app_version.feature --tags "@rails6" +RUBY_TEST_VERSION=2.6 RAILS_VERSION=6 docker-compose run --use-aliases ruby-maze-runner features/rails_features/app_version.feature --tags "@rails6" ``` In order to avoid running flakey or unfinished tests, the tag `"not @wip"` can be added to the tags option. This is recommended for all CI runs. If a tag is already specified, this should be added using the `and` keyword, e.g. `--tags "@rails6 and not @wip"` diff --git a/features/fixtures/rails3/app/config/initializers/bugsnag.rb b/features/fixtures/rails3/app/config/initializers/bugsnag.rb index fea970a97..b849c0995 100644 --- a/features/fixtures/rails3/app/config/initializers/bugsnag.rb +++ b/features/fixtures/rails3/app/config/initializers/bugsnag.rb @@ -11,10 +11,11 @@ config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] if ENV.include? "BUGSNAG_RELEASE_STAGE" config.send_code = ENV["BUGSNAG_SEND_CODE"] != "false" config.send_environment = ENV["BUGSNAG_SEND_ENVIRONMENT"] == "true" + config.meta_data_filters << 'filtered_parameter' if ENV["SQL_ONLY_BREADCRUMBS"] == "true" config.before_breadcrumb_callbacks << Proc.new do |breadcrumb| breadcrumb.ignore! unless breadcrumb.meta_data[:event_name] == "sql.active_record" && breadcrumb.meta_data[:name] == "User Load" end end -end \ No newline at end of file +end diff --git a/features/fixtures/rails4/app/config/initializers/bugsnag.rb b/features/fixtures/rails4/app/config/initializers/bugsnag.rb index d7ce3b9b3..b849c0995 100644 --- a/features/fixtures/rails4/app/config/initializers/bugsnag.rb +++ b/features/fixtures/rails4/app/config/initializers/bugsnag.rb @@ -11,6 +11,7 @@ config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] if ENV.include? "BUGSNAG_RELEASE_STAGE" config.send_code = ENV["BUGSNAG_SEND_CODE"] != "false" config.send_environment = ENV["BUGSNAG_SEND_ENVIRONMENT"] == "true" + config.meta_data_filters << 'filtered_parameter' if ENV["SQL_ONLY_BREADCRUMBS"] == "true" config.before_breadcrumb_callbacks << Proc.new do |breadcrumb| diff --git a/features/fixtures/rails5/app/config/initializers/bugsnag.rb b/features/fixtures/rails5/app/config/initializers/bugsnag.rb index d7ce3b9b3..b849c0995 100644 --- a/features/fixtures/rails5/app/config/initializers/bugsnag.rb +++ b/features/fixtures/rails5/app/config/initializers/bugsnag.rb @@ -11,6 +11,7 @@ config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] if ENV.include? "BUGSNAG_RELEASE_STAGE" config.send_code = ENV["BUGSNAG_SEND_CODE"] != "false" config.send_environment = ENV["BUGSNAG_SEND_ENVIRONMENT"] == "true" + config.meta_data_filters << 'filtered_parameter' if ENV["SQL_ONLY_BREADCRUMBS"] == "true" config.before_breadcrumb_callbacks << Proc.new do |breadcrumb| diff --git a/features/fixtures/rails6/app/config/initializers/bugsnag.rb b/features/fixtures/rails6/app/config/initializers/bugsnag.rb index d7ce3b9b3..b849c0995 100644 --- a/features/fixtures/rails6/app/config/initializers/bugsnag.rb +++ b/features/fixtures/rails6/app/config/initializers/bugsnag.rb @@ -11,6 +11,7 @@ config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] if ENV.include? "BUGSNAG_RELEASE_STAGE" config.send_code = ENV["BUGSNAG_SEND_CODE"] != "false" config.send_environment = ENV["BUGSNAG_SEND_ENVIRONMENT"] == "true" + config.meta_data_filters << 'filtered_parameter' if ENV["SQL_ONLY_BREADCRUMBS"] == "true" config.before_breadcrumb_callbacks << Proc.new do |breadcrumb| diff --git a/features/rails_features/meta_data_filters.feature b/features/rails_features/meta_data_filters.feature index fc6b4a8f6..b867e63e7 100644 --- a/features/rails_features/meta_data_filters.feature +++ b/features/rails_features/meta_data_filters.feature @@ -3,12 +3,14 @@ Feature: Metadata filters @rails3 @rails4 @rails5 @rails6 Scenario: Meta_data_filters should include Rails.configuration.filter_parameters Given I start the rails service - When I navigate to the route "/metadata_filters/filter" on the rails app + When I navigate to the route "/metadata_filters/filter?filtered_parameter=foo&other_parameter=bar" on the rails app And I wait to receive a request Then the request is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" And the event "unhandled" is false And the exception "errorClass" equals "RuntimeError" And the exception "message" starts with "handled string" And the event "app.type" equals "rails" - And the event "metaData.request.url" ends with "/metadata_filters/filter" + And the event "metaData.request.url" ends with "/metadata_filters/filter?filtered_parameter=[FILTERED]&other_parameter=bar" And the event "metaData.my_specific_filter" equals "[FILTERED]" + And the event "metaData.request.params.filtered_parameter" equals "[FILTERED]" + And the event "metaData.request.params.other_parameter" equals "bar" From 7cf7c4611f7ac09913a3812c87c37e8d0162fe54 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 18:07:18 +0100 Subject: [PATCH 35/44] Add tests for stacktrace file paths --- spec/stacktrace_spec.rb | 212 ++++++++++++++++++++++++++-------------- 1 file changed, 139 insertions(+), 73 deletions(-) diff --git a/spec/stacktrace_spec.rb b/spec/stacktrace_spec.rb index f17b2dff3..38339d189 100644 --- a/spec/stacktrace_spec.rb +++ b/spec/stacktrace_spec.rb @@ -1,91 +1,157 @@ require 'spec_helper' describe Bugsnag::Stacktrace do - it "includes code in the stack trace" do - begin - _a = 1 - _b = 2 - _c = 3 - "Test".prepnd "T" - _d = 4 - _e = 5 - _f = 6 - rescue Exception => e - Bugsnag.notify(e) + context "sending code" do + it "includes code in the stack trace" do + begin + _a = 1 + _b = 2 + _c = 3 + "Test".prepnd "T" + _d = 4 + _e = 5 + _f = 6 + rescue Exception => e + Bugsnag.notify(e) + end + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + exception = get_exception_from_payload(payload) + starting_line = __LINE__ - 13 + expect(exception["stacktrace"][0]["code"]).to eq({ + (starting_line + 0).to_s => ' _a = 1', + (starting_line + 1).to_s => ' _b = 2', + (starting_line + 2).to_s => ' _c = 3', + (starting_line + 3).to_s => ' "Test".prepnd "T"', + (starting_line + 4).to_s => ' _d = 4', + (starting_line + 5).to_s => ' _e = 5', + (starting_line + 6).to_s => ' _f = 6' + }) + } end - expect(Bugsnag).to have_sent_notification{ |payload, headers| - exception = get_exception_from_payload(payload) - starting_line = __LINE__ - 13 - expect(exception["stacktrace"][0]["code"]).to eq({ - (starting_line + 0).to_s => ' _a = 1', - (starting_line + 1).to_s => ' _b = 2', - (starting_line + 2).to_s => ' _c = 3', - (starting_line + 3).to_s => ' "Test".prepnd "T"', - (starting_line + 4).to_s => ' _d = 4', - (starting_line + 5).to_s => ' _e = 5', - (starting_line + 6).to_s => ' _f = 6' + it "allows you to disable sending code" do + Bugsnag.configuration.send_code = false + + notify_test_exception + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + exception = get_exception_from_payload(payload) + expect(exception["stacktrace"][1]["code"]).to eq(nil) + } + end + + it 'should send the first 7 lines of the file for exceptions near the top' do + load 'spec/fixtures/crashes/start_of_file.rb' rescue Bugsnag.notify $! + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + exception = get_exception_from_payload(payload) + + expect(exception["stacktrace"][0]["code"]).to eq({ + "1" => "#", + "2" => "raise 'hell'", + "3" => "#", + "4" => "#", + "5" => "#", + "6" => "#", + "7" => "#" }) - } - end + } + end - it "allows you to disable sending code" do - Bugsnag.configuration.send_code = false + it 'should send the last 7 lines of the file for exceptions near the bottom' do + load 'spec/fixtures/crashes/end_of_file.rb' rescue Bugsnag.notify $! - notify_test_exception + expect(Bugsnag).to have_sent_notification{ |payload, headers| + exception = get_exception_from_payload(payload) - expect(Bugsnag).to have_sent_notification{ |payload, headers| - exception = get_exception_from_payload(payload) - expect(exception["stacktrace"][1]["code"]).to eq(nil) - } - end + expect(exception["stacktrace"][0]["code"]).to eq({ + "3" => "#", + "4" => "#", + "5" => "#", + "6" => "#", + "7" => "#", + "8" => "raise 'hell'", + "9" => "#" + }) + } + end - it 'should send the first 7 lines of the file for exceptions near the top' do - load 'spec/fixtures/crashes/start_of_file.rb' rescue Bugsnag.notify $! - - expect(Bugsnag).to have_sent_notification{ |payload, headers| - exception = get_exception_from_payload(payload) - - expect(exception["stacktrace"][0]["code"]).to eq({ - "1" => "#", - "2" => "raise 'hell'", - "3" => "#", - "4" => "#", - "5" => "#", - "6" => "#", - "7" => "#" - }) - } - end + it 'should send the last 7 lines of the file for exceptions near the bottom' do + load 'spec/fixtures/crashes/short_file.rb' rescue Bugsnag.notify $! + + expect(Bugsnag).to have_sent_notification{ |payload, headers| + exception = get_exception_from_payload(payload) - it 'should send the last 7 lines of the file for exceptions near the bottom' do - load 'spec/fixtures/crashes/end_of_file.rb' rescue Bugsnag.notify $! - - expect(Bugsnag).to have_sent_notification{ |payload, headers| - exception = get_exception_from_payload(payload) - - expect(exception["stacktrace"][0]["code"]).to eq({ - "3" => "#", - "4" => "#", - "5" => "#", - "6" => "#", - "7" => "#", - "8" => "raise 'hell'", - "9" => "#" - }) - } + expect(exception["stacktrace"][0]["code"]).to eq({ + "1" => "raise 'hell'" + }) + } + end end - it 'should send the last 7 lines of the file for exceptions near the bottom' do - load 'spec/fixtures/crashes/short_file.rb' rescue Bugsnag.notify $! + context "file paths" do + it "leaves absolute paths alone" do + configuration = Bugsnag::Configuration.new + configuration.send_code = false + + dir = File.dirname(__FILE__) + + backtrace = [ + "/foo/bar/app/models/user.rb:1:in `something'", + "/foo/bar/other_vendor/lib/dont.rb:2:in `to_s'", + "/foo/bar/vendor/lib/ignore_me.rb:3:in `to_s'", + "/foo/bar/.bundle/lib/ignore_me.rb:4:in `to_s'", + "#{dir}/../spec/stacktrace_spec.rb:5:in `something_else'", + ] - expect(Bugsnag).to have_sent_notification{ |payload, headers| - exception = get_exception_from_payload(payload) + stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a - expect(exception["stacktrace"][0]["code"]).to eq({ - "1" => "raise 'hell'" - }) - } + expect(stacktrace).to eq([ + { file: "/foo/bar/app/models/user.rb", lineNumber: 1, method: "something" }, + { file: "/foo/bar/other_vendor/lib/dont.rb", lineNumber: 2, method: "to_s" }, + { file: "/foo/bar/vendor/lib/ignore_me.rb", lineNumber: 3, method: "to_s" }, + { file: "/foo/bar/.bundle/lib/ignore_me.rb", lineNumber: 4, method: "to_s" }, + { file: "#{dir}/../spec/stacktrace_spec.rb", lineNumber: 5, method: "something_else" }, + ]) + end + + it "does not modify relative paths if they can't be resolved" do + configuration = Bugsnag::Configuration.new + + backtrace = [ + "./foo/bar/baz.rb:1:in `something'", + "../foo.rb:1:in `to_s'", + "../xyz.rb:1:in `to_s'", + ] + + stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a + + expect(stacktrace).to eq([ + { code: nil, file: "./foo/bar/baz.rb", lineNumber: 1, method: "something" }, + { code: nil, file: "../foo.rb", lineNumber: 1, method: "to_s" }, + { code: nil, file: "../xyz.rb", lineNumber: 1, method: "to_s" }, + ]) + end + + it "resolves relative paths when the files exist" do + configuration = Bugsnag::Configuration.new + configuration.send_code = false + + backtrace = [ + "./spec/spec_helper.rb:1:in `something'", + "./lib/bugsnag/breadcrumbs/../configuration.rb:100:in `to_s'", + ] + + stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a + + dir = File.dirname(__FILE__) + + expect(stacktrace).to eq([ + { file: "#{dir}/spec_helper.rb", lineNumber: 1, method: "something" }, + { file: "#{File.dirname(dir)}/lib/bugsnag/configuration.rb", lineNumber: 100, method: "to_s" }, + ]) + end end context "with configurable vendor_path" do From 481adec516c896a85f6e47e2004bdd0a8a5e8492 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 24 Jun 2020 18:08:45 +0100 Subject: [PATCH 36/44] Use File.realpath over Pathname.realpath This is a significant performance boost when sending a large number of errors as it avoids the overhead of creating another Pathname object --- lib/bugsnag/stacktrace.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bugsnag/stacktrace.rb b/lib/bugsnag/stacktrace.rb index c147935df..f4eb762ca 100644 --- a/lib/bugsnag/stacktrace.rb +++ b/lib/bugsnag/stacktrace.rb @@ -17,20 +17,19 @@ def initialize(backtrace, configuration) backtrace = caller if !backtrace || backtrace.empty? @processed_backtrace = backtrace.map do |trace| + # Parse the stacktrace line if trace.match(BACKTRACE_LINE_REGEX) file, line_str, method = [$1, $2, $3] elsif trace.match(JAVA_BACKTRACE_REGEX) method, file, line_str = [$1, $2, $3] end - # Parse the stacktrace line - next(nil) if file.nil? # Expand relative paths p = Pathname.new(file) if p.relative? - file = p.realpath.to_s rescue file + file = File.realpath(file) rescue file end # Generate the stacktrace line hash From 1c166aab2489176035bf5aad706fe90eba5ceab1 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Thu, 25 Jun 2020 09:29:28 +0100 Subject: [PATCH 37/44] Add tests for relative paths without './' or '../' --- spec/stacktrace_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/stacktrace_spec.rb b/spec/stacktrace_spec.rb index 38339d189..0f0487edd 100644 --- a/spec/stacktrace_spec.rb +++ b/spec/stacktrace_spec.rb @@ -123,6 +123,7 @@ "./foo/bar/baz.rb:1:in `something'", "../foo.rb:1:in `to_s'", "../xyz.rb:1:in `to_s'", + "abc.rb:1:in `defg'", ] stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a @@ -131,6 +132,7 @@ { code: nil, file: "./foo/bar/baz.rb", lineNumber: 1, method: "something" }, { code: nil, file: "../foo.rb", lineNumber: 1, method: "to_s" }, { code: nil, file: "../xyz.rb", lineNumber: 1, method: "to_s" }, + { code: nil, file: "abc.rb", lineNumber: 1, method: "defg" }, ]) end @@ -141,6 +143,7 @@ backtrace = [ "./spec/spec_helper.rb:1:in `something'", "./lib/bugsnag/breadcrumbs/../configuration.rb:100:in `to_s'", + "lib/bugsnag.rb:20:in `notify'", ] stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a @@ -150,6 +153,7 @@ expect(stacktrace).to eq([ { file: "#{dir}/spec_helper.rb", lineNumber: 1, method: "something" }, { file: "#{File.dirname(dir)}/lib/bugsnag/configuration.rb", lineNumber: 100, method: "to_s" }, + { file: "#{File.dirname(dir)}/lib/bugsnag.rb", lineNumber: 20, method: "notify" }, ]) end end From 47e67b715713f9f2bb5cca023b60a41f711d9719 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Tue, 14 Jul 2020 11:56:33 +0100 Subject: [PATCH 38/44] Add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08799dd3e..86d14717e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Changelog * Improve performance of payload cleaning | [#601](https://github.com/bugsnag/bugsnag-ruby/pull/601) +* Improve performance when processing stacktraces + | [#602](https://github.com/bugsnag/bugsnag-ruby/pull/602) + ### Deprecated * The `ignore_classes` configuration option has been deprecated in favour of `discard_classes`. `ignore_classes` will be removed in the next major release From f14f39a22892c9a838bee33bc8476c371ece6a9c Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Tue, 14 Jul 2020 12:20:21 +0100 Subject: [PATCH 39/44] Remove the check for a relative path This isn't a _huge_ perf boost, but every little helps :^) In the old Pathname method, this if was useful because it was quicker to skip files that were already resolved, assuming there was a mix of relative and absolute paths With File.realpath, however, it's quicker to just run the function as it does nothing if the path is already resolved. This is roughtly equal in terms of performance to using the new File.absolute_path? method (they are so close in benchmarks that it's essentially noise) --- CHANGELOG.md | 1 + lib/bugsnag/stacktrace.rb | 5 +---- spec/stacktrace_spec.rb | 10 ++++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86d14717e..608f7027f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Changelog * Improve performance when processing stacktraces | [#602](https://github.com/bugsnag/bugsnag-ruby/pull/602) + | [#603](https://github.com/bugsnag/bugsnag-ruby/pull/603) ### Deprecated diff --git a/lib/bugsnag/stacktrace.rb b/lib/bugsnag/stacktrace.rb index f4eb762ca..ac31bb535 100644 --- a/lib/bugsnag/stacktrace.rb +++ b/lib/bugsnag/stacktrace.rb @@ -27,10 +27,7 @@ def initialize(backtrace, configuration) next(nil) if file.nil? # Expand relative paths - p = Pathname.new(file) - if p.relative? - file = File.realpath(file) rescue file - end + file = File.realpath(file) rescue file # Generate the stacktrace line hash trace_hash = {} diff --git a/spec/stacktrace_spec.rb b/spec/stacktrace_spec.rb index 0f0487edd..909d4e025 100644 --- a/spec/stacktrace_spec.rb +++ b/spec/stacktrace_spec.rb @@ -95,14 +95,11 @@ configuration = Bugsnag::Configuration.new configuration.send_code = false - dir = File.dirname(__FILE__) - backtrace = [ "/foo/bar/app/models/user.rb:1:in `something'", "/foo/bar/other_vendor/lib/dont.rb:2:in `to_s'", "/foo/bar/vendor/lib/ignore_me.rb:3:in `to_s'", "/foo/bar/.bundle/lib/ignore_me.rb:4:in `to_s'", - "#{dir}/../spec/stacktrace_spec.rb:5:in `something_else'", ] stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a @@ -112,7 +109,6 @@ { file: "/foo/bar/other_vendor/lib/dont.rb", lineNumber: 2, method: "to_s" }, { file: "/foo/bar/vendor/lib/ignore_me.rb", lineNumber: 3, method: "to_s" }, { file: "/foo/bar/.bundle/lib/ignore_me.rb", lineNumber: 4, method: "to_s" }, - { file: "#{dir}/../spec/stacktrace_spec.rb", lineNumber: 5, method: "something_else" }, ]) end @@ -140,20 +136,22 @@ configuration = Bugsnag::Configuration.new configuration.send_code = false + dir = File.dirname(__FILE__) + backtrace = [ "./spec/spec_helper.rb:1:in `something'", "./lib/bugsnag/breadcrumbs/../configuration.rb:100:in `to_s'", "lib/bugsnag.rb:20:in `notify'", + "#{dir}/../spec/stacktrace_spec.rb:5:in `something_else'", ] stacktrace = Bugsnag::Stacktrace.new(backtrace, configuration).to_a - dir = File.dirname(__FILE__) - expect(stacktrace).to eq([ { file: "#{dir}/spec_helper.rb", lineNumber: 1, method: "something" }, { file: "#{File.dirname(dir)}/lib/bugsnag/configuration.rb", lineNumber: 100, method: "to_s" }, { file: "#{File.dirname(dir)}/lib/bugsnag.rb", lineNumber: 20, method: "notify" }, + { file: "#{dir}/stacktrace_spec.rb", lineNumber: 5, method: "something_else" }, ]) end end From 42c0adc47ae659a63ce823f7c62a02e4c78d121e Mon Sep 17 00:00:00 2001 From: Manoj M J Date: Fri, 8 Feb 2019 13:54:52 +0530 Subject: [PATCH 40/44] If a custom object responds to `id` method, show the id value, instead of showing "[OBJECT]" --- lib/bugsnag/cleaner.rb | 8 +++++++- spec/cleaner_spec.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index 25ca20508..bbe535c92 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -7,6 +7,7 @@ class Cleaner RECURSION = '[RECURSION]'.freeze OBJECT = '[OBJECT]'.freeze RAISED = '[RAISED]'.freeze + OBJECT_WITH_ID_AND_CLASS = '[OBJECT]: [Class]: %{class_name} [ID]: %{id}'.freeze ## # @param configuration [Configuration] @@ -121,7 +122,12 @@ def traverse_object(obj, seen, scope) # avoid leaking potentially sensitive data from objects' #inspect output if str =~ /#<.*>/ - OBJECT + # Use id of the object if available + if obj.respond_to?(:id) + OBJECT_WITH_ID_AND_CLASS % { class_name: obj.class, id: obj.id } + else + OBJECT + end else clean_string(str) end diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index 3f207a0e7..60a4c65ce 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -134,6 +134,16 @@ def to_s expect(subject.clean_object(object)).to eq("[RECURSION]") end + it "cleans custom objects to show the id of the object if object responds to id method" do + class Macaron + def id + 10 + end + end + a = Macaron.new + expect(subject.clean_object(a)).to eq("[OBJECT]: [Class]: #{a.class.name} [ID]: #{a.id}") + end + it "cleans up binary strings properly" do if RUBY_VERSION > "1.9" obj = "Andr\xc7\xff" From eb030386facdf7a2613c7c6ef7a77e33098d8903 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 15 Jul 2020 16:59:02 +0100 Subject: [PATCH 41/44] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 608f7027f..a8fbd7978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ Changelog | [#602](https://github.com/bugsnag/bugsnag-ruby/pull/602) | [#603](https://github.com/bugsnag/bugsnag-ruby/pull/603) +* If a custom object responds to `id` method, show the id and class in error reports + | [#531](https://github.com/bugsnag/bugsnag-ruby/pull/531) + | [manojmj92](https://github.com/manojmj92) + ### Deprecated * The `ignore_classes` configuration option has been deprecated in favour of `discard_classes`. `ignore_classes` will be removed in the next major release From e74728bd8d3092c6bd0742f1d12c2da1244aa8de Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 15 Jul 2020 17:42:52 +0100 Subject: [PATCH 42/44] Make Rubocop happy --- lib/bugsnag/cleaner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bugsnag/cleaner.rb b/lib/bugsnag/cleaner.rb index bbe535c92..b33d06600 100644 --- a/lib/bugsnag/cleaner.rb +++ b/lib/bugsnag/cleaner.rb @@ -7,7 +7,7 @@ class Cleaner RECURSION = '[RECURSION]'.freeze OBJECT = '[OBJECT]'.freeze RAISED = '[RAISED]'.freeze - OBJECT_WITH_ID_AND_CLASS = '[OBJECT]: [Class]: %{class_name} [ID]: %{id}'.freeze + OBJECT_WITH_ID_AND_CLASS = '[OBJECT]: [Class]: %s [ID]: %d'.freeze ## # @param configuration [Configuration] @@ -124,7 +124,7 @@ def traverse_object(obj, seen, scope) if str =~ /#<.*>/ # Use id of the object if available if obj.respond_to?(:id) - OBJECT_WITH_ID_AND_CLASS % { class_name: obj.class, id: obj.id } + format(OBJECT_WITH_ID_AND_CLASS, class_name: obj.class, id: obj.id) else OBJECT end From cb14be546c139eb70234d5a10f585c3f9b3bd622 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 15 Jul 2020 17:43:18 +0100 Subject: [PATCH 43/44] Fix test failures in Ruby 1.9 --- spec/cleaner_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/cleaner_spec.rb b/spec/cleaner_spec.rb index 60a4c65ce..96bb9dfec 100644 --- a/spec/cleaner_spec.rb +++ b/spec/cleaner_spec.rb @@ -135,12 +135,13 @@ def to_s end it "cleans custom objects to show the id of the object if object responds to id method" do - class Macaron + class MacaronWithId def id 10 end end - a = Macaron.new + + a = MacaronWithId.new expect(subject.clean_object(a)).to eq("[OBJECT]: [Class]: #{a.class.name} [ID]: #{a.id}") end From 3df705f254b8ff594aa53b1c90b500a476d5c341 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Mon, 20 Jul 2020 10:19:20 +0100 Subject: [PATCH 44/44] Bump version --- CHANGELOG.md | 2 +- VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8fbd7978..be53a6bef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ Changelog ========= -## TBD +## 6.14.0 (20 July 2020) ### Enhancements diff --git a/VERSION b/VERSION index d7d9d3fbd..68390495f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.13.1 +6.14.0