AI Analysis

    Intelligent error analysis and automated fix suggestions.

    ActiveRabbit's AI engine analyzes your errors and performance issues to provide actionable insights and fix suggestions. This guide explains how to get the most out of AI-powered analysis.

    How It Works

    When an error is captured, our AI analyzes:

    • Stack trace - Identifies the root cause location
    • Error message - Extracts key information
    • Code context - Reviews surrounding code
    • Historical data - Compares with similar past errors
    • Rails patterns - Matches against known issues

    Fix Suggestions

    For common error patterns, ActiveRabbit suggests specific code fixes:

    # Example: NoMethodError on nil
    # Your code:
    user.profile.avatar_url
    
    # AI Analysis:
    # "Null reference error - profile may be nil"
    #
    # Suggested fix:
    user&.profile&.avatar_url
    # or
    user.profile&.avatar_url if user.profile.present?
    
    # With explanation:
    # "Use safe navigation operator (&.) to handle cases where 
    #  profile is nil. Consider adding a presence check if the 
    #  nil case should be handled differently."

    Error Categories

    The AI automatically categorizes errors:

    CategoryExamplesAI Action
    Null ReferenceNoMethodError on nilSuggests safe navigation, presence checks
    DatabaseActiveRecord errors, N+1Query optimization, eager loading
    ValidationRecordInvalid, params issuesInput validation, strong params
    External ServiceTimeout, connection errorsRetry logic, circuit breakers
    SecurityCSRF, auth failuresSecurity best practices

    Root Cause Analysis

    # When you have a chain of errors, AI traces to root cause:
    #
    # Symptom: ActionView::Template::Error in orders/show
    #   └─ Caused by: NoMethodError in OrderPresenter
    #       └─ Root cause: nil product in line_item
    #
    # AI identifies: "Data integrity issue - LineItem has 
    # product_id referencing deleted Product"
    #
    # Suggested fixes:
    # 1. Add foreign key constraint with ON DELETE behavior
    # 2. Add validation: validates :product, presence: true
    # 3. Handle gracefully: line_item.product || NullProduct.new

    Smart Grouping

    AI groups errors by root cause, not just stack trace:

    # These errors are grouped together despite different stack traces:
    #
    # Error 1: NoMethodError: undefined method 'name' for nil
    #   app/views/users/show.html.erb:15
    #
    # Error 2: NoMethodError: undefined method 'email' for nil  
    #   app/views/users/profile.html.erb:8
    #
    # AI groups as: "User object nil in views"
    # Common cause: Current user session expired or invalid user_id

    Performance Insights

    AI analyzes performance data to identify issues:

    # AI Performance Analysis Example:
    #
    # Detected: Response time increased 340% over 2 weeks
    # 
    # Analysis:
    # - P95 latency: 89ms → 392ms
    # - Primary contributor: Database queries (+280ms)
    # - Specific query: SELECT * FROM orders WHERE user_id = ?
    # 
    # Root cause: Missing index after migration
    # 
    # Suggested fix:
    # rails g migration AddIndexToOrdersUserId
    #
    # add_index :orders, :user_id
    #
    # Estimated improvement: ~85% reduction in query time

    Enabling AI Features

    ActiveRabbit.configure do |config|
      config.api_key = ENV['ACTIVERABBIT_API_KEY']
      
      # Enable AI analysis (enabled by default)
      config.ai_analysis = true
      
      # Upload source code for better analysis
      config.include_source_context = true
      
      # Number of source lines to include
      config.source_context_lines = 10
    end

    Code Context

    For best AI analysis, enable source code context:

    # During deployment, upload source maps
    activerabbit releases new \
      --release v1.2.3 \
      --commit $(git rev-parse HEAD)
    
    # Upload source code (for AI analysis)
    activerabbit releases upload-source \
      --release v1.2.3 \
      --path ./app
    
    # This enables:
    # - Accurate source location in stack traces
    # - AI analysis of actual code, not just error messages
    # - Suggested fixes with proper context

    AI Insights Dashboard

    The dashboard shows AI-generated insights including:

    • Trend Analysis - "Error rate increased 50% after deploy at 3:45 PM"
    • Impact Assessment - "This error affects 12% of checkout attempts"
    • Priority Score - Based on frequency, user impact, and fixability
    • Similar Issues - "3 other errors share the same root cause"

    Custom AI Rules

    # Add custom context to improve AI analysis
    ActiveRabbit.configure do |config|
      config.before_send do |event|
        # Add feature flags context
        event.extra[:feature_flags] = current_feature_flags
        
        # Add deployment info
        event.extra[:deployment] = {
          version: ENV['APP_VERSION'],
          deployed_at: ENV['DEPLOYED_AT'],
          deployer: ENV['DEPLOYED_BY']
        }
        
        event
      end
    end
    
    # AI uses this context to identify:
    # - Errors specific to feature flag states
    # - Regression introduced in specific deployments
    # - Environment-specific issues

    Privacy & Security

    AI analysis respects your privacy settings:

    • Filtered parameters are never sent to AI
    • Source code is processed in isolated environments
    • No data is used to train external models
    • Self-hosted customers can run AI locally

    🤖 Getting Better Results

    • Enable source code uploads for accurate fix suggestions
    • Add meaningful context (user IDs, feature flags, etc.)
    • Use breadcrumbs to show user flow before errors
    • Tag errors by feature area for better grouping