fluyenta-ruby 0.1.14
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/CHANGELOG.md +68 -0
- data/LICENSE +11 -0
- data/README.md +571 -0
- data/lib/brainzlab/beacon/client.rb +227 -0
- data/lib/brainzlab/beacon/provisioner.rb +44 -0
- data/lib/brainzlab/beacon.rb +215 -0
- data/lib/brainzlab/configuration.rb +676 -0
- data/lib/brainzlab/context.rb +90 -0
- data/lib/brainzlab/cortex/cache.rb +59 -0
- data/lib/brainzlab/cortex/client.rb +159 -0
- data/lib/brainzlab/cortex/provisioner.rb +49 -0
- data/lib/brainzlab/cortex.rb +223 -0
- data/lib/brainzlab/debug.rb +305 -0
- data/lib/brainzlab/dendrite/client.rb +250 -0
- data/lib/brainzlab/dendrite/provisioner.rb +44 -0
- data/lib/brainzlab/dendrite.rb +195 -0
- data/lib/brainzlab/development/logger.rb +150 -0
- data/lib/brainzlab/development/store.rb +121 -0
- data/lib/brainzlab/development.rb +72 -0
- data/lib/brainzlab/devtools/assets/devtools.css +1329 -0
- data/lib/brainzlab/devtools/assets/devtools.js +396 -0
- data/lib/brainzlab/devtools/assets/logo.svg +6 -0
- data/lib/brainzlab/devtools/assets/templates/debug_panel.html.erb +511 -0
- data/lib/brainzlab/devtools/assets/templates/error_page.html.erb +1086 -0
- data/lib/brainzlab/devtools/data/collector.rb +248 -0
- data/lib/brainzlab/devtools/middleware/asset_server.rb +63 -0
- data/lib/brainzlab/devtools/middleware/database_handler.rb +177 -0
- data/lib/brainzlab/devtools/middleware/debug_panel.rb +126 -0
- data/lib/brainzlab/devtools/middleware/error_page.rb +377 -0
- data/lib/brainzlab/devtools/renderers/debug_panel_renderer.rb +159 -0
- data/lib/brainzlab/devtools/renderers/error_page_renderer.rb +98 -0
- data/lib/brainzlab/devtools.rb +75 -0
- data/lib/brainzlab/errors.rb +490 -0
- data/lib/brainzlab/flux/buffer.rb +96 -0
- data/lib/brainzlab/flux/client.rb +68 -0
- data/lib/brainzlab/flux/provisioner.rb +124 -0
- data/lib/brainzlab/flux.rb +184 -0
- data/lib/brainzlab/instrumentation/action_cable.rb +351 -0
- data/lib/brainzlab/instrumentation/action_controller.rb +649 -0
- data/lib/brainzlab/instrumentation/action_dispatch.rb +259 -0
- data/lib/brainzlab/instrumentation/action_mailbox.rb +197 -0
- data/lib/brainzlab/instrumentation/action_mailer.rb +182 -0
- data/lib/brainzlab/instrumentation/action_view.rb +380 -0
- data/lib/brainzlab/instrumentation/active_job.rb +569 -0
- data/lib/brainzlab/instrumentation/active_record.rb +559 -0
- data/lib/brainzlab/instrumentation/active_storage.rb +541 -0
- data/lib/brainzlab/instrumentation/active_support_cache.rb +730 -0
- data/lib/brainzlab/instrumentation/aws.rb +183 -0
- data/lib/brainzlab/instrumentation/dalli.rb +108 -0
- data/lib/brainzlab/instrumentation/delayed_job.rb +234 -0
- data/lib/brainzlab/instrumentation/elasticsearch.rb +209 -0
- data/lib/brainzlab/instrumentation/excon.rb +152 -0
- data/lib/brainzlab/instrumentation/faraday.rb +181 -0
- data/lib/brainzlab/instrumentation/good_job.rb +102 -0
- data/lib/brainzlab/instrumentation/grape.rb +293 -0
- data/lib/brainzlab/instrumentation/graphql.rb +252 -0
- data/lib/brainzlab/instrumentation/httparty.rb +193 -0
- data/lib/brainzlab/instrumentation/mongodb.rb +187 -0
- data/lib/brainzlab/instrumentation/net_http.rb +114 -0
- data/lib/brainzlab/instrumentation/rails_deprecation.rb +139 -0
- data/lib/brainzlab/instrumentation/railties.rb +134 -0
- data/lib/brainzlab/instrumentation/redis.rb +324 -0
- data/lib/brainzlab/instrumentation/resque.rb +114 -0
- data/lib/brainzlab/instrumentation/sidekiq.rb +265 -0
- data/lib/brainzlab/instrumentation/solid_queue.rb +194 -0
- data/lib/brainzlab/instrumentation/stripe.rb +163 -0
- data/lib/brainzlab/instrumentation/typhoeus.rb +106 -0
- data/lib/brainzlab/instrumentation.rb +360 -0
- data/lib/brainzlab/nerve/client.rb +235 -0
- data/lib/brainzlab/nerve/provisioner.rb +44 -0
- data/lib/brainzlab/nerve.rb +219 -0
- data/lib/brainzlab/pulse/client.rb +203 -0
- data/lib/brainzlab/pulse/instrumentation.rb +401 -0
- data/lib/brainzlab/pulse/propagation.rb +241 -0
- data/lib/brainzlab/pulse/provisioner.rb +114 -0
- data/lib/brainzlab/pulse/tracer.rb +111 -0
- data/lib/brainzlab/pulse.rb +294 -0
- data/lib/brainzlab/rails/log_formatter.rb +807 -0
- data/lib/brainzlab/rails/log_subscriber.rb +334 -0
- data/lib/brainzlab/rails/railtie.rb +606 -0
- data/lib/brainzlab/recall/buffer.rb +66 -0
- data/lib/brainzlab/recall/client.rb +158 -0
- data/lib/brainzlab/recall/logger.rb +116 -0
- data/lib/brainzlab/recall/provisioner.rb +130 -0
- data/lib/brainzlab/recall.rb +175 -0
- data/lib/brainzlab/reflex/breadcrumbs.rb +55 -0
- data/lib/brainzlab/reflex/client.rb +150 -0
- data/lib/brainzlab/reflex/provisioner.rb +116 -0
- data/lib/brainzlab/reflex.rb +421 -0
- data/lib/brainzlab/sentinel/client.rb +236 -0
- data/lib/brainzlab/sentinel/provisioner.rb +44 -0
- data/lib/brainzlab/sentinel.rb +165 -0
- data/lib/brainzlab/signal/client.rb +60 -0
- data/lib/brainzlab/signal/provisioner.rb +115 -0
- data/lib/brainzlab/signal.rb +136 -0
- data/lib/brainzlab/synapse/client.rb +308 -0
- data/lib/brainzlab/synapse/provisioner.rb +44 -0
- data/lib/brainzlab/synapse.rb +270 -0
- data/lib/brainzlab/testing/event_store.rb +377 -0
- data/lib/brainzlab/testing/helpers.rb +650 -0
- data/lib/brainzlab/testing/matchers.rb +391 -0
- data/lib/brainzlab/testing.rb +327 -0
- data/lib/brainzlab/utilities/circuit_breaker.rb +290 -0
- data/lib/brainzlab/utilities/health_check.rb +294 -0
- data/lib/brainzlab/utilities/log_formatter.rb +254 -0
- data/lib/brainzlab/utilities/rate_limiter.rb +230 -0
- data/lib/brainzlab/utilities.rb +17 -0
- data/lib/brainzlab/vault/cache.rb +80 -0
- data/lib/brainzlab/vault/client.rb +216 -0
- data/lib/brainzlab/vault/provisioner.rb +49 -0
- data/lib/brainzlab/vault.rb +262 -0
- data/lib/brainzlab/version.rb +5 -0
- data/lib/brainzlab/vision/client.rb +175 -0
- data/lib/brainzlab/vision/provisioner.rb +136 -0
- data/lib/brainzlab/vision.rb +155 -0
- data/lib/brainzlab-sdk.rb +3 -0
- data/lib/brainzlab.rb +306 -0
- data/lib/generators/brainzlab/install/install_generator.rb +63 -0
- data/lib/generators/brainzlab/install/templates/brainzlab.rb.tt +77 -0
- metadata +251 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 87d4a26be4c3abfeaeda6fc7c0c197215a457d1444f24ba224305c9e080f286b
|
|
4
|
+
data.tar.gz: 609546d538388627c1ace6840f7c518ca92fbcd27b618fa37ffd681a6d604f99
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6313badd5547bee8de8d489cb353d8c1265fcfc84bfd13eacba22c33cdd5982a309fdb153332c45aa04770bb0eb9d381f902bbefa5fac3fc0781691d878b5d91
|
|
7
|
+
data.tar.gz: b6b248d819cac668ace6cba23f2fe6f71afcca695b3cc6fdd3c1a675654a5e795be72ba985791d2666d94c02007389acf40bfec91d48a964083f10f47dbf2bd5
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.13] - 2026-02-24
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Rails LogFormatter** - Fix `TypeError: wrong element type Hash at 0 (expected array)` in `format_params_toml`
|
|
10
|
+
- `hash_like?` incorrectly matched Arrays (they respond to `to_h` and `each`), causing `Array#to_h` to fail when params contained arrays of hashes
|
|
11
|
+
|
|
12
|
+
## [0.1.1] - 2025-12-23
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **Reflex** - Improved backtrace parsing
|
|
17
|
+
- Handle different Ruby backtrace formats (backtick+quote and single quotes)
|
|
18
|
+
- Parse backtrace lines without method names
|
|
19
|
+
- Better `in_app` frame detection for absolute paths
|
|
20
|
+
|
|
21
|
+
## [0.1.0] - 2025-01-01
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- **Recall** - Structured logging
|
|
26
|
+
- Log levels (debug, info, warn, error, fatal)
|
|
27
|
+
- Buffered batch sending
|
|
28
|
+
- Auto-provisioning support
|
|
29
|
+
- Rails integration
|
|
30
|
+
|
|
31
|
+
- **Reflex** - Error tracking
|
|
32
|
+
- Exception capturing with context
|
|
33
|
+
- Breadcrumbs support
|
|
34
|
+
- User context tracking
|
|
35
|
+
- Sample rate and before_send hooks
|
|
36
|
+
- Custom fingerprinting
|
|
37
|
+
- Auto-provisioning support
|
|
38
|
+
|
|
39
|
+
- **Pulse** - APM & Distributed Tracing
|
|
40
|
+
- Request tracing with breakdown
|
|
41
|
+
- Distributed tracing (W3C Trace Context + B3)
|
|
42
|
+
- Auto-provisioning support
|
|
43
|
+
|
|
44
|
+
- **Instrumentation** (13 libraries)
|
|
45
|
+
- Rails/Rack middleware
|
|
46
|
+
- Active Record (SQL queries)
|
|
47
|
+
- Net::HTTP
|
|
48
|
+
- Faraday
|
|
49
|
+
- HTTParty
|
|
50
|
+
- Redis (v4 and v5+)
|
|
51
|
+
- Sidekiq (server and client middleware)
|
|
52
|
+
- Delayed::Job
|
|
53
|
+
- GraphQL (query and field tracing)
|
|
54
|
+
- Grape API
|
|
55
|
+
- MongoDB/Mongoid
|
|
56
|
+
- Elasticsearch/OpenSearch
|
|
57
|
+
- ActionMailer
|
|
58
|
+
|
|
59
|
+
- **Configuration**
|
|
60
|
+
- Environment variable support
|
|
61
|
+
- Per-product enable/disable
|
|
62
|
+
- Sensitive field scrubbing
|
|
63
|
+
- Debug mode
|
|
64
|
+
|
|
65
|
+
- **Rails Integration**
|
|
66
|
+
- Automatic setup via Railtie
|
|
67
|
+
- Request context propagation
|
|
68
|
+
- User context from current_user
|
data/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
OSAaSy License
|
|
2
|
+
|
|
3
|
+
Copyright © 2025, Brainz Lab.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
No licensee or downstream recipient may use the Software (including any modified or derivative versions) to directly compete with the original Licensor by offering it to third parties as a hosted, managed, or Software-as-a-Service (SaaS) product or cloud service where the primary value of the service is the functionality of the Software itself.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
# BrainzLab Ruby SDK
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/brainzlab)
|
|
4
|
+
[](https://github.com/brainz-lab/brainzlab-ruby/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/brainz-lab/brainzlab-ruby/actions/workflows/codeql.yml)
|
|
6
|
+
[](https://codecov.io/gh/brainz-lab/brainzlab-ruby)
|
|
7
|
+
[](https://docs.brainzlab.ai/sdk/ruby/installation)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
Official Ruby SDK for [BrainzLab](https://brainzlab.ai) - the complete observability platform.
|
|
11
|
+
|
|
12
|
+
- **Recall** - Structured logging
|
|
13
|
+
- **Reflex** - Error tracking
|
|
14
|
+
- **Pulse** - APM & distributed tracing
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### From RubyGems (recommended)
|
|
19
|
+
|
|
20
|
+
Add to your Gemfile:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
gem 'brainzlab'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then run:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bundle install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### From GitHub Packages
|
|
33
|
+
|
|
34
|
+
Add the GitHub Packages source to your Gemfile:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
source "https://rubygems.pkg.github.com/brainz-lab" do
|
|
38
|
+
gem 'brainzlab'
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Configure Bundler with your GitHub token:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bundle config set --global rubygems.pkg.github.com USERNAME:TOKEN
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Get Your API Key
|
|
51
|
+
|
|
52
|
+
1. Sign up at [platform.brainzlab.ai](https://platform.brainzlab.ai)
|
|
53
|
+
2. Create or select a project
|
|
54
|
+
3. Copy your API key (`sk_live_xxx` or `sk_test_xxx`)
|
|
55
|
+
4. Set it as `BRAINZLAB_SECRET_KEY` environment variable
|
|
56
|
+
|
|
57
|
+
**One key, all products**: Your Platform API key works across Recall, Reflex, Pulse, and all BrainzLab products. No separate keys needed.
|
|
58
|
+
|
|
59
|
+
### Configuration
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# config/initializers/brainzlab.rb
|
|
63
|
+
BrainzLab.configure do |config|
|
|
64
|
+
# Authentication (required) - Your Platform API key
|
|
65
|
+
config.secret_key = ENV['BRAINZLAB_SECRET_KEY']
|
|
66
|
+
|
|
67
|
+
# Environment
|
|
68
|
+
config.environment = Rails.env
|
|
69
|
+
config.service = 'my-app'
|
|
70
|
+
|
|
71
|
+
# Enable/disable products
|
|
72
|
+
config.recall_enabled = true # Logging
|
|
73
|
+
config.reflex_enabled = true # Error tracking
|
|
74
|
+
config.pulse_enabled = true # APM
|
|
75
|
+
|
|
76
|
+
# Auto-provisioning (creates projects automatically)
|
|
77
|
+
config.recall_auto_provision = true
|
|
78
|
+
config.reflex_auto_provision = true
|
|
79
|
+
config.pulse_auto_provision = true
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Recall - Structured Logging
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
# Log levels
|
|
87
|
+
BrainzLab::Recall.debug("Debug message", details: "...")
|
|
88
|
+
BrainzLab::Recall.info("User signed up", user_id: user.id)
|
|
89
|
+
BrainzLab::Recall.warn("Rate limit approaching", current: 95, limit: 100)
|
|
90
|
+
BrainzLab::Recall.error("Payment failed", error: e.message, amount: 99.99)
|
|
91
|
+
BrainzLab::Recall.fatal("Database connection lost")
|
|
92
|
+
|
|
93
|
+
# With context
|
|
94
|
+
BrainzLab::Recall.info("Order created",
|
|
95
|
+
order_id: order.id,
|
|
96
|
+
user_id: user.id,
|
|
97
|
+
total: order.total,
|
|
98
|
+
items: order.items.count
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Configuration Options
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
config.recall_min_level = :info # Minimum log level (:debug, :info, :warn, :error, :fatal)
|
|
106
|
+
config.recall_buffer_size = 50 # Batch size before flush
|
|
107
|
+
config.recall_flush_interval = 5 # Seconds between flushes
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Reflex - Error Tracking
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
# Capture exceptions
|
|
114
|
+
begin
|
|
115
|
+
risky_operation
|
|
116
|
+
rescue => e
|
|
117
|
+
BrainzLab::Reflex.capture(e,
|
|
118
|
+
user_id: current_user.id,
|
|
119
|
+
order_id: order.id
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Add breadcrumbs for context
|
|
124
|
+
BrainzLab::Reflex.add_breadcrumb("User clicked checkout",
|
|
125
|
+
category: "ui.click",
|
|
126
|
+
data: { button: "checkout" }
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Set user context
|
|
130
|
+
BrainzLab::Reflex.set_user(
|
|
131
|
+
id: user.id,
|
|
132
|
+
email: user.email,
|
|
133
|
+
plan: user.plan
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Add tags
|
|
137
|
+
BrainzLab::Reflex.set_tags(
|
|
138
|
+
environment: "production",
|
|
139
|
+
region: "us-east-1"
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Configuration Options
|
|
144
|
+
|
|
145
|
+
```ruby
|
|
146
|
+
config.reflex_excluded_exceptions = ['ActiveRecord::RecordNotFound']
|
|
147
|
+
config.reflex_sample_rate = 1.0 # 1.0 = 100%, 0.5 = 50%
|
|
148
|
+
config.reflex_before_send = ->(event) {
|
|
149
|
+
# Modify or filter events
|
|
150
|
+
event[:tags][:custom] = 'value'
|
|
151
|
+
event # Return nil to drop the event
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Pulse - APM & Distributed Tracing
|
|
156
|
+
|
|
157
|
+
Pulse automatically instruments your application to track performance.
|
|
158
|
+
|
|
159
|
+
### Automatic Instrumentation
|
|
160
|
+
|
|
161
|
+
The SDK automatically instruments:
|
|
162
|
+
|
|
163
|
+
| Library | Description |
|
|
164
|
+
|---------|-------------|
|
|
165
|
+
| Rails/Rack | Request tracing with breakdown |
|
|
166
|
+
| Active Record | SQL queries with timing |
|
|
167
|
+
| Net::HTTP | Outbound HTTP calls |
|
|
168
|
+
| Faraday | HTTP client requests |
|
|
169
|
+
| HTTParty | HTTP client requests |
|
|
170
|
+
| Redis | Redis commands |
|
|
171
|
+
| Sidekiq | Background job processing |
|
|
172
|
+
| Delayed::Job | Background job processing |
|
|
173
|
+
| GraphQL | Query and field resolution |
|
|
174
|
+
| Grape | API endpoint tracing |
|
|
175
|
+
| MongoDB | Database operations |
|
|
176
|
+
| Elasticsearch | Search operations |
|
|
177
|
+
| ActionMailer | Email delivery |
|
|
178
|
+
|
|
179
|
+
### Configuration Options
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
# Enable/disable specific instrumentations
|
|
183
|
+
config.instrument_http = true # Net::HTTP, Faraday, HTTParty
|
|
184
|
+
config.instrument_active_record = true # SQL queries
|
|
185
|
+
config.instrument_redis = true # Redis commands
|
|
186
|
+
config.instrument_sidekiq = true # Sidekiq jobs
|
|
187
|
+
config.instrument_graphql = true # GraphQL queries
|
|
188
|
+
config.instrument_mongodb = true # MongoDB operations
|
|
189
|
+
config.instrument_elasticsearch = true # Elasticsearch queries
|
|
190
|
+
config.instrument_action_mailer = true # Email delivery
|
|
191
|
+
config.instrument_delayed_job = true # Delayed::Job
|
|
192
|
+
config.instrument_grape = true # Grape API
|
|
193
|
+
|
|
194
|
+
# Filtering
|
|
195
|
+
config.http_ignore_hosts = ['localhost', '127.0.0.1']
|
|
196
|
+
config.redis_ignore_commands = ['ping', 'info']
|
|
197
|
+
config.pulse_excluded_paths = ['/health', '/ping', '/up', '/assets']
|
|
198
|
+
config.pulse_sample_rate = 1.0 # 1.0 = 100%
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Distributed Tracing
|
|
202
|
+
|
|
203
|
+
Pulse supports distributed tracing across services using W3C Trace Context and B3 propagation.
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
# Extracting trace context from incoming requests (automatic in Rails)
|
|
207
|
+
context = BrainzLab::Pulse.extract!(request.headers)
|
|
208
|
+
|
|
209
|
+
# Injecting trace context into outgoing requests (automatic with instrumentation)
|
|
210
|
+
BrainzLab::Pulse.inject!(headers)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Custom Spans
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
BrainzLab::Pulse.trace("process_payment", kind: "payment") do |span|
|
|
217
|
+
span[:data] = { amount: 99.99, currency: "USD" }
|
|
218
|
+
process_payment(order)
|
|
219
|
+
end
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Rails Integration
|
|
223
|
+
|
|
224
|
+
The SDK automatically integrates with Rails when loaded:
|
|
225
|
+
|
|
226
|
+
- Request context (request_id, path, method, params)
|
|
227
|
+
- Exception reporting to Reflex
|
|
228
|
+
- Performance tracing with Pulse
|
|
229
|
+
- User context from `current_user`
|
|
230
|
+
|
|
231
|
+
### Setting User Context
|
|
232
|
+
|
|
233
|
+
```ruby
|
|
234
|
+
class ApplicationController < ActionController::Base
|
|
235
|
+
before_action :set_brainzlab_context
|
|
236
|
+
|
|
237
|
+
private
|
|
238
|
+
|
|
239
|
+
def set_brainzlab_context
|
|
240
|
+
if current_user
|
|
241
|
+
BrainzLab.set_user(
|
|
242
|
+
id: current_user.id,
|
|
243
|
+
email: current_user.email,
|
|
244
|
+
name: current_user.name
|
|
245
|
+
)
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Sidekiq Integration
|
|
252
|
+
|
|
253
|
+
For Sidekiq, the SDK automatically:
|
|
254
|
+
|
|
255
|
+
- Traces job execution with queue wait time
|
|
256
|
+
- Propagates trace context between web and worker
|
|
257
|
+
- Captures job failures to Reflex
|
|
258
|
+
|
|
259
|
+
```ruby
|
|
260
|
+
# config/initializers/sidekiq.rb
|
|
261
|
+
# Instrumentation is automatic, but you can configure:
|
|
262
|
+
|
|
263
|
+
BrainzLab.configure do |config|
|
|
264
|
+
config.instrument_sidekiq = true
|
|
265
|
+
end
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Grape API Integration
|
|
269
|
+
|
|
270
|
+
For Grape APIs, you can use the middleware:
|
|
271
|
+
|
|
272
|
+
```ruby
|
|
273
|
+
class API < Grape::API
|
|
274
|
+
use BrainzLab::Instrumentation::GrapeInstrumentation::Middleware
|
|
275
|
+
|
|
276
|
+
# Your API endpoints...
|
|
277
|
+
end
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## GraphQL Integration
|
|
281
|
+
|
|
282
|
+
For GraphQL-Ruby 2.0+, add the tracer:
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
class MySchema < GraphQL::Schema
|
|
286
|
+
trace_with BrainzLab::Instrumentation::GraphQLInstrumentation::Tracer
|
|
287
|
+
|
|
288
|
+
# Your schema...
|
|
289
|
+
end
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Environment Variables
|
|
293
|
+
|
|
294
|
+
| Variable | Description |
|
|
295
|
+
|----------|-------------|
|
|
296
|
+
| `BRAINZLAB_SECRET_KEY` | API key for authentication |
|
|
297
|
+
| `BRAINZLAB_ENVIRONMENT` | Environment name (default: auto-detect) |
|
|
298
|
+
| `BRAINZLAB_SERVICE` | Service name |
|
|
299
|
+
| `BRAINZLAB_APP_NAME` | App name for auto-provisioning |
|
|
300
|
+
| `BRAINZLAB_DEBUG` | Enable debug logging (`true`/`false`) |
|
|
301
|
+
| `BRAINZLAB_MODE` | SDK mode: `production` (default) or `development` (offline) |
|
|
302
|
+
| `BRAINZLAB_DEV_DB_PATH` | SQLite database path for development mode |
|
|
303
|
+
| `RECALL_URL` | Custom Recall endpoint |
|
|
304
|
+
| `REFLEX_URL` | Custom Reflex endpoint |
|
|
305
|
+
| `PULSE_URL` | Custom Pulse endpoint |
|
|
306
|
+
|
|
307
|
+
## Scrubbing Sensitive Data
|
|
308
|
+
|
|
309
|
+
The SDK automatically scrubs sensitive fields:
|
|
310
|
+
|
|
311
|
+
```ruby
|
|
312
|
+
config.scrub_fields = [:password, :password_confirmation, :token, :api_key, :secret]
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Debug Mode
|
|
316
|
+
|
|
317
|
+
Debug mode provides detailed visibility into SDK operations, including all API requests and responses with timing information. This is invaluable for troubleshooting integration issues.
|
|
318
|
+
|
|
319
|
+
### Enabling Debug Mode
|
|
320
|
+
|
|
321
|
+
```ruby
|
|
322
|
+
# In your initializer
|
|
323
|
+
BrainzLab.configure do |config|
|
|
324
|
+
config.debug = true
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Or via environment variable
|
|
328
|
+
# BRAINZLAB_DEBUG=true
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Debug Output Format
|
|
332
|
+
|
|
333
|
+
When debug mode is enabled, you'll see colorized output in your terminal:
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
[BrainzLab] 12:34:56 -> Recall POST /api/v1/logs (count: 5)
|
|
337
|
+
[BrainzLab] 12:34:56 <- Recall 200 OK (45ms)
|
|
338
|
+
|
|
339
|
+
[BrainzLab] 12:34:57 -> Reflex POST /api/v1/errors (exception: RuntimeError)
|
|
340
|
+
[BrainzLab] 12:34:57 <- Reflex 201 Created (23ms)
|
|
341
|
+
|
|
342
|
+
[BrainzLab] 12:34:58 -> Pulse POST /api/v1/traces (name: GET /users)
|
|
343
|
+
[BrainzLab] 12:34:58 <- Pulse 200 OK (18ms)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
The output includes:
|
|
347
|
+
- Timestamp for each operation
|
|
348
|
+
- Service name (Recall, Reflex, Pulse, etc.)
|
|
349
|
+
- Request method and path
|
|
350
|
+
- Payload summary (log count, exception type, etc.)
|
|
351
|
+
- Response status code and message
|
|
352
|
+
- Request duration with color coding (green < 100ms, yellow < 1s, red > 1s)
|
|
353
|
+
|
|
354
|
+
### Custom Logger
|
|
355
|
+
|
|
356
|
+
You can provide your own logger to capture debug output:
|
|
357
|
+
|
|
358
|
+
```ruby
|
|
359
|
+
BrainzLab.configure do |config|
|
|
360
|
+
config.debug = true
|
|
361
|
+
config.logger = Rails.logger
|
|
362
|
+
# Or any Logger-compatible object
|
|
363
|
+
config.logger = Logger.new('log/brainzlab.log')
|
|
364
|
+
end
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Debug Callbacks
|
|
368
|
+
|
|
369
|
+
For advanced debugging and monitoring, you can hook into SDK operations:
|
|
370
|
+
|
|
371
|
+
```ruby
|
|
372
|
+
BrainzLab.configure do |config|
|
|
373
|
+
# Called before each API request
|
|
374
|
+
config.on_send = ->(service, method, path, payload) {
|
|
375
|
+
Rails.logger.debug "[BrainzLab] Sending to #{service}: #{method} #{path}"
|
|
376
|
+
|
|
377
|
+
# You can use this to:
|
|
378
|
+
# - Log all outgoing requests
|
|
379
|
+
# - Send metrics to your monitoring system
|
|
380
|
+
# - Add custom tracing
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
# Called when an SDK error occurs
|
|
384
|
+
config.on_error = ->(error, context) {
|
|
385
|
+
Rails.logger.error "[BrainzLab] Error in #{context[:service]}: #{error.message}"
|
|
386
|
+
|
|
387
|
+
# You can use this to:
|
|
388
|
+
# - Alert on SDK failures
|
|
389
|
+
# - Track error rates
|
|
390
|
+
# - Fallback to alternative logging
|
|
391
|
+
|
|
392
|
+
# Note: This is for SDK errors, not application errors
|
|
393
|
+
# Application errors are sent to Reflex as normal
|
|
394
|
+
}
|
|
395
|
+
end
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Programmatic Debug Logging
|
|
399
|
+
|
|
400
|
+
You can also use the Debug module directly:
|
|
401
|
+
|
|
402
|
+
```ruby
|
|
403
|
+
# Log a debug message (only outputs when debug=true)
|
|
404
|
+
BrainzLab::Debug.log("Custom message", level: :info)
|
|
405
|
+
BrainzLab::Debug.log("Something went wrong", level: :error, error_code: 500)
|
|
406
|
+
|
|
407
|
+
# Measure operation timing
|
|
408
|
+
BrainzLab::Debug.measure(:custom, "expensive_operation") do
|
|
409
|
+
# Your code here
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
# Check if debug mode is enabled
|
|
413
|
+
if BrainzLab::Debug.enabled?
|
|
414
|
+
# Perform additional debug operations
|
|
415
|
+
end
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Debug Output Levels
|
|
419
|
+
|
|
420
|
+
Debug messages are color-coded by level:
|
|
421
|
+
- **DEBUG** (gray) - Verbose internal operations
|
|
422
|
+
- **INFO** (cyan) - Normal operations
|
|
423
|
+
- **WARN** (yellow) - Potential issues
|
|
424
|
+
- **ERROR** (red) - Failed operations
|
|
425
|
+
|
|
426
|
+
## Development Mode
|
|
427
|
+
|
|
428
|
+
Development mode allows you to use the SDK without a BrainzLab server connection. Events are logged to stdout in a readable format and stored locally in a SQLite database.
|
|
429
|
+
|
|
430
|
+
### Configuration
|
|
431
|
+
|
|
432
|
+
```ruby
|
|
433
|
+
# config/initializers/brainzlab.rb
|
|
434
|
+
BrainzLab.configure do |config|
|
|
435
|
+
# Enable development mode (works offline)
|
|
436
|
+
config.mode = :development
|
|
437
|
+
|
|
438
|
+
# Optional: customize the SQLite database path (default: tmp/brainzlab.sqlite3)
|
|
439
|
+
config.development_db_path = 'tmp/brainzlab_dev.sqlite3'
|
|
440
|
+
|
|
441
|
+
# Other settings still apply
|
|
442
|
+
config.environment = Rails.env
|
|
443
|
+
config.service = 'my-app'
|
|
444
|
+
end
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
Or use the environment variable:
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
export BRAINZLAB_MODE=development
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### Features
|
|
454
|
+
|
|
455
|
+
In development mode:
|
|
456
|
+
|
|
457
|
+
- **No server connection required** - Works completely offline
|
|
458
|
+
- **Stdout logging** - All events are pretty-printed to the console with colors
|
|
459
|
+
- **Local storage** - Events are stored in SQLite at `tmp/brainzlab.sqlite3`
|
|
460
|
+
- **Queryable** - Use `BrainzLab.development_events` to query stored events
|
|
461
|
+
|
|
462
|
+
### Querying Events
|
|
463
|
+
|
|
464
|
+
```ruby
|
|
465
|
+
# Get all events
|
|
466
|
+
events = BrainzLab.development_events
|
|
467
|
+
|
|
468
|
+
# Filter by service
|
|
469
|
+
logs = BrainzLab.development_events(service: :recall)
|
|
470
|
+
errors = BrainzLab.development_events(service: :reflex)
|
|
471
|
+
traces = BrainzLab.development_events(service: :pulse)
|
|
472
|
+
|
|
473
|
+
# Filter by event type
|
|
474
|
+
BrainzLab.development_events(event_type: 'log')
|
|
475
|
+
BrainzLab.development_events(event_type: 'error')
|
|
476
|
+
BrainzLab.development_events(event_type: 'trace')
|
|
477
|
+
|
|
478
|
+
# Filter by time
|
|
479
|
+
BrainzLab.development_events(since: 1.hour.ago)
|
|
480
|
+
|
|
481
|
+
# Limit results
|
|
482
|
+
BrainzLab.development_events(limit: 10)
|
|
483
|
+
|
|
484
|
+
# Combine filters
|
|
485
|
+
BrainzLab.development_events(
|
|
486
|
+
service: :recall,
|
|
487
|
+
since: 30.minutes.ago,
|
|
488
|
+
limit: 50
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
# Get stats by service
|
|
492
|
+
BrainzLab.development_stats
|
|
493
|
+
# => { recall: 42, reflex: 3, pulse: 15 }
|
|
494
|
+
|
|
495
|
+
# Clear all stored events
|
|
496
|
+
BrainzLab.clear_development_events!
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Console Output
|
|
500
|
+
|
|
501
|
+
In development mode, events are pretty-printed to stdout:
|
|
502
|
+
|
|
503
|
+
```
|
|
504
|
+
[14:32:15.123] [RECALL] log [INFO] User signed up
|
|
505
|
+
user_id: 123
|
|
506
|
+
data: {email: "user@example.com"}
|
|
507
|
+
|
|
508
|
+
[14:32:16.456] [REFLEX] error RuntimeError: Something went wrong
|
|
509
|
+
error_class: "RuntimeError"
|
|
510
|
+
environment: "development"
|
|
511
|
+
request_id: "abc-123"
|
|
512
|
+
|
|
513
|
+
[14:32:17.789] [PULSE] trace GET /users (45.2ms)
|
|
514
|
+
request_method: "GET"
|
|
515
|
+
request_path: "/users"
|
|
516
|
+
status: 200
|
|
517
|
+
db_ms: 12.3
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Use Cases
|
|
521
|
+
|
|
522
|
+
Development mode is useful for:
|
|
523
|
+
|
|
524
|
+
- **Local development** without setting up a BrainzLab account
|
|
525
|
+
- **Testing** SDK integration in CI/CD pipelines
|
|
526
|
+
- **Debugging** to inspect exactly what events would be sent
|
|
527
|
+
- **Offline development** when working without internet access
|
|
528
|
+
|
|
529
|
+
## Self-Hosted
|
|
530
|
+
|
|
531
|
+
For self-hosted BrainzLab installations:
|
|
532
|
+
|
|
533
|
+
```ruby
|
|
534
|
+
BrainzLab.configure do |config|
|
|
535
|
+
config.recall_url = 'https://recall.your-domain.com'
|
|
536
|
+
config.reflex_url = 'https://reflex.your-domain.com'
|
|
537
|
+
config.pulse_url = 'https://pulse.your-domain.com'
|
|
538
|
+
end
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
## Documentation
|
|
542
|
+
|
|
543
|
+
Full documentation: [docs.brainzlab.ai](https://docs.brainzlab.ai)
|
|
544
|
+
|
|
545
|
+
- [Installation Guide](https://docs.brainzlab.ai/sdk/ruby/installation)
|
|
546
|
+
- [Recall (Logging)](https://docs.brainzlab.ai/sdk/ruby/recall)
|
|
547
|
+
- [Reflex (Errors)](https://docs.brainzlab.ai/sdk/ruby/reflex)
|
|
548
|
+
- [Pulse (APM)](https://docs.brainzlab.ai/sdk/ruby/pulse)
|
|
549
|
+
|
|
550
|
+
## Related
|
|
551
|
+
|
|
552
|
+
- [Recall](https://github.com/brainz-lab/recall) - Logging service
|
|
553
|
+
- [Reflex](https://github.com/brainz-lab/reflex) - Error tracking service
|
|
554
|
+
- [Pulse](https://github.com/brainz-lab/pulse) - APM service
|
|
555
|
+
- [Stack](https://github.com/brainz-lab/stack) - Self-hosted deployment
|
|
556
|
+
|
|
557
|
+
## Contributors
|
|
558
|
+
|
|
559
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
560
|
+
<!-- prettier-ignore-start -->
|
|
561
|
+
<!-- markdownlint-disable -->
|
|
562
|
+
<!-- markdownlint-restore -->
|
|
563
|
+
<!-- prettier-ignore-end -->
|
|
564
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
565
|
+
|
|
566
|
+
Thanks to all our contributors! See [all-contributors](https://allcontributors.org) for how to add yourself.
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
## License
|
|
570
|
+
|
|
571
|
+
OSAaSy License - see [LICENSE](LICENSE) for details.
|