catpm 0.6.2 → 0.6.3
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/lib/catpm/collector.rb +51 -0
- data/lib/catpm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b36a94d20679108a187a682cc578a0b6a90afc6f4c42a0d645ae02c517206ce8
|
|
4
|
+
data.tar.gz: a493544c554ef3bb3fce48a430660f5cebdff7322cbdb553a71a7b573062a442
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c34e1daeb528987a6d90d4343a2f274db4024714891af8ad6a5e568e061b80335c41406cfa6f16e2545a9bc69aab83c7408f658de6c43b2b0aa0fdb5357897d4
|
|
7
|
+
data.tar.gz: 4a954b7676aebe80843f8c56695e4ed73ea9706132c009b0366c2f7c2ccb3f3c826670e12b3ec2c564465464f422f664bf808ded1decabe95b88632fe490cbab
|
data/lib/catpm/collector.rb
CHANGED
|
@@ -45,6 +45,7 @@ module Catpm
|
|
|
45
45
|
|
|
46
46
|
if req_segments
|
|
47
47
|
segments = segment_data[:segments]
|
|
48
|
+
collapse_code_wrappers(segments)
|
|
48
49
|
|
|
49
50
|
# Inject root request segment with full duration
|
|
50
51
|
root_segment = {
|
|
@@ -227,6 +228,7 @@ module Catpm
|
|
|
227
228
|
|
|
228
229
|
if req_segments && segment_data
|
|
229
230
|
segments = segment_data[:segments]
|
|
231
|
+
collapse_code_wrappers(segments)
|
|
230
232
|
|
|
231
233
|
# Inject root request segment
|
|
232
234
|
root_segment = {
|
|
@@ -331,6 +333,55 @@ module Catpm
|
|
|
331
333
|
|
|
332
334
|
private
|
|
333
335
|
|
|
336
|
+
# Remove near-zero-duration "code" spans that merely wrap a "controller" span.
|
|
337
|
+
# This happens when CallTracer (TracePoint) captures a thin dispatch method
|
|
338
|
+
# (e.g. Telegram::WebhookController#process) whose :return fires before the
|
|
339
|
+
# ActiveSupport controller notification finishes.
|
|
340
|
+
# Mutates segments in place: removes the wrapper and re-indexes parent references.
|
|
341
|
+
def collapse_code_wrappers(segments)
|
|
342
|
+
# Identify code spans to collapse: near-zero duration wrapping a controller child
|
|
343
|
+
collapse = {}
|
|
344
|
+
segments.each_with_index do |seg, i|
|
|
345
|
+
next unless seg[:type] == 'code'
|
|
346
|
+
next unless (seg[:duration] || 0).to_f < 1.0
|
|
347
|
+
|
|
348
|
+
has_controller_child = segments.any? { |s| s[:parent_index] == i && s[:type] == 'controller' }
|
|
349
|
+
next unless has_controller_child
|
|
350
|
+
|
|
351
|
+
collapse[i] = seg[:parent_index]
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
return if collapse.empty?
|
|
355
|
+
|
|
356
|
+
# Reparent children of collapsed spans
|
|
357
|
+
segments.each do |seg|
|
|
358
|
+
pi = seg[:parent_index]
|
|
359
|
+
next unless pi && collapse.key?(pi)
|
|
360
|
+
new_parent = collapse[pi]
|
|
361
|
+
if new_parent.nil?
|
|
362
|
+
seg.delete(:parent_index)
|
|
363
|
+
else
|
|
364
|
+
seg[:parent_index] = new_parent
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Build old→new index mapping, remove collapsed spans
|
|
369
|
+
old_to_new = {}
|
|
370
|
+
kept = []
|
|
371
|
+
segments.each_with_index do |seg, i|
|
|
372
|
+
next if collapse.key?(i)
|
|
373
|
+
old_to_new[i] = kept.size
|
|
374
|
+
kept << seg
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# Rewrite parent references to new indices
|
|
378
|
+
kept.each do |seg|
|
|
379
|
+
seg[:parent_index] = old_to_new[seg[:parent_index]] if seg[:parent_index]
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
segments.replace(kept)
|
|
383
|
+
end
|
|
384
|
+
|
|
334
385
|
# Determine sample type at event creation time so only sampled events
|
|
335
386
|
# carry full context in the buffer. Includes filling phase via
|
|
336
387
|
# process-level counter (resets on restart — acceptable approximation).
|
data/lib/catpm/version.rb
CHANGED