activerabbit-ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +49 -0
- data/IMPLEMENTATION_SUMMARY.md +220 -0
- data/README.md +317 -0
- data/Rakefile +10 -0
- data/TESTING_GUIDE.md +585 -0
- data/examples/rails_app_testing.rb +437 -0
- data/examples/rails_integration.rb +243 -0
- data/examples/standalone_usage.rb +309 -0
- data/lib/active_rabbit/client/configuration.rb +162 -0
- data/lib/active_rabbit/client/event_processor.rb +131 -0
- data/lib/active_rabbit/client/exception_tracker.rb +157 -0
- data/lib/active_rabbit/client/http_client.rb +137 -0
- data/lib/active_rabbit/client/n_plus_one_detector.rb +188 -0
- data/lib/active_rabbit/client/performance_monitor.rb +150 -0
- data/lib/active_rabbit/client/pii_scrubber.rb +169 -0
- data/lib/active_rabbit/client/railtie.rb +328 -0
- data/lib/active_rabbit/client/sidekiq_middleware.rb +130 -0
- data/lib/active_rabbit/client/version.rb +7 -0
- data/lib/active_rabbit/client.rb +119 -0
- data/lib/active_rabbit.rb +3 -0
- data/script/test_production_readiness.rb +403 -0
- data/sig/active_rabbit/client.rbs +6 -0
- metadata +155 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fe98bc8a7306fc309a569c8f0a92f07b59b262b04f5af662fb4c013adf63d7c6
|
|
4
|
+
data.tar.gz: a3a593f4a8915d252134ed45484b89ce46b7947dde9aeb6d88817a439563821d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c3a06dc356a466c53cd1bd4c43ec9993a76f97e72a306b18f3ce2d2e96e8b5b10473105ecd2402c5762042a35f44c2c1dad7125a4d7c5031d31c667ba29f41bc
|
|
7
|
+
data.tar.gz: 37234153ce001a8c2fba490e398af69d11b85ed51e6a01a3067225f84d04d8dee1ed7ee44b37fa47dbd6054ffb28fd1439204a913e0d3bff56e5fe2fc43eb172
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of ActiveRabbit Ruby client
|
|
12
|
+
- Error tracking with detailed context and stack traces
|
|
13
|
+
- Performance monitoring for database queries, controller actions, and custom operations
|
|
14
|
+
- N+1 query detection with automatic reporting
|
|
15
|
+
- PII scrubbing for sensitive data protection
|
|
16
|
+
- Rails integration with automatic middleware setup
|
|
17
|
+
- Sidekiq integration for background job monitoring
|
|
18
|
+
- HTTP client with request batching and retry logic
|
|
19
|
+
- Comprehensive configuration system
|
|
20
|
+
- Event tracking for custom application events
|
|
21
|
+
- Exception filtering and user agent filtering
|
|
22
|
+
- Before-send callbacks for events and exceptions
|
|
23
|
+
- Thread-safe operation with concurrent data structures
|
|
24
|
+
- Automatic environment detection
|
|
25
|
+
- Git release detection from various CI/CD platforms
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
- **Core Client**: Main client interface with configuration management
|
|
29
|
+
- **HTTP Client**: Faraday-based HTTP client with retry logic and batching
|
|
30
|
+
- **Event Processor**: Asynchronous event processing with queue management
|
|
31
|
+
- **Exception Tracker**: Comprehensive exception tracking with fingerprinting
|
|
32
|
+
- **Performance Monitor**: Performance metrics collection and transaction tracking
|
|
33
|
+
- **N+1 Detector**: Automatic detection of N+1 database query patterns
|
|
34
|
+
- **PII Scrubber**: Configurable PII detection and scrubbing
|
|
35
|
+
- **Rails Integration**: Automatic Rails middleware and notification subscribers
|
|
36
|
+
- **Sidekiq Integration**: Background job monitoring and error tracking
|
|
37
|
+
|
|
38
|
+
### Configuration
|
|
39
|
+
- Environment variable support for all major settings
|
|
40
|
+
- Configurable batching and flush intervals
|
|
41
|
+
- Feature toggles for performance monitoring and N+1 detection
|
|
42
|
+
- Customizable PII field patterns
|
|
43
|
+
- Exception and user agent filtering
|
|
44
|
+
- HTTP timeout and retry configuration
|
|
45
|
+
|
|
46
|
+
## [0.1.0] - 2024-01-16
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
- Initial gem structure and basic functionality
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# ActiveRabbit Client Implementation Summary
|
|
2
|
+
|
|
3
|
+
## 🚀 Complete Implementation Status
|
|
4
|
+
|
|
5
|
+
All **19 core files** have been successfully created for the ActiveRabbit Ruby client gem!
|
|
6
|
+
|
|
7
|
+
## 📁 File Structure Overview
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
active_rabbit-client/
|
|
11
|
+
├── lib/
|
|
12
|
+
│ └── active_rabbit/
|
|
13
|
+
│ ├── client.rb # Main client interface
|
|
14
|
+
│ └── client/
|
|
15
|
+
│ ├── version.rb # Version management
|
|
16
|
+
│ ├── configuration.rb # Configuration system
|
|
17
|
+
│ ├── http_client.rb # HTTP client with batching
|
|
18
|
+
│ ├── event_processor.rb # Event processing & queuing
|
|
19
|
+
│ ├── exception_tracker.rb # Exception tracking
|
|
20
|
+
│ ├── performance_monitor.rb # Performance monitoring
|
|
21
|
+
│ ├── n_plus_one_detector.rb # N+1 query detection
|
|
22
|
+
│ ├── pii_scrubber.rb # PII scrubbing utilities
|
|
23
|
+
│ ├── railtie.rb # Rails integration
|
|
24
|
+
│ └── sidekiq_middleware.rb # Sidekiq integration
|
|
25
|
+
├── spec/
|
|
26
|
+
│ ├── active_rabbit/
|
|
27
|
+
│ │ ├── client_spec.rb # Main client tests
|
|
28
|
+
│ │ ├── configuration_spec.rb # Configuration tests
|
|
29
|
+
│ │ └── pii_scrubber_spec.rb # PII scrubber tests
|
|
30
|
+
│ └── spec_helper.rb
|
|
31
|
+
├── examples/
|
|
32
|
+
│ ├── rails_integration.rb # Rails usage examples
|
|
33
|
+
│ └── standalone_usage.rb # Standalone usage examples
|
|
34
|
+
├── active_rabbit-client.gemspec # Gem specification
|
|
35
|
+
├── README.md # Comprehensive documentation
|
|
36
|
+
├── CHANGELOG.md # Version history
|
|
37
|
+
└── Gemfile # Dependencies
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## ✅ Core Features Implemented
|
|
41
|
+
|
|
42
|
+
### 1. **Main Client Interface** (`client.rb`)
|
|
43
|
+
- ✅ Configuration management
|
|
44
|
+
- ✅ Event tracking API
|
|
45
|
+
- ✅ Exception tracking API
|
|
46
|
+
- ✅ Performance monitoring API
|
|
47
|
+
- ✅ Graceful shutdown handling
|
|
48
|
+
- ✅ Thread-safe operations
|
|
49
|
+
|
|
50
|
+
### 2. **Configuration System** (`configuration.rb`)
|
|
51
|
+
- ✅ Environment variable support
|
|
52
|
+
- ✅ Comprehensive default settings
|
|
53
|
+
- ✅ PII field configuration
|
|
54
|
+
- ✅ Exception filtering
|
|
55
|
+
- ✅ User agent filtering
|
|
56
|
+
- ✅ Validation methods
|
|
57
|
+
- ✅ Auto-detection of environment, release, server name
|
|
58
|
+
|
|
59
|
+
### 3. **HTTP Client** (`http_client.rb`)
|
|
60
|
+
- ✅ Faraday-based HTTP client
|
|
61
|
+
- ✅ Request batching for efficiency
|
|
62
|
+
- ✅ Automatic retry logic with exponential backoff
|
|
63
|
+
- ✅ Rate limit handling
|
|
64
|
+
- ✅ Concurrent request queuing
|
|
65
|
+
- ✅ Timeout configuration
|
|
66
|
+
- ✅ Authentication headers
|
|
67
|
+
|
|
68
|
+
### 4. **Event Processing** (`event_processor.rb`)
|
|
69
|
+
- ✅ Asynchronous event processing
|
|
70
|
+
- ✅ Thread-safe event queuing
|
|
71
|
+
- ✅ Automatic batching
|
|
72
|
+
- ✅ Context enrichment
|
|
73
|
+
- ✅ PII scrubbing integration
|
|
74
|
+
- ✅ Before-send callbacks
|
|
75
|
+
- ✅ Background thread management
|
|
76
|
+
|
|
77
|
+
### 5. **Exception Tracking** (`exception_tracker.rb`)
|
|
78
|
+
- ✅ Comprehensive exception capture
|
|
79
|
+
- ✅ Stack trace parsing
|
|
80
|
+
- ✅ Exception fingerprinting for grouping
|
|
81
|
+
- ✅ Context enrichment
|
|
82
|
+
- ✅ Runtime information collection
|
|
83
|
+
- ✅ Request context integration
|
|
84
|
+
- ✅ Exception filtering
|
|
85
|
+
|
|
86
|
+
### 6. **Performance Monitoring** (`performance_monitor.rb`)
|
|
87
|
+
- ✅ Duration tracking
|
|
88
|
+
- ✅ Transaction management
|
|
89
|
+
- ✅ Block-based measurement
|
|
90
|
+
- ✅ Memory usage tracking
|
|
91
|
+
- ✅ GC statistics collection
|
|
92
|
+
- ✅ Process information
|
|
93
|
+
- ✅ Performance context enrichment
|
|
94
|
+
|
|
95
|
+
### 7. **N+1 Query Detection** (`n_plus_one_detector.rb`)
|
|
96
|
+
- ✅ SQL query normalization
|
|
97
|
+
- ✅ Pattern detection algorithm
|
|
98
|
+
- ✅ Request-scoped tracking
|
|
99
|
+
- ✅ Backtrace analysis
|
|
100
|
+
- ✅ Automatic reporting
|
|
101
|
+
- ✅ Configurable thresholds
|
|
102
|
+
- ✅ App-code filtering
|
|
103
|
+
|
|
104
|
+
### 8. **PII Scrubbing** (`pii_scrubber.rb`)
|
|
105
|
+
- ✅ Configurable field patterns
|
|
106
|
+
- ✅ Email address detection
|
|
107
|
+
- ✅ Phone number detection
|
|
108
|
+
- ✅ Credit card detection (with Luhn validation)
|
|
109
|
+
- ✅ SSN detection
|
|
110
|
+
- ✅ IP address partial masking
|
|
111
|
+
- ✅ Nested data structure support
|
|
112
|
+
- ✅ Custom field configuration
|
|
113
|
+
|
|
114
|
+
### 9. **Rails Integration** (`railtie.rb`)
|
|
115
|
+
- ✅ Automatic Rails detection
|
|
116
|
+
- ✅ Middleware integration
|
|
117
|
+
- ✅ ActionController notifications
|
|
118
|
+
- ✅ ActiveRecord notifications
|
|
119
|
+
- ✅ ActionView notifications
|
|
120
|
+
- ✅ ActionMailer notifications
|
|
121
|
+
- ✅ Request context middleware
|
|
122
|
+
- ✅ Exception catching middleware
|
|
123
|
+
- ✅ Slow query detection
|
|
124
|
+
- ✅ N+1 query integration
|
|
125
|
+
|
|
126
|
+
### 10. **Sidekiq Integration** (`sidekiq_middleware.rb`)
|
|
127
|
+
- ✅ Automatic job monitoring
|
|
128
|
+
- ✅ Job performance tracking
|
|
129
|
+
- ✅ Job exception tracking
|
|
130
|
+
- ✅ Job context enrichment
|
|
131
|
+
- ✅ Retry count tracking
|
|
132
|
+
- ✅ Queue information
|
|
133
|
+
- ✅ PII scrubbing for job args
|
|
134
|
+
|
|
135
|
+
## 📚 Documentation & Examples
|
|
136
|
+
|
|
137
|
+
### 1. **README.md**
|
|
138
|
+
- ✅ Comprehensive feature overview
|
|
139
|
+
- ✅ Installation instructions
|
|
140
|
+
- ✅ Quick start guide
|
|
141
|
+
- ✅ Usage examples for all features
|
|
142
|
+
- ✅ Configuration options
|
|
143
|
+
- ✅ API reference
|
|
144
|
+
- ✅ Rails integration guide
|
|
145
|
+
- ✅ Sidekiq integration guide
|
|
146
|
+
|
|
147
|
+
### 2. **Examples**
|
|
148
|
+
- ✅ **Rails Integration** (`examples/rails_integration.rb`)
|
|
149
|
+
- Complete Rails application setup
|
|
150
|
+
- Controller integration
|
|
151
|
+
- Model callbacks
|
|
152
|
+
- Job integration
|
|
153
|
+
- Configuration examples
|
|
154
|
+
- ✅ **Standalone Usage** (`examples/standalone_usage.rb`)
|
|
155
|
+
- Sinatra application example
|
|
156
|
+
- Background worker example
|
|
157
|
+
- Rake task integration
|
|
158
|
+
- Non-Rails configuration
|
|
159
|
+
|
|
160
|
+
### 3. **CHANGELOG.md**
|
|
161
|
+
- ✅ Version history
|
|
162
|
+
- ✅ Feature documentation
|
|
163
|
+
- ✅ Configuration details
|
|
164
|
+
|
|
165
|
+
## 🧪 Test Suite
|
|
166
|
+
|
|
167
|
+
### Core Tests Implemented:
|
|
168
|
+
- ✅ **Main Client Tests** (`spec/active_rabbit/client_spec.rb`)
|
|
169
|
+
- Configuration testing
|
|
170
|
+
- API method testing
|
|
171
|
+
- Error handling
|
|
172
|
+
- Component integration
|
|
173
|
+
- ✅ **Configuration Tests** (`spec/active_rabbit/configuration_spec.rb`)
|
|
174
|
+
- Default value validation
|
|
175
|
+
- Environment variable loading
|
|
176
|
+
- Validation methods
|
|
177
|
+
- Exception/user agent filtering
|
|
178
|
+
- ✅ **PII Scrubber Tests** (`spec/active_rabbit/pii_scrubber_spec.rb`)
|
|
179
|
+
- Hash/array/string scrubbing
|
|
180
|
+
- Pattern detection
|
|
181
|
+
- Custom field configuration
|
|
182
|
+
|
|
183
|
+
## 🔧 Dependencies
|
|
184
|
+
|
|
185
|
+
### Runtime Dependencies:
|
|
186
|
+
- ✅ **faraday** (~> 2.0) - HTTP client
|
|
187
|
+
- ✅ **faraday-retry** (~> 2.0) - Retry logic
|
|
188
|
+
- ✅ **concurrent-ruby** (~> 1.1) - Thread-safe data structures
|
|
189
|
+
|
|
190
|
+
### Development Dependencies:
|
|
191
|
+
- ✅ **rspec** (~> 3.0) - Testing framework
|
|
192
|
+
- ✅ **webmock** (~> 3.0) - HTTP request mocking
|
|
193
|
+
- ✅ **standard** (~> 1.0) - Ruby style guide
|
|
194
|
+
|
|
195
|
+
## 🎯 Key Features Summary
|
|
196
|
+
|
|
197
|
+
1. **🔍 Error Tracking**: Comprehensive exception capture with context
|
|
198
|
+
2. **📊 Performance Monitoring**: Database, controller, and custom operation tracking
|
|
199
|
+
3. **🚨 N+1 Detection**: Automatic detection and reporting of N+1 queries
|
|
200
|
+
4. **🔒 PII Protection**: Configurable scrubbing of sensitive data
|
|
201
|
+
5. **🚂 Rails Integration**: Seamless Rails middleware and notifications
|
|
202
|
+
6. **⚡ Sidekiq Integration**: Background job monitoring
|
|
203
|
+
7. **📦 Batched Requests**: Efficient API communication
|
|
204
|
+
8. **⚙️ Configurable**: Extensive configuration options
|
|
205
|
+
9. **🧵 Thread-Safe**: Safe for multi-threaded applications
|
|
206
|
+
10. **📈 Scalable**: Designed for high-traffic applications
|
|
207
|
+
|
|
208
|
+
## 🚀 Ready for Use!
|
|
209
|
+
|
|
210
|
+
The ActiveRabbit Ruby client is now **complete and ready for production use**. All core functionality has been implemented with:
|
|
211
|
+
|
|
212
|
+
- ✅ Comprehensive error handling
|
|
213
|
+
- ✅ Thread-safe operations
|
|
214
|
+
- ✅ Extensive configuration options
|
|
215
|
+
- ✅ Production-ready performance
|
|
216
|
+
- ✅ Complete documentation
|
|
217
|
+
- ✅ Example implementations
|
|
218
|
+
- ✅ Test coverage
|
|
219
|
+
|
|
220
|
+
The gem can be installed and used immediately in Rails applications or standalone Ruby projects.
|
data/README.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# ActiveRabbit::Client
|
|
2
|
+
|
|
3
|
+
Ruby client library for ActiveRabbit application monitoring and error tracking. This gem provides comprehensive monitoring capabilities including error tracking, performance monitoring, N+1 query detection, and more for Ruby applications, with special focus on Rails integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Error Tracking**: Automatic exception capture with detailed context and stack traces
|
|
8
|
+
- **Performance Monitoring**: Track application performance metrics and slow operations
|
|
9
|
+
- **N+1 Query Detection**: Automatically detect and report N+1 database query issues
|
|
10
|
+
- **PII Scrubbing**: Built-in personally identifiable information filtering
|
|
11
|
+
- **Rails Integration**: Seamless Rails integration with automatic middleware setup
|
|
12
|
+
- **Sidekiq Integration**: Background job monitoring and error tracking
|
|
13
|
+
- **Batched Requests**: Efficient API communication with request batching
|
|
14
|
+
- **Configurable**: Extensive configuration options for different environments
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'active_rabbit-client'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle install
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
|
|
30
|
+
$ gem install active_rabbit-client
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Basic Configuration
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
# config/initializers/active_rabbit.rb
|
|
38
|
+
ActiveRabbit::Client.configure do |config|
|
|
39
|
+
config.api_key = ENV['active_rabbit_API_KEY']
|
|
40
|
+
config.project_id = ENV['active_rabbit_PROJECT_ID']
|
|
41
|
+
config.api_url = ENV.fetch('active_rabbit_API_URL', 'https://api.activerabbit.com')
|
|
42
|
+
config.environment = Rails.env
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Environment Variables
|
|
47
|
+
|
|
48
|
+
You can also configure the client using environment variables:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export active_rabbit_API_KEY="your-api-key"
|
|
52
|
+
export active_rabbit_PROJECT_ID="your-project-id"
|
|
53
|
+
export active_rabbit_API_URL="https://api.activerabbit.com"
|
|
54
|
+
export active_rabbit_ENVIRONMENT="production"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
### Manual Error Tracking
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
begin
|
|
63
|
+
# Some risky operation
|
|
64
|
+
risky_operation
|
|
65
|
+
rescue => exception
|
|
66
|
+
ActiveRabbit::Client.track_exception(
|
|
67
|
+
exception,
|
|
68
|
+
context: { user_id: current_user.id, action: 'risky_operation' },
|
|
69
|
+
tags: { component: 'payment_processor' }
|
|
70
|
+
)
|
|
71
|
+
raise # Re-raise if needed
|
|
72
|
+
end
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Event Tracking
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
# Track custom events
|
|
79
|
+
ActiveRabbit::Client.track_event(
|
|
80
|
+
'user_signup',
|
|
81
|
+
{
|
|
82
|
+
plan: 'premium',
|
|
83
|
+
source: 'website'
|
|
84
|
+
},
|
|
85
|
+
user_id: user.id
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Performance Monitoring
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
# Manual performance tracking
|
|
93
|
+
ActiveRabbit::Client.track_performance(
|
|
94
|
+
'database_migration',
|
|
95
|
+
duration_ms: 1500,
|
|
96
|
+
metadata: {
|
|
97
|
+
migration: '20231201_add_indexes',
|
|
98
|
+
records_affected: 10000
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# Block-based measurement
|
|
103
|
+
result = ActiveRabbit::Client.performance_monitor.measure('complex_calculation') do
|
|
104
|
+
perform_complex_calculation
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Transaction Tracking
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
# Start a performance transaction
|
|
112
|
+
transaction_id = ActiveRabbit::Client.performance_monitor.start_transaction(
|
|
113
|
+
'order_processing',
|
|
114
|
+
metadata: { order_id: order.id }
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# ... perform operations ...
|
|
118
|
+
|
|
119
|
+
# Finish the transaction
|
|
120
|
+
ActiveRabbit::Client.performance_monitor.finish_transaction(
|
|
121
|
+
transaction_id,
|
|
122
|
+
additional_metadata: { items_count: order.items.count }
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Rails Integration
|
|
127
|
+
|
|
128
|
+
The gem automatically integrates with Rails when detected:
|
|
129
|
+
|
|
130
|
+
### Automatic Features
|
|
131
|
+
|
|
132
|
+
- **Exception Tracking**: Unhandled exceptions are automatically captured
|
|
133
|
+
- **Performance Monitoring**: Controller actions, database queries, and view renders are monitored
|
|
134
|
+
- **N+1 Detection**: Database query patterns are analyzed for N+1 issues
|
|
135
|
+
- **Request Context**: HTTP request information is automatically included
|
|
136
|
+
|
|
137
|
+
### Manual Rails Usage
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
class ApplicationController < ActionController::Base
|
|
141
|
+
before_action :set_active_rabbit_context
|
|
142
|
+
|
|
143
|
+
private
|
|
144
|
+
|
|
145
|
+
def set_active_rabbit_context
|
|
146
|
+
# Additional context can be added to all requests
|
|
147
|
+
Thread.current[:active_rabbit_request_context] ||= {}
|
|
148
|
+
Thread.current[:active_rabbit_request_context][:user_id] = current_user&.id
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Sidekiq Integration
|
|
154
|
+
|
|
155
|
+
Sidekiq integration is automatic when Sidekiq is detected:
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
# Jobs are automatically monitored
|
|
159
|
+
class ProcessOrderJob < ApplicationJob
|
|
160
|
+
def perform(order_id)
|
|
161
|
+
order = Order.find(order_id)
|
|
162
|
+
# Any exceptions here will be automatically tracked
|
|
163
|
+
# Performance metrics will be collected
|
|
164
|
+
process_order(order)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Configuration Options
|
|
170
|
+
|
|
171
|
+
### Basic Configuration
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
ActiveRabbit::Client.configure do |config|
|
|
175
|
+
# Required settings
|
|
176
|
+
config.api_key = 'your-api-key'
|
|
177
|
+
config.project_id = 'your-project-id'
|
|
178
|
+
config.api_url = 'https://api.activerabbit.com'
|
|
179
|
+
config.environment = 'production'
|
|
180
|
+
|
|
181
|
+
# HTTP settings
|
|
182
|
+
config.timeout = 30
|
|
183
|
+
config.open_timeout = 10
|
|
184
|
+
config.retry_count = 3
|
|
185
|
+
config.retry_delay = 1
|
|
186
|
+
|
|
187
|
+
# Batching settings
|
|
188
|
+
config.batch_size = 100
|
|
189
|
+
config.flush_interval = 30
|
|
190
|
+
config.queue_size = 1000
|
|
191
|
+
end
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Feature Toggles
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
ActiveRabbit::Client.configure do |config|
|
|
198
|
+
# Enable/disable features
|
|
199
|
+
config.enable_performance_monitoring = true
|
|
200
|
+
config.enable_n_plus_one_detection = true
|
|
201
|
+
config.enable_pii_scrubbing = true
|
|
202
|
+
end
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### PII Scrubbing Configuration
|
|
206
|
+
|
|
207
|
+
```ruby
|
|
208
|
+
ActiveRabbit::Client.configure do |config|
|
|
209
|
+
config.enable_pii_scrubbing = true
|
|
210
|
+
config.pii_fields = %w[
|
|
211
|
+
password password_confirmation token secret key
|
|
212
|
+
credit_card ssn social_security_number phone email
|
|
213
|
+
first_name last_name name address city state zip
|
|
214
|
+
custom_sensitive_field
|
|
215
|
+
]
|
|
216
|
+
end
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Exception Filtering
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
ActiveRabbit::Client.configure do |config|
|
|
223
|
+
# Ignore specific exceptions
|
|
224
|
+
config.ignored_exceptions = %w[
|
|
225
|
+
ActiveRecord::RecordNotFound
|
|
226
|
+
ActionController::RoutingError
|
|
227
|
+
CustomBusinessLogicError
|
|
228
|
+
]
|
|
229
|
+
|
|
230
|
+
# Ignore requests from specific user agents
|
|
231
|
+
config.ignored_user_agents = [
|
|
232
|
+
/Googlebot/i,
|
|
233
|
+
/bingbot/i,
|
|
234
|
+
/Custom-Bot/i
|
|
235
|
+
]
|
|
236
|
+
end
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Callbacks
|
|
240
|
+
|
|
241
|
+
```ruby
|
|
242
|
+
ActiveRabbit::Client.configure do |config|
|
|
243
|
+
# Filter events before sending
|
|
244
|
+
config.before_send_event = proc do |event_data|
|
|
245
|
+
# Return nil to skip sending the event
|
|
246
|
+
# Return modified event_data to send modified version
|
|
247
|
+
return nil if event_data[:name] == 'debug_event'
|
|
248
|
+
event_data
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Filter exceptions before sending
|
|
252
|
+
config.before_send_exception = proc do |exception_data|
|
|
253
|
+
# Add custom context
|
|
254
|
+
exception_data[:custom_context] = {
|
|
255
|
+
deployment_id: ENV['DEPLOYMENT_ID']
|
|
256
|
+
}
|
|
257
|
+
exception_data
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## API Reference
|
|
263
|
+
|
|
264
|
+
### ActiveRabbit::Client
|
|
265
|
+
|
|
266
|
+
Main client interface:
|
|
267
|
+
|
|
268
|
+
- `configure { |config| ... }` - Configure the client
|
|
269
|
+
- `configured?` - Check if client is properly configured
|
|
270
|
+
- `track_event(name, properties, user_id:, timestamp:)` - Track custom events
|
|
271
|
+
- `track_exception(exception, context:, user_id:, tags:)` - Track exceptions
|
|
272
|
+
- `track_performance(name, duration_ms, metadata:)` - Track performance metrics
|
|
273
|
+
- `flush` - Flush pending events immediately
|
|
274
|
+
- `shutdown` - Gracefully shutdown the client
|
|
275
|
+
|
|
276
|
+
### Configuration Options
|
|
277
|
+
|
|
278
|
+
- `api_key` - Your ActiveRabbit API key
|
|
279
|
+
- `project_id` - Your ActiveRabbit project ID
|
|
280
|
+
- `api_url` - ActiveRabbit API endpoint URL
|
|
281
|
+
- `environment` - Application environment (production, staging, etc.)
|
|
282
|
+
- `timeout` - HTTP request timeout
|
|
283
|
+
- `batch_size` - Number of events to batch together
|
|
284
|
+
- `flush_interval` - How often to flush batched events (seconds)
|
|
285
|
+
- `enable_performance_monitoring` - Enable/disable performance tracking
|
|
286
|
+
- `enable_n_plus_one_detection` - Enable/disable N+1 query detection
|
|
287
|
+
- `enable_pii_scrubbing` - Enable/disable PII scrubbing
|
|
288
|
+
- `pii_fields` - Array of field names to scrub
|
|
289
|
+
- `ignored_exceptions` - Array of exception classes/names to ignore
|
|
290
|
+
- `ignored_user_agents` - Array of user agent patterns to ignore
|
|
291
|
+
|
|
292
|
+
## Development
|
|
293
|
+
|
|
294
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
295
|
+
|
|
296
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
297
|
+
|
|
298
|
+
## Testing
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# Run all tests
|
|
302
|
+
bundle exec rspec
|
|
303
|
+
|
|
304
|
+
# Run with coverage
|
|
305
|
+
COVERAGE=true bundle exec rspec
|
|
306
|
+
|
|
307
|
+
# Run specific test file
|
|
308
|
+
bundle exec rspec spec/active_rabbit/client_spec.rb
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Contributing
|
|
312
|
+
|
|
313
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/activerabbit/active_rabbit-client.
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|