diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbf611..238785f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.5.4 - 2026-02-15 + +1. fix: Move Rails generator template to `lib/generators/posthog/templates/` to ensure it's included in the gem package ([#103](https://github.com/PostHog/posthog-ruby/issues/103)) + ## 3.5.3 - 2026-02-08 1. fix: Fix Railtie middleware insertion crashing on Rails initialization — changed `insert_middleware_after` from a class method to an instance method (matching how Rails executes initializer blocks via `instance_exec`), and removed the unsupported `include?` query on `MiddlewareStackProxy` ([#97](https://github.com/PostHog/posthog-ruby/issues/97)) diff --git a/lib/posthog/version.rb b/lib/posthog/version.rb index 00464c0..8766c8f 100644 --- a/lib/posthog/version.rb +++ b/lib/posthog/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module PostHog - VERSION = '3.5.3' + VERSION = '3.5.4' end diff --git a/posthog-rails/lib/generators/posthog/install_generator.rb b/posthog-rails/lib/generators/posthog/install_generator.rb index f13b10e..5c3a04a 100644 --- a/posthog-rails/lib/generators/posthog/install_generator.rb +++ b/posthog-rails/lib/generators/posthog/install_generator.rb @@ -7,10 +7,10 @@ module Generators class InstallGenerator < ::Rails::Generators::Base desc 'Creates a PostHog initializer file at config/initializers/posthog.rb' - source_root File.expand_path('../../..', __dir__) + source_root File.expand_path('templates', __dir__) def copy_initializer - copy_file 'examples/posthog.rb', 'config/initializers/posthog.rb' + copy_file 'posthog.rb', 'config/initializers/posthog.rb' end def show_readme diff --git a/posthog-rails/lib/generators/posthog/templates/posthog.rb b/posthog-rails/lib/generators/posthog/templates/posthog.rb new file mode 100644 index 0000000..3b6fc81 --- /dev/null +++ b/posthog-rails/lib/generators/posthog/templates/posthog.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true + +# PostHog Rails Initializer +# Place this file in config/initializers/posthog.rb + +# ============================================================================ +# RAILS-SPECIFIC CONFIGURATION +# ============================================================================ +# Configure Rails-specific options via PostHog::Rails.configure +# These settings control how PostHog integrates with Rails features. + +PostHog::Rails.configure do |config| + # Automatically capture exceptions (default: false) + # Set to true to enable automatic exception tracking + # config.auto_capture_exceptions = true + + # Report exceptions that Rails rescues (e.g., with rescue_from) (default: false) + # Set to true to capture rescued exceptions + # config.report_rescued_exceptions = true + + # Automatically instrument ActiveJob background jobs (default: false) + # Set to true to enable automatic ActiveJob exception tracking + # config.auto_instrument_active_job = true + + # Capture user context with exceptions (default: true) + # config.capture_user_context = true + + # Controller method name to get current user (default: :current_user) + # Change this if your app uses a different method name (e.g., :authenticated_user) + # When configured, exceptions will include user context (distinct_id, email, name), + # making it easier to identify affected users and debug user-specific issues. + # config.current_user_method = :current_user + + # Additional exception classes to exclude from reporting + # These are added to the default excluded exceptions + # config.excluded_exceptions = [ + # # 'MyCustom404Error', + # # 'MyCustomValidationError' + # ] +end + +# You can also configure Rails options directly: +# PostHog::Rails.config.auto_capture_exceptions = true + +# ============================================================================ +# CORE POSTHOG CONFIGURATION +# ============================================================================ +# Initialize the PostHog client with core SDK options. + +PostHog.init do |config| + # ============================================================================ + # REQUIRED CONFIGURATION + # ============================================================================ + + # Your PostHog project API key (required) + # Get this from: PostHog Project Settings > API Keys + # https://app.posthog.com/settings/project-details#variables + config.api_key = ENV.fetch('POSTHOG_API_KEY', nil) + + # ============================================================================ + # OPTIONAL CONFIGURATION + # ============================================================================ + + # For PostHog Cloud, use: https://us.i.posthog.com or https://eu.i.posthog.com + config.host = ENV.fetch('POSTHOG_HOST', 'https://us.i.posthog.com') + + # Personal API key (optional, but required for local feature flag evaluation) + # Get this from: PostHog Settings > Personal API Keys + # https://app.posthog.com/settings/user-api-keys + config.personal_api_key = ENV.fetch('POSTHOG_PERSONAL_API_KEY', nil) + + # Maximum number of events to queue before dropping (default: 10000) + config.max_queue_size = 10_000 + + # Feature flags polling interval in seconds (default: 30) + config.feature_flags_polling_interval = 30 + + # Feature flag request timeout in seconds (default: 3) + config.feature_flag_request_timeout_seconds = 3 + + # Error callback - called when PostHog encounters an error + # config.on_error = proc { |status, message| + # Rails.logger.error("[PostHog] Error #{status}: #{message}") + # } + + # Before send callback - modify or filter events before sending + # Return nil to prevent the event from being sent + # config.before_send = proc { |event| + # # Filter out test users + # return nil if event[:properties]&.dig('$user_email')&.end_with?('@test.com') + # + # # Add custom properties to all events + # event[:properties] ||= {} + # event[:properties]['environment'] = Rails.env + # + # event + # } + + # ============================================================================ + # ENVIRONMENT-SPECIFIC CONFIGURATION + # ============================================================================ + + # Disable in test environment + config.test_mode = true if Rails.env.test? + + # Optional: Disable in development + # config.test_mode = true if Rails.env.test? || Rails.env.development? +end + +# ============================================================================ +# DEFAULT EXCLUDED EXCEPTIONS +# ============================================================================ +# The following exceptions are excluded by default: +# +# - AbstractController::ActionNotFound +# - ActionController::BadRequest +# - ActionController::InvalidAuthenticityToken +# - ActionController::InvalidCrossOriginRequest +# - ActionController::MethodNotAllowed +# - ActionController::NotImplemented +# - ActionController::ParameterMissing +# - ActionController::RoutingError +# - ActionController::UnknownFormat +# - ActionController::UnknownHttpMethod +# - ActionDispatch::Http::Parameters::ParseError +# - ActiveRecord::RecordNotFound +# - ActiveRecord::RecordNotUnique +# +# These can be re-enabled by removing them from the exclusion list if needed.