sinaliza 0.2.0 → 0.3.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 +4 -4
- data/README.md +73 -2
- data/app/assets/stylesheets/sinaliza/application.css +578 -56
- data/app/controllers/sinaliza/interceptors_controller.rb +62 -0
- data/app/models/sinaliza/interceptor.rb +61 -0
- data/app/views/layouts/sinaliza/application.html.erb +13 -2
- data/app/views/sinaliza/events/index.html.erb +26 -5
- data/app/views/sinaliza/events/show.html.erb +46 -10
- data/app/views/sinaliza/interceptors/_form.html.erb +42 -0
- data/app/views/sinaliza/interceptors/edit.html.erb +7 -0
- data/app/views/sinaliza/interceptors/index.html.erb +57 -0
- data/app/views/sinaliza/interceptors/new.html.erb +7 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20260314000000_create_sinaliza_interceptors.rb +20 -0
- data/lib/sinaliza/engine.rb +23 -0
- data/lib/sinaliza/interceptor_registry.rb +109 -0
- data/lib/sinaliza/version.rb +1 -1
- data/lib/sinaliza.rb +12 -0
- metadata +10 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d645f68aef485dbc199b994b47c4f3434e89cb9101615d4b2806d0203033a340
|
|
4
|
+
data.tar.gz: 428eed5415abc8bf3f7866e6e4903162e417c0b6eceee8e7a4e233bc7374fdaa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d03113b99053374a9b758acc715ed5f370aa7a3bef568d782c5abfaf7b109b7255d3f0586c26fd74d436635bb74132d03d3d9fa525897e739bce8a0be0b5acc5
|
|
7
|
+
data.tar.gz: 5ff4559f655c0e3182f0d7ad4170326bae7cae2b8736f70318bd84f8331dacbf8bdda8616743d2c632ebc0c2c734d203e2a89997c5104bbea151b66d22338938
|
data/README.md
CHANGED
|
@@ -154,6 +154,61 @@ Events are recorded with `source: "controller"`. Request context (IP address, us
|
|
|
154
154
|
|
|
155
155
|
The actor is resolved by calling the method defined in `Sinaliza.configuration.actor_method` (default: `current_user`).
|
|
156
156
|
|
|
157
|
+
### Interceptors
|
|
158
|
+
|
|
159
|
+
Interceptors let you automatically record events whenever a specific method is called — without modifying the original code. They are stored in the database and can be managed at runtime through the dashboard or programmatically.
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
# Create an interceptor that tracks every call to User#send_welcome_email
|
|
163
|
+
Sinaliza::Interceptor.create!(
|
|
164
|
+
target_class: "User",
|
|
165
|
+
method_name: "send_welcome_email",
|
|
166
|
+
method_type: "instance",
|
|
167
|
+
event_name: "user.welcome_email_sent"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Track a class method
|
|
171
|
+
Sinaliza::Interceptor.create!(
|
|
172
|
+
target_class: "Report",
|
|
173
|
+
method_name: "generate_monthly",
|
|
174
|
+
method_type: "class",
|
|
175
|
+
event_name: "report.monthly_generated"
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Each interceptor can optionally capture:
|
|
180
|
+
|
|
181
|
+
| Option | Description | Default |
|
|
182
|
+
|--------------------------|------------------------------------------|---------|
|
|
183
|
+
| `capture_args` | Log method arguments in metadata | `false` |
|
|
184
|
+
| `capture_return` | Log the return value in metadata | `false` |
|
|
185
|
+
| `capture_execution_time` | Log execution time (ms) in metadata | `false` |
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
# Interceptor with full instrumentation
|
|
189
|
+
Sinaliza::Interceptor.create!(
|
|
190
|
+
target_class: "PaymentGateway",
|
|
191
|
+
method_name: "charge",
|
|
192
|
+
method_type: "instance",
|
|
193
|
+
event_name: "payment.charged",
|
|
194
|
+
capture_args: true,
|
|
195
|
+
capture_return: true,
|
|
196
|
+
capture_execution_time: true
|
|
197
|
+
)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Interceptors can be toggled on and off without removing them:
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
interceptor = Sinaliza::Interceptor.find_by(event_name: "user.welcome_email_sent")
|
|
204
|
+
interceptor.deactivate! # stops recording events
|
|
205
|
+
interceptor.activate! # resumes recording events
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Events recorded by interceptors have `source: "interceptor"`.
|
|
209
|
+
|
|
210
|
+
The dashboard includes an **Interceptors** section where you can create, edit, toggle, and delete interceptors through a web interface.
|
|
211
|
+
|
|
157
212
|
### Query scopes
|
|
158
213
|
|
|
159
214
|
```ruby
|
|
@@ -188,15 +243,31 @@ The engine mounts a monitor dashboard at your chosen path. It provides:
|
|
|
188
243
|
|
|
189
244
|
### Protecting the dashboard
|
|
190
245
|
|
|
191
|
-
The gem does not include authentication. Protect access via route constraints in your host app
|
|
246
|
+
The gem does not include authentication. Protect access via route constraints in your host app.
|
|
247
|
+
|
|
248
|
+
**With Devise:**
|
|
192
249
|
|
|
193
250
|
```ruby
|
|
194
251
|
# config/routes.rb
|
|
195
252
|
authenticate :user, ->(u) { u.admin? } do
|
|
196
253
|
mount Sinaliza::Engine => "/sinaliza"
|
|
197
254
|
end
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Without Devise:**
|
|
258
|
+
|
|
259
|
+
```ruby
|
|
260
|
+
# app/constraints/admin_constraint.rb
|
|
261
|
+
class AdminConstraint
|
|
262
|
+
def matches?(request)
|
|
263
|
+
user_id = request.session[:user_id]
|
|
264
|
+
return false unless user_id
|
|
265
|
+
|
|
266
|
+
User.find_by(id: user_id)&.admin?
|
|
267
|
+
end
|
|
268
|
+
end
|
|
198
269
|
|
|
199
|
-
#
|
|
270
|
+
# config/routes.rb
|
|
200
271
|
mount Sinaliza::Engine => "/sinaliza", constraints: AdminConstraint.new
|
|
201
272
|
```
|
|
202
273
|
|