getsentry/raven-ruby

View on GitHub

Showing 143 of 143 total issues

Method handle_rate_limited_response has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_rate_limited_response(headers)
      rate_limits =
        if rate_limits = headers[RATE_LIMIT_HEADER]
          parse_rate_limit_header(rate_limits)
        elsif retry_after = headers[RETRY_AFTER_HEADER]
Severity: Minor
Found in sentry-ruby/lib/sentry/transport/http_transport.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method timing has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def timing(key, unit: 'second', tags: {}, timestamp: nil, &block)
        return unless block_given?
        return yield unless DURATION_UNITS.include?(unit)

        result, value = Sentry.with_child_span(op: OP_NAME, description: key) do |span|
Severity: Minor
Found in sentry-ruby/lib/sentry/metrics.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method compute_filename has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def compute_filename(abs_path, in_app)
      return nil if abs_path.nil?

      under_project_root = @project_root && abs_path.start_with?(@project_root)

Severity: Minor
Found in sentry-ruby/lib/sentry/profiler.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method stacktrace_interface_from has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def stacktrace_interface_from(backtrace)
      Backtrace.parse(backtrace, { configuration: configuration }).lines.reverse.each_with_object([]) do |line, memo|
        frame = StacktraceInterface::Frame.new
        frame.abs_path = line.file if line.file
        frame.function = line.method if line.method
Severity: Minor
Found in sentry-raven/lib/raven/event.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method from_sentry_sdk? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def from_sentry_sdk?(otel_span)
        dsn = Sentry.configuration.dsn
        return false unless dsn

        if otel_span.name.start_with?("HTTP")
Severity: Minor
Found in sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method build_with_stacktrace has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def self.build_with_stacktrace(exception:, stacktrace_builder:, mechanism:)
      stacktrace = stacktrace_builder.build(backtrace: exception.backtrace)

      if locals = exception.instance_variable_get(:@sentry_locals)
        locals.each do |k, v|
Severity: Minor
Found in sentry-ruby/lib/sentry/interfaces/single_exception.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method send_data has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def send_data(data)
      encoding = ""

      if should_compress?(data)
        data = Zlib.gzip(data)
Severity: Minor
Found in sentry-ruby/lib/sentry/transport/http_transport.rb - About 1 hr to fix

    Method test has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.test(dsn = nil, silent = false, config = nil)
          config ||= Raven.configuration
    
          config.logger = if silent
                            ::Logger.new(nil)
    Severity: Minor
    Found in sentry-raven/lib/raven/cli.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method capture has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

              def capture(connection, transaction_name:, extra_context: nil, &block)
                return block.call unless Sentry.initialized?
                # ActionCable's ConnectionStub (for testing) doesn't implement the exact same interfaces as Connection::Base.
                # One thing that's missing is `env`. So calling `connection.env` direclty will fail in test environments when `stub_connection` is used.
                # See https://github.com/getsentry/sentry-ruby/pull/1684 for more information.
    Severity: Minor
    Found in sentry-rails/lib/sentry/rails/action_cable.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

      create_table :delayed_jobs do |table|
        table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
        table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
        table.text :handler,                 null: false # YAML-encoded string of the object that will do work
        table.text :last_error                           # reason for last failure (See Note below)
    Severity: Major
    Found in sentry-delayed_job/example/app.rb and 1 other location - About 1 hr to fix
    sentry-rails/examples/rails-6.0/db/migrate/20211219212232_create_delayed_jobs.rb on lines 3..14

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 50.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Method new_job has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def new_job(name, interval_type, config, schedule, options)
            # Schedule the job upstream first
            # SidekiqScheduler does not validate schedules
            # It will fail with an error if the schedule in the config is invalid.
            # If this errors out, let it fall through.
    Severity: Minor
    Found in sentry-sidekiq/lib/sentry/sidekiq-scheduler/scheduler.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method add_breadcrumb has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def add_breadcrumb(severity, message = nil, progname = nil)
            message = progname if message.nil? # see Ruby's Logger docs for why
            return if ignored_logger?(progname)
            return if message.nil? || message == ""
    
    
    Severity: Minor
    Found in sentry-raven/lib/raven/breadcrumbs/sentry_logger.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        create_table :delayed_jobs do |table|
          table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
          table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
          table.text :handler,                 null: false # YAML-encoded string of the object that will do work
          table.text :last_error                           # reason for last failure (See Note below)
    sentry-delayed_job/example/app.rb on lines 13..24

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 50.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Method initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def initialize(configuration)
          @shutdown_timeout = 1
          @number_of_threads = configuration.background_worker_threads
          @max_queue = configuration.background_worker_max_queue
          @logger = configuration.logger
    Severity: Minor
    Found in sentry-ruby/lib/sentry/background_worker.rb - About 1 hr to fix

      Method record has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def record(queue, worker, payload, &block)
                Sentry.with_scope do |scope|
                  begin
                    contexts = generate_contexts(queue, worker, payload)
                    scope.set_contexts(**contexts)
      Severity: Minor
      Found in sentry-resque/lib/sentry/resque.rb - About 1 hr to fix

        Method record has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                  def record(job, &block)
                    Sentry.with_scope do |scope|
                      begin
                        scope.set_transaction_name(job.class.name, source: :task)
                        transaction =
        Severity: Minor
        Found in sentry-rails/lib/sentry/rails/active_job.rb - About 1 hr to fix

          Method envelope_from_event has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def envelope_from_event(event)
                # Convert to hash
                event_payload = event.to_hash
                event_id = event_payload[:event_id] || event_payload["event_id"]
                item_type = event_payload[:type] || event_payload["type"]
          Severity: Minor
          Found in sentry-ruby/lib/sentry/transport.rb - About 1 hr to fix

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

              def create
                @post = Post.new(post_params)
            
                respond_to do |format|
                  if @post.save
            sentry-rails/examples/rails-5.2/app/controllers/posts_controller.rb on lines 26..35
            sentry-rails/examples/rails-6.0/app/controllers/posts_controller.rb on lines 32..41

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 47.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

              def create
                @post = Post.new(post_params)
            
                respond_to do |format|
                  if @post.save
            sentry-rails/examples/rails-5.2/app/controllers/posts_controller.rb on lines 26..35
            sentry-rails/examples/rails-7.0/app/controllers/posts_controller.rb on lines 32..41

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 47.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

              def create
                @post = Post.new(post_params)
            
                respond_to do |format|
                  if @post.save
            sentry-rails/examples/rails-6.0/app/controllers/posts_controller.rb on lines 32..41
            sentry-rails/examples/rails-7.0/app/controllers/posts_controller.rb on lines 32..41

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 47.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Severity
            Category
            Status
            Source
            Language