chronos-ruby 0.6.0.pre.1 → 0.7.0.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ad7bc09dd58b0476b65687d0b7c695bdc5e82c898f882fc82ed2e87eb352b79
4
- data.tar.gz: 527383d76a4432bc16f48d2a476d7c2398d66f5b891bbe666d1e0ceba9dc9959
3
+ metadata.gz: b9cf448c12955078e3a714df2d41bcd94d89f840fea406dc6595f72661e8abc2
4
+ data.tar.gz: 1401d283792e930caa252b21191de3d8fcc02bf5b2936416ed28eec2e319dab3
5
5
  SHA512:
6
- metadata.gz: 24bf5ed37de64c34a82fd0b98f3e1323cac14c2392fa0d6a01dbcd24d48a69a52100a6127a79b2567314bcf2c464b354fee226ab19bba08ea384bfb3ec8a12f9
7
- data.tar.gz: 1696953512893c9d3eecc23d361b35c5434df7dda25e33a1fe6321b5c25ae4d9e03a2a843bd76e9c327130be2cba2a6c7a9766d70a6f068007b24959aa3cfdc0
6
+ metadata.gz: 43f80510ce3d78e6c9b4b571f7d79cb66b8a4fad8f36b66996ea5cc42868c6ec7b1a05ae1556c8442569787f2f350e2884a779e36af649734eced377396c892b
7
+ data.tar.gz: 30b0f93cfba0ce2fb856b4c65eff6e1ebfa906c8c45ec5c6e287ddc080bc23bd63e4e1a7a4d80a56f40b5001c768719c3b52a2d7e9b08d08b39a2512b476db30
data/CHANGELOG.md CHANGED
@@ -12,6 +12,30 @@ All notable changes are documented here. The project follows Semantic Versioning
12
12
  - legacy CI now resolves Bundler 1.17.3 through `Gem.bin_path` on RubyGems versions that do not support the `_version_` executable selector.
13
13
  - documentation verification now reads source and Markdown files explicitly as UTF-8 on legacy container locales.
14
14
 
15
+ ## [0.7.0.pre.1] - 2026-07-20
16
+
17
+ ### Added
18
+
19
+ - bounded local request, SQL, and job aggregation with count, error rate, duration statistics, histograms, status codes, and component breakdown;
20
+ - `metric_batch` v1 payloads containing at most 50 sanitized metric groups;
21
+ - bounded SQL normalization, fingerprinting, adapter/operation/table/name/cache/role/shard dimensions, and sampled slow-query source;
22
+ - heuristic slow-query, repeated-query, possible N+1, long-transaction, connection-error, and deadlock signals;
23
+ - generic Rack request metrics with Rails/Rack deduplication;
24
+ - APM configuration, diagnostics, contracts, tests, example, benchmark, module documentation, and ADR-015.
25
+
26
+ ### Changed
27
+
28
+ - request, query, and job observations aggregate by default instead of producing one delivery event each;
29
+ - `Chronos.flush` and `Chronos.close` drain APM aggregates before delivery shutdown;
30
+ - version advanced to `0.7.0.pre.1`.
31
+
32
+ ### Known limitations
33
+
34
+ - local signals are heuristic and require server-side confirmation;
35
+ - incomplete trace trackers are cleared when aggregates drain;
36
+ - normalized SQL is defensive rather than a complete dialect parser;
37
+ - external HTTP breakdown remains version 0.8 scope.
38
+
15
39
  ## [0.6.0.pre.1] - 2026-07-20
16
40
 
17
41
  ### Added
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Chronos Ruby
2
2
 
3
- Chronos Ruby is the framework-independent client for sending Ruby application errors and bounded telemetry to Chronos. Version 0.6 starts legacy worker support with Sidekiq 4/5 middleware, cross-process trace context, bounded job telemetry, and exception deduplication on top of the Rails, Rack, privacy, and resilience foundations from earlier releases.
3
+ Chronos Ruby is the framework-independent client for sending Ruby application errors and bounded telemetry to Chronos. Version 0.7 adds bounded essential APM aggregation for requests, SQL, and jobs, including histograms, error rates, component breakdown, normalized SQL fingerprints, and local diagnostic signals.
4
4
 
5
5
  ## What the gem collects
6
6
 
7
- For each exception, version 0.6 can collect:
7
+ For each exception, version 0.7 can collect:
8
8
 
9
9
  - exception class, message, structured backtrace, and chained causes;
10
10
  - timestamp, severity, tags, and an optional fingerprint;
@@ -31,7 +31,7 @@ See [Compatibility](docs/compatibility.md).
31
31
  The current public build is a pre-release. Add its exact version to the application's `Gemfile`:
32
32
 
33
33
  ```ruby
34
- gem "chronos-ruby", "0.6.0.pre.1"
34
+ gem "chronos-ruby", "0.7.0.pre.1"
35
35
  ```
36
36
 
37
37
  Install with a Bundler version compatible with the application. For the oldest supported runtime:
@@ -52,7 +52,7 @@ gem install chronos-ruby --pre
52
52
  Version 0.5 exposes Rails support explicitly, keeping Rails and ActiveSupport out of plain Ruby applications:
53
53
 
54
54
  ```ruby
55
- gem "chronos-ruby", "0.6.0.pre.1", :require => "chronos/rails"
55
+ gem "chronos-ruby", "0.7.0.pre.1", :require => "chronos/rails"
56
56
  ```
57
57
 
58
58
  Generate the initializer with:
@@ -168,7 +168,22 @@ Local exception-specific ignore callbacks are not available in version 0.4. The
168
168
 
169
169
  ## Performance monitoring
170
170
 
171
- Version 0.5 emits bounded `request`, `query`, `job`, and `cache` events from public Rails notifications. SQL text and binds, cache keys and values, job arguments, mail content and recipients, and request or response bodies are never copied. Aggregation, percentiles, query fingerprints, and external HTTP monitoring are not implemented in this version.
171
+ Version 0.7 aggregates request, query, and job observations into bounded `metric_batch` events. Groups include count, error count/rate, total/min/max/average duration, fixed histogram buckets, status counts, and component breakdown. Percentiles are calculated in the SaaS without retaining every local duration.
172
+
173
+ SQL comments and literal values are removed before a bounded normalized query and SHA-256 fingerprint are produced. Binds are never read. Slow, repeated, possible N+1, long-transaction, connection-error, and deadlock signals are heuristic and require server-side confirmation. Group count, active trace count, fingerprints per trace, histogram buckets, and batch size all have fixed limits. See [Essential APM aggregation](docs/modules/apm-aggregation.md).
174
+
175
+ ```ruby
176
+ Chronos.configure do |config|
177
+ # required connection settings omitted
178
+ config.apm_enabled = true
179
+ config.apm_max_groups = 200
180
+ config.apm_flush_count = 100
181
+ config.apm_batch_size = 50
182
+ config.apm_max_queries_per_request = 100
183
+ config.apm_slow_query_threshold_ms = 500.0
184
+ config.apm_n_plus_one_threshold = 5
185
+ end
186
+ ```
172
187
 
173
188
  ## Sidekiq and Active Job
174
189
 
@@ -176,7 +191,7 @@ Version `0.6.0.pre.1` adds optional Sidekiq 4/5 middleware:
176
191
 
177
192
  ```ruby
178
193
  gem "sidekiq", "~> 5.0"
179
- gem "chronos-ruby", "0.6.0.pre.1", :require => "chronos/sidekiq"
194
+ gem "chronos-ruby", "0.7.0.pre.1", :require => "chronos/sidekiq"
180
195
  ```
181
196
 
182
197
  The client middleware propagates only trace/request identifiers in a versioned Sidekiq-envelope field and never changes worker arguments. The server records class, queue, JID, retry count, duration, calculable queue latency, bounded arguments/tags, status, and error class. Values pass through the shared sanitizer before delivery. Failed jobs are notified once and the original exception is re-raised. See [Sidekiq 4/5 legacy integration](docs/modules/sidekiq-legacy.md).
@@ -255,6 +270,9 @@ Chronos.configure do |config|
255
270
  config.context_store = :thread_local
256
271
  config.breadcrumb_capacity = 20
257
272
  config.breadcrumb_max_bytes = 2048
273
+ config.apm_enabled = true
274
+ config.apm_max_groups = 200
275
+ config.apm_flush_count = 100
258
276
  end
259
277
  ```
260
278
 
@@ -266,7 +284,7 @@ Configuration errors are raised during `Chronos.configure`. Capture and delivery
266
284
 
267
285
  ## Benchmark
268
286
 
269
- Run the version 0.6 benchmarks with:
287
+ Run the version 0.7 benchmarks with:
270
288
 
271
289
  ```bash
272
290
  bundle _1.17.3_ exec ruby benchmarks/capture_exception.rb
@@ -277,13 +295,14 @@ bundle _1.17.3_ exec ruby benchmarks/retry_backlog.rb
277
295
  bundle _1.17.3_ exec ruby benchmarks/request_overhead.rb
278
296
  bundle _1.17.3_ exec ruby benchmarks/rails_notifications.rb
279
297
  bundle _1.17.3_ exec ruby benchmarks/sidekiq_middleware.rb
298
+ bundle _1.17.3_ exec ruby benchmarks/apm_aggregation.rb
280
299
  ```
281
300
 
282
301
  Results depend on runtime, hardware, and payload. No performance comparison is claimed until repeatable measurements are published.
283
302
 
284
303
  ## Migration from Airbrake
285
304
 
286
- An Airbrake migration guide will be added before the legacy 1.0 release. Version 0.6 does not claim API compatibility or automatic replacement.
305
+ An Airbrake migration guide will be added before the legacy 1.0 release. Version 0.7 does not claim API compatibility or automatic replacement.
287
306
 
288
307
  ## Local development
289
308
 
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://chronos.example/schemas/apm-batch-v1.schema.json",
4
+ "title": "Chronos APM metric batch payload v1",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["metrics", "dropped_groups"],
8
+ "properties": {
9
+ "dropped_groups": {"type": "integer", "minimum": 0},
10
+ "metrics": {
11
+ "type": "array",
12
+ "minItems": 1,
13
+ "maxItems": 50,
14
+ "items": {
15
+ "type": "object",
16
+ "required": ["metric_type", "dimensions", "count", "error_count", "error_rate", "duration_ms", "histogram", "breakdown_ms", "signals", "status_codes"],
17
+ "properties": {
18
+ "metric_type": {"enum": ["request", "query", "job"]},
19
+ "dimensions": {"type": "object"},
20
+ "count": {"type": "integer", "minimum": 1},
21
+ "error_count": {"type": "integer", "minimum": 0},
22
+ "error_rate": {"type": "number", "minimum": 0, "maximum": 1},
23
+ "duration_ms": {
24
+ "type": "object",
25
+ "required": ["total", "min", "max", "average"]
26
+ },
27
+ "histogram": {"type": "array", "maxItems": 20},
28
+ "breakdown_ms": {"type": "object"},
29
+ "signals": {"type": "object"},
30
+ "status_codes": {"type": "object"}
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
@@ -20,7 +20,7 @@
20
20
  "properties": {
21
21
  "schema_version": {"const": "1.0"},
22
22
  "event_id": {"type": "string", "minLength": 1},
23
- "event_type": {"enum": ["exception", "request", "query", "job", "cache"]},
23
+ "event_type": {"enum": ["exception", "request", "query", "job", "cache", "metric_batch"]},
24
24
  "occurred_at": {"type": "string"},
25
25
  "sent_at": {"type": "string"},
26
26
  "project_key": {"type": "string", "minLength": 1},
@@ -0,0 +1,27 @@
1
+ # ADR-015 — Bounded local APM aggregation
2
+
3
+ ## Status
4
+
5
+ Accepted for version 0.7.
6
+
7
+ ## Context
8
+
9
+ Sending every request, SQL query, and job as an independent event increases network overhead. Retaining every observation for client-side percentiles or unbounded N+1 analysis would transfer that cost to application memory.
10
+
11
+ ## Decision
12
+
13
+ Aggregate request, query, and job observations by bounded low-cardinality dimensions. Store only counters, error counters, duration sum/min/max, fixed histogram buckets, component totals, status counters, and heuristic signal counters. Calculate averages locally and percentiles in the SaaS.
14
+
15
+ Use a fixed group limit, fixed query-fingerprint limit per trace, fixed batch size, and no new timer thread. Drain on observation threshold, explicit flush, and close. Clear incomplete trace trackers during drain. Normalize SQL comments and literal values before fingerprinting and never read binds. Use a `metric_batch` event through the existing sanitization, queue, retry, circuit breaker, and backlog pipeline.
16
+
17
+ ## Alternatives
18
+
19
+ One event per observation was rejected as the default because delivery overhead scales directly with traffic. Retaining raw duration arrays was rejected because memory would scale with traffic. Client-side percentiles, SQL parsing dependencies, and background flush threads were rejected for the legacy line. Full SQL and bind capture was rejected for privacy and cardinality.
20
+
21
+ ## Positive consequences
22
+
23
+ Delivery volume is reduced, memory remains bounded, request breakdown is available, SQL values are excluded, and the SaaS receives stable histograms suitable for percentile calculation.
24
+
25
+ ## Negative consequences
26
+
27
+ Process crashes can lose undrained aggregates, incomplete trackers are discarded on drain, local signals are heuristic, and a defensive SQL normalizer cannot understand every database dialect.
data/docs/architecture.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Architecture
2
2
 
3
- Chronos Ruby 0.6 uses hexagonal boundaries so the legacy core remains independent of frameworks and delivery infrastructure.
3
+ Chronos Ruby 0.7 uses hexagonal boundaries so the legacy core remains independent of frameworks and delivery infrastructure.
4
4
 
5
5
  ```mermaid
6
6
  flowchart TB
@@ -19,6 +19,8 @@ flowchart TB
19
19
  Sidekiq[Integrations / Sidekiq client and server middleware] --> Facade
20
20
  Sidekiq --> Envelope[Versioned job-envelope context]
21
21
  Application --> Telemetry[Core / TelemetryEvent]
22
+ Telemetry --> APM[Application / ApmAggregator]
23
+ APM --> Metrics[Core / MetricAggregate and SqlNormalizer]
22
24
  ```
23
25
 
24
26
  ## Boundaries
@@ -44,7 +46,9 @@ An exception becomes an immutable notice. `Sanitizer` removes sensitive values b
44
46
 
45
47
  Rails timings become immutable `TelemetryEvent` values. `CaptureTelemetry` applies the remote/local event policy, `TelemetrySerializer` sanitizes the allowlisted payload, and the resulting `SerializedEvent` enters the same delivery pipeline. Rails classes are loaded only through `chronos/rails`; the core never requires Rails or ActiveSupport.
46
48
 
47
- Sidekiq client middleware writes a versioned, allowlisted trace/request context beside the job's public arguments. Server middleware restores a job scope, limits arguments and tags, emits one job telemetry event, and routes a failure through the existing notice pipeline before re-raising it. Sidekiq retains queue, retry, thread, and connection lifecycle ownership.
49
+ Sidekiq client middleware writes a versioned, allowlisted trace/request context beside the job's public arguments. Server middleware restores a job scope, limits arguments and tags, emits a job observation, and routes a failure through the existing notice pipeline before re-raising it. Sidekiq retains queue, retry, thread, and connection lifecycle ownership.
50
+
51
+ Version 0.7 routes request, query, and job observations through `ApmAggregator`. `SqlNormalizer` removes values before grouping, while `MetricAggregate` owns fixed numerical statistics. Aggregates and per-trace query trackers are bounded and mutex-protected. Threshold or lifecycle drains create `metric_batch` telemetry that passes through the existing sanitizer and delivery pipeline. No APM-specific thread is created.
48
52
 
49
53
  ## Failure policy
50
54
 
@@ -19,6 +19,8 @@ Version 0.5 includes Rails 4.2 and 5.2 applications plus a dedicated matrix, but
19
19
 
20
20
  Version `0.6.0.pre.1` uses the public Sidekiq 4/5 middleware signatures and remains `Best effort` until dedicated jobs exercise both real gem versions across their valid Ruby combinations.
21
21
 
22
+ Version `0.7.0.pre.1` keeps the same Ruby/Rails matrix and implements APM aggregation without modern concurrency or SQL-parser dependencies. Its compatibility remains `Best effort` until request/SQL/job aggregate payloads pass the dedicated fake-server gates for every listed runtime.
23
+
22
24
  Status meanings:
23
25
 
24
26
  - Supported: the complete required compatibility gate passes.
@@ -39,7 +39,7 @@
39
39
  | `remote_configuration` | Optional | `true` | Accepts only the documented bounded remote policy fields |
40
40
  | `remote_config_max_bytes` | Optional | `4096` | Maximum remote policy response-header bytes |
41
41
  | `sampling_rate` | Optional | `1.0` | Local upper bound for event sampling |
42
- | `enabled_event_types` | Optional | exception, request, query, job, cache | Local allowlist for supported event envelopes |
42
+ | `enabled_event_types` | Optional | exception, request, query, job, cache, metric_batch | Local allowlist for supported event envelopes |
43
43
  | `max_remote_send_interval` | Optional | `60.0` | Local upper bound for remotely requested send spacing |
44
44
  | `context_store` | Optional | `:thread_local` | `:thread_local` or an object implementing `get`, `set`, `clear`, and `with_context` |
45
45
  | `breadcrumb_capacity` | Optional | `20` | Positive count of newest breadcrumbs retained per execution |
@@ -48,6 +48,15 @@
48
48
  | `rails_capture_in_console` | Optional | `false` | Enables automatic integration while Rails console is loaded |
49
49
  | `rails_capture_in_test` | Optional | `false` | Enables automatic integration in the Rails test environment |
50
50
  | `rails_capture_user_agent` | Optional | `false` | Adds the Rack user agent to request context |
51
+ | `apm_enabled` | Optional | `true` | Aggregates request, query, and job observations into bounded metric batches |
52
+ | `apm_max_groups` | Optional | `200` | Maximum metric groups and active trace trackers retained locally |
53
+ | `apm_flush_count` | Optional | `100` | Aggregate observations accepted before a threshold drain |
54
+ | `apm_batch_size` | Optional | `50` | Metric groups per batch; hard maximum 50 |
55
+ | `apm_max_queries_per_request` | Optional | `100` | Query fingerprints tracked per trace for repetition signals |
56
+ | `apm_slow_query_threshold_ms` | Optional | `500.0` | Query duration that produces a slow-query signal and sampled source |
57
+ | `apm_long_transaction_threshold_ms` | Optional | `1000.0` | Transaction-labelled SQL duration that produces a signal |
58
+ | `apm_n_plus_one_threshold` | Optional | `5` | Repeated fingerprint count producing one possible-N+1 signal; minimum 2 |
59
+ | `apm_histogram_buckets` | Optional | Fixed millisecond boundaries | Increasing positive duration boundaries; at most 19 plus `+Inf` |
51
60
 
52
61
  ```ruby
53
62
  Chronos.configure do |config|
@@ -67,6 +76,14 @@ Chronos.configure do |config|
67
76
  config.breadcrumb_capacity = 20
68
77
  config.rails_capture_in_test = false
69
78
  config.rails_capture_in_console = false
79
+ config.apm_enabled = true
80
+ config.apm_max_groups = 200
81
+ config.apm_flush_count = 100
82
+ config.apm_batch_size = 50
83
+ config.apm_max_queries_per_request = 100
84
+ config.apm_slow_query_threshold_ms = 500.0
85
+ config.apm_long_transaction_threshold_ms = 1000.0
86
+ config.apm_n_plus_one_threshold = 5
70
87
  end
71
88
  ```
72
89
 
@@ -1,6 +1,6 @@
1
1
  # Data collected
2
2
 
3
- Version 0.6 emits exception, request, query, job, and cache events. All fields pass through the privacy sanitizer and bounded safe serializer before queueing, retry storage, or delivery.
3
+ Version 0.7 emits exceptions, individual cache telemetry, and aggregated request/query/job metric batches. All fields pass through the privacy sanitizer and bounded safe serializer before queueing, retry storage, or delivery.
4
4
 
5
5
  | Data | Default | Source |
6
6
  |---|---|---|
@@ -32,10 +32,19 @@ Version 0.6 emits exception, request, query, job, and cache events. All fields p
32
32
  | Sidekiq arguments | Collected, sanitized, and bounded | First 20 job arguments; collections/depth/strings limited |
33
33
  | Sidekiq tags | Collected and bounded | Job payload or public worker options |
34
34
  | Sidekiq trace/request IDs | Propagated when present; trace generated otherwise | Chronos job-envelope metadata |
35
+ | APM counts, error counts/rates, duration total/min/max/average | Aggregated by default | Request, query, and job observations |
36
+ | Fixed duration histogram and status counts | Aggregated by default | Local bounded counters |
37
+ | Component breakdown | database/view/cache/queue/application when observable | Trace-local bounded totals |
38
+ | Normalized SQL and SHA-256 fingerprint | Collected without comments, literals, or binds | `sql.active_record` payload |
39
+ | SQL adapter, operation, inferred table, AR name, cache flag, role/shard | Collected when exposed | Public notification payload and connection feature detection |
40
+ | Slow SQL source frame | Collected only for threshold-selected slow queries | Bounded application call frame |
41
+ | APM diagnostic signals | Heuristic counters | Local threshold and repetition detection |
35
42
  | Cache operation, store, hit flag, duration | Collected; key/value omitted | ActiveSupport cache notifications |
36
43
 
37
44
  The gem never collects request bodies, response bodies, raw query strings, cookies, HTTP authorization headers, environment variables in bulk, source code, raw SQL, SQL bind values, database rows, cache keys/values, mail bodies/recipients, or installed gems. Sidekiq JIDs and bounded arguments are the explicit version 0.6 exception to the earlier job-ID/argument exclusion.
38
45
 
46
+ APM dimensions never include user ID, job ID, raw URL, exception message, bind value, or cache key. Normalized routes replace common numeric/UUID segments. Normalized SQL can retain schema, table, and column identifiers; review those identifiers as part of the privacy audit.
47
+
39
48
  The secret `project_key` is an authentication header and is excluded from the JSON payload and logger diagnostics. The envelope field named `project_key` contains the public `project_id` required by the current v1 server contract.
40
49
 
41
50
  See [Privacy and LGPD](privacy-lgpd.md) for redaction rules and the payload audit procedure.
@@ -0,0 +1,57 @@
1
+ # Essential APM aggregation
2
+
3
+ Version `0.7.0.pre.1` aggregates request, SQL, and job observations locally before delivery. The agent emits versioned `metric_batch` envelopes containing at most 50 metric groups instead of one event per observation. Aggregates drain when `apm_flush_count` observations are reached and whenever `Chronos.flush` or `Chronos.close` runs. No timer or additional APM thread is created.
4
+
5
+ ## Request metrics
6
+
7
+ Request groups use normalized route and HTTP method. Status codes are counted inside the group so error rate can be calculated without making status part of an unbounded key. Each metric contains count, error count/rate, total, minimum, maximum, average, fixed histogram buckets, and component breakdown. Percentiles remain server-side because retaining every duration locally would violate the memory boundary.
8
+
9
+ Rack records request metrics for non-Rails applications. Rails controller notifications and Rack share `record_event_once`, so the same request is counted only once. Controller notification data wins when available because its route is more precise.
10
+
11
+ ## SQL metrics and signals
12
+
13
+ `Chronos::Core::SqlNormalizer` removes block/line comments, quoted literal values, numeric values, booleans, nulls, and repeated `IN` values before producing a SHA-256 fingerprint. Binds are never read. Query dimensions can contain adapter, operation, inferred table, bounded normalized query, fingerprint, Active Record operation name, cache flag, connection role/shard, and a bounded source frame for slow sampled queries.
14
+
15
+ Local signals are intentionally heuristic:
16
+
17
+ - `slow_query` when duration reaches `apm_slow_query_threshold_ms`;
18
+ - `repeated_query` after the same fingerprint appears again in one trace;
19
+ - `possible_n_plus_one` once when the configured repetition threshold is reached;
20
+ - `long_transaction` for transaction-labelled SQL over its threshold;
21
+ - `connection_error` and `deadlock` from bounded exception class names.
22
+
23
+ The SaaS must confirm and correlate these signals. They are not proof of an N+1, deadlock, or application defect.
24
+
25
+ ## Bounded state
26
+
27
+ - at most `apm_max_groups` metric groups;
28
+ - at most `apm_max_groups` active trace trackers;
29
+ - at most `apm_max_queries_per_request` fingerprints per trace;
30
+ - at most 19 configured histogram boundaries plus `+Inf`;
31
+ - at most `apm_batch_size` groups per payload, with a hard maximum of 50;
32
+ - trackers are removed when their request completes and all remaining trackers are cleared on aggregate drain.
33
+
34
+ New groups beyond capacity are dropped and counted in `dropped_groups`. Existing groups continue accumulating. The state is process-local and is lost on restart.
35
+
36
+ ## Breakdown
37
+
38
+ The contract supports `database`, `view`, `external_http`, `cache`, `queue`, `application`, and `unknown`. Version 0.7 fills database/view/cache within a traced request, queue/application for jobs, and residual application time for requests. External HTTP instrumentation begins in version 0.8.
39
+
40
+ ## Configuration
41
+
42
+ ```ruby
43
+ Chronos.configure do |config|
44
+ # connection settings omitted
45
+ config.apm_enabled = true
46
+ config.apm_max_groups = 200
47
+ config.apm_flush_count = 100
48
+ config.apm_batch_size = 50
49
+ config.apm_max_queries_per_request = 100
50
+ config.apm_slow_query_threshold_ms = 500.0
51
+ config.apm_long_transaction_threshold_ms = 1000.0
52
+ config.apm_n_plus_one_threshold = 5
53
+ config.apm_histogram_buckets = [5.0, 10.0, 25.0, 50.0, 100.0, 250.0, 500.0, 1000.0]
54
+ end
55
+ ```
56
+
57
+ Setting `apm_enabled = false` restores individual request/query/job telemetry for compatibility diagnostics. Cache events remain individual in 0.7 while also contributing to an existing request breakdown.
@@ -7,3 +7,5 @@ This module is separate from capture because configuration errors should be foun
7
7
  Risks include accidentally logging credentials and changing settings while events run. The snapshot prevents mutation, while logger and transport code never interpolate `project_key`.
8
8
 
9
9
  Tests in `spec/unit/configuration_spec.rb` verify required fields, HTTPS defaults, immutable containers, disabled operation, and bounded numeric settings.
10
+
11
+ Version 0.7 adds bounded APM capacities, thresholds, and histogram boundaries. Invalid zero/negative capacities, batches above 50, N+1 thresholds below two, and non-increasing histogram boundaries are rejected before agent construction. See [Essential APM aggregation](apm-aggregation.md).
@@ -57,4 +57,4 @@ The repository contains independent applications under `examples/rails-4.2` and
57
57
 
58
58
  ## Limits
59
59
 
60
- Version 0.5 emits individual bounded timings. It does not aggregate APM metrics, capture SQL text, or calculate query fingerprints. Sidekiq support is a separate optional integration beginning in version 0.6; full Active Job propagation remains a later 0.6 increment.
60
+ Version 0.7 aggregates controller, SQL, and job timings into bounded APM batches. SQL literals and binds remain excluded while a bounded normalized query and fingerprint are produced. Sidekiq support remains a separate optional integration; full Active Job propagation remains a later legacy increment.
@@ -4,7 +4,7 @@ Version `0.6.0.pre.1` starts the legacy jobs line with optional Sidekiq 4 and 5
4
4
 
5
5
  ```ruby
6
6
  gem "sidekiq", "~> 5.0"
7
- gem "chronos-ruby", "0.6.0.pre.1", :require => "chronos/sidekiq"
7
+ gem "chronos-ruby", "0.7.0.pre.1", :require => "chronos/sidekiq"
8
8
  ```
9
9
 
10
10
  `chronos/sidekiq` installs middleware through the public `configure_client` and `configure_server` APIs. It does nothing when Sidekiq is unavailable, and the core gem never requires Sidekiq. Installation adds no Chronos thread or Redis/database connection per job; delivery continues through the agent's existing fixed worker pool.
@@ -13,7 +13,7 @@ The client middleware adds a top-level `chronos` metadata object to the Sidekiq
13
13
 
14
14
  Collected Sidekiq fields are worker class, queue, JID, retry count, duration, queue latency, status, error class, bounded tags, and bounded arguments. At most 20 top-level arguments, 20 values per nested collection, four levels, and 512 bytes per string are traversed. Arguments then pass through the standard sensitive-key/content sanitizer before queueing. Limits reduce exposure and resource use but do not make unnecessary personal data safe to collect.
15
15
 
16
- On failure, the server middleware records failed-job telemetry, invokes `notify_once`, and re-raises the identical exception so Sidekiq retains ownership of retries and failure handlers. A shared execution marker prevents a nested Active Job hook and the Sidekiq middleware from sending the same exception twice. Chronos does not install an additional global Sidekiq error handler.
16
+ On failure, the server middleware records a failed-job observation, invokes `notify_once`, and re-raises the identical exception so Sidekiq retains ownership of retries and failure handlers. A shared execution marker prevents a nested Active Job hook and the Sidekiq middleware from sending the same exception twice. Version 0.7 aggregates the job observation; the exception retains sanitized bounded arguments. Chronos does not install an additional global Sidekiq error handler.
17
17
 
18
18
  Known limitations for this first 0.6 prerelease:
19
19
 
@@ -6,4 +6,4 @@ Telemetry has the same `schema_version`, event ID, timestamps, project, environm
6
6
 
7
7
  `Chronos.record_event` is the narrow integration entry point. Application code should prefer documented higher-level APIs; its payload is allowlisted by each bundled integration and then sanitized. Remote configuration can reduce or disable any locally enabled telemetry type but cannot enable a type excluded by local configuration.
8
8
 
9
- Version 0.5 intentionally sends individual framework events. Aggregation, percentiles, slow-query analysis, and transaction breakdowns remain part of version 0.7.
9
+ Version 0.7 aggregates request, query, and job observations into `metric_batch` events by default. Cache remains an individual event while contributing to an existing traced request breakdown. Set `apm_enabled = false` only when individual legacy telemetry is required for diagnostics. Percentiles remain server-side; see [Essential APM aggregation](apm-aggregation.md).
data/docs/performance.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Performance
2
2
 
3
- Performance is a functional requirement, but version 0.6 makes no unverified speed claim.
3
+ Performance is a functional requirement, but version 0.7 makes no unverified speed claim.
4
4
 
5
5
  Current controls:
6
6
 
@@ -20,6 +20,7 @@ Current controls:
20
20
  - Rack middleware never consumes request or response bodies.
21
21
  - Rails subscribers copy only small allowlisted field sets and never copy raw SQL or job arguments.
22
22
  - Sidekiq middleware creates no per-job thread or connection and bounds arguments, collections, nesting, strings, and tags before telemetry capture.
23
+ - APM group, trace, query-fingerprint, histogram, and batch counts are fixed; no APM timer thread is created.
23
24
 
24
25
  Run the scripts under `benchmarks/` and record Ruby version, operating system, CPU, warmup, iteration count, median, and dispersion before publishing results. `benchmarks/filtering.rb` measures privacy filtering, `benchmarks/retry_backlog.rb` measures fixed-memory outage behavior, `benchmarks/request_overhead.rb` compares Rack-protocol calls, and `benchmarks/rails_notifications.rb` isolates subscriber normalization overhead.
25
26
 
@@ -87,3 +88,15 @@ ITERATIONS=100000 bundle _1.17.3_ exec ruby benchmarks/sidekiq_middleware.rb
87
88
  ```
88
89
 
89
90
  The benchmark executes client context injection and successful server normalization with a no-op notifier. It includes bounded argument handling and clock reads, but excludes Sidekiq/Redis, serialization, queueing, and network delivery. Record a controlled result before making a performance claim.
91
+
92
+ ## Version 0.7 APM aggregation benchmark
93
+
94
+ Run:
95
+
96
+ ```bash
97
+ ITERATIONS=100000 bundle _1.17.3_ exec ruby benchmarks/apm_aggregation.rb
98
+ ```
99
+
100
+ The fixture repeatedly updates one SQL metric group and one trace-local fingerprint. It excludes ActiveSupport dispatch, serialization, queueing, and network delivery. The benchmark must report one retained group; memory must remain bounded by configuration. Record runtime, hardware, warmup, median, and dispersion before publishing a performance claim.
101
+
102
+ A local diagnostic run on 2026-07-20 used Ruby 2.2.10 on macOS arm64 and 10,000 observations. It retained one group and measured approximately 34.972 microseconds per observation. This single run has no controlled warmup, median, or dispersion and is not a production performance claim.
data/docs/privacy-lgpd.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Privacy and LGPD
2
2
 
3
- Version 0.6 sanitizes exception and framework telemetry before JSON serialization, queueing, retry backlog, or transport. This reduces accidental exposure, but the host application remains responsible for lawful purpose, minimization, access control, retention, and responses to data-subject requests.
3
+ Version 0.7 sanitizes exception, framework telemetry, and APM metric batches before JSON serialization, queueing, retry backlog, or transport. This reduces accidental exposure, but the host application remains responsible for lawful purpose, minimization, access control, retention, and responses to data-subject requests.
4
4
 
5
5
  ## Default policy
6
6
 
@@ -15,8 +15,9 @@ Version 0.6 sanitizes exception and framework telemetry before JSON serializatio
15
15
  | Unknown Ruby objects | Represented by class name without calling application serialization |
16
16
  | Request/response bodies, raw query strings, cookies, authorization headers, raw SQL/binds, cache values, mail bodies, environment variables | Never collected automatically |
17
17
  | Sidekiq arguments | Collected automatically, limited before sanitization, then redacted by the common policy |
18
+ | SQL | Comments, quoted/numeric/boolean/null literals removed; binds never read; bounded identifiers remain |
18
19
 
19
- The retry backlog exists only in process memory, accepts only `SerializedEvent`, has a fixed capacity, and disappears on process exit. Version 0.6 does not persist telemetry to disk.
20
+ The retry backlog exists only in process memory, accepts only `SerializedEvent`, has a fixed capacity, and disappears on process exit. Version 0.7 does not persist telemetry to disk.
20
21
 
21
22
  ## Rails telemetry
22
23
 
@@ -26,6 +27,10 @@ Rails subscribers use per-notification allowlists. SQL events retain only the op
26
27
 
27
28
  The optional Sidekiq middleware is the only version 0.6 integration that automatically reads job arguments. It traverses at most 20 top-level arguments, 20 items per nested collection, four levels, and 512 bytes per string. These structural limits run before the common key and content sanitizer. Trace propagation contains only trace and request identifiers. Do not place credentials or unnecessary personal, health, or financial data in job arguments; configure application-specific blocklist keys and audit representative synthetic payloads before enabling production delivery.
28
29
 
30
+ ## APM dimensions
31
+
32
+ Metric groups deliberately exclude user IDs, JIDs, raw URLs, request parameters, bind values, exception messages, and cache keys. SQL normalization removes common literal forms and comments before fingerprinting, but retains bounded database identifiers and cannot parse every dialect. Do not encode personal or secret values in schema, table, column, SQL keyword, or operation names. Slow-query source contains a bounded file/line frame under the configured application root, not source-code contents.
33
+
29
34
  ## Rack context and breadcrumbs
30
35
 
31
36
  The Rack middleware copies only bounded operational fields and parameter hashes that another component already parsed. It does not read `rack.input` or copy `QUERY_STRING`. User context is opt-in through `chronos.user`, and user agent collection is disabled unless the middleware option enables it.
@@ -32,6 +32,18 @@ Require `chronos/sidekiq` after Sidekiq is available and configure Chronos befor
32
32
 
33
33
  The bundled middleware does not install a global error handler and uses `notify_once` inside a shared job scope. Check for application-installed Chronos calls or third-party global handlers outside that scope. Keep a single bundled server middleware entry in the Sidekiq chain.
34
34
 
35
+ ## Request, query, or job events are not sent immediately
36
+
37
+ This is expected with version 0.7 APM aggregation. Groups drain after `apm_flush_count` observations or during `Chronos.flush`/`Chronos.close`. Inspect `agent.diagnostics[:apm]` when using an explicit agent. Set `apm_enabled = false` only for temporary individual-event diagnostics.
38
+
39
+ ## Query metrics contain no literal values or binds
40
+
41
+ This is intentional. The normalizer removes common literal forms and never reads binds. Queries differing only by values should share a fingerprint. If an unsupported database dialect leaves a sensitive literal form, stop delivery, add a synthetic privacy fixture, and report the dialect through the security/support process.
42
+
43
+ ## Possible N+1 or deadlock signal is inaccurate
44
+
45
+ Local detectors emit bounded heuristics, not confirmed diagnoses. Repetition can be legitimate and exception class names can be adapter-specific. Confirm the trace in the SaaS and application logs before changing application behavior.
46
+
35
47
  ## Context appears missing
36
48
 
37
49
  The legacy context store is thread-local. A new application-created thread does not inherit context. Establish a new `Chronos.with_context` scope inside that thread, and issue manual notification before the scope exits. For Rack capture, supply user and explicit parameters through the documented environment keys.
data/lib/chronos/agent.rb CHANGED
@@ -67,6 +67,26 @@ module Chronos
67
67
  @telemetry.call(event_type, payload, telemetry_context(context))
68
68
  end
69
69
 
70
+ def record_event_once(key, event_type, payload = {}, context = {})
71
+ execution = @context_store.get
72
+ captured = execution[:__chronos_captured_events] || {}
73
+ return false if captured[key.to_s]
74
+
75
+ captured[key.to_s] = true
76
+ @context_store.set(execution.merge(:__chronos_captured_events => captured))
77
+ record_event(event_type, payload, context)
78
+ rescue StandardError
79
+ false
80
+ end
81
+
82
+ def apm_integration_options
83
+ {
84
+ :enabled => @config.apm_enabled,
85
+ :slow_query_threshold_ms => @config.apm_slow_query_threshold_ms,
86
+ :root_directory => @config.root_directory
87
+ }
88
+ end
89
+
70
90
  # Returns the correlation subset safe for an integration-owned process boundary.
71
91
  def propagation_context
72
92
  current = context_hash(@context_store.get)
@@ -104,6 +124,7 @@ module Chronos
104
124
  end
105
125
 
106
126
  def flush(timeout = DEFAULT_FLUSH_TIMEOUT)
127
+ @telemetry.flush
107
128
  @delivery_pipeline.flush(timeout)
108
129
  rescue StandardError => error
109
130
  @logger.warn("Chronos flush failed: #{error.class}")
@@ -111,6 +132,7 @@ module Chronos
111
132
  end
112
133
 
113
134
  def close(timeout = DEFAULT_FLUSH_TIMEOUT)
135
+ @telemetry.flush
114
136
  @delivery_pipeline.close(timeout)
115
137
  rescue StandardError => error
116
138
  @logger.warn("Chronos close failed: #{error.class}")
@@ -119,6 +141,7 @@ module Chronos
119
141
 
120
142
  def diagnostics
121
143
  details = @delivery_pipeline.diagnostics
144
+ details[:apm] = @telemetry.diagnostics
122
145
  details[:queue].merge(details)
123
146
  end
124
147
 
@@ -139,6 +162,8 @@ module Chronos
139
162
  merged = deep_merge(context_hash(@context_store.get), context_hash(additional))
140
163
  merged.delete(:__chronos_captured_exceptions)
141
164
  merged.delete("__chronos_captured_exceptions")
165
+ merged.delete(:__chronos_captured_events)
166
+ merged.delete("__chronos_captured_events")
142
167
  buffer = merged.delete(:__chronos_breadcrumbs) || merged.delete("__chronos_breadcrumbs")
143
168
  if buffer.respond_to?(:to_a)
144
169
  merged[:context] = context_hash(merged[:context]).merge("breadcrumbs" => buffer.to_a)