puma_metrics_engine 1.2.0 → 1.2.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: 1ab335fa7843d45934fd97c5442b9bfd3a87006066b6f14ef99123a9316ab165
4
- data.tar.gz: 7bd9134d5a436aecebd2a3f2a4073a5b51c46f3fb3d4a8b2391464e108326503
3
+ metadata.gz: 32e8e883e66e79ca9d1ed80ee21f5b0b880241f0157e325b21c7b679d9ffa56f
4
+ data.tar.gz: de06e4bed7924f401382ad5e852936cc16bbb699e7c98569957d8a7dae203cf9
5
5
  SHA512:
6
- metadata.gz: c9f71532254eed460c8169a894c41e0ac03c7a089c37a133fc097d7632a0ab2bd2e282bbe84b7cd3ea667ea1adfa9f5a9cb3afc4aaaeb8d470107e5f403ab016
7
- data.tar.gz: b704e4c376bdbdad8324b004c71ed20d176dbdda1febaaa63c6c411da33beee40cdb98460671dd8c558feb085a491602f2babc220d3ede42f2d77e90594b00d7
6
+ metadata.gz: d51049bfb157f4641cf41499ddd3c1769f7ffa8e13b0dba731124e748cfa2b80cfefb445ca7ecdc1fe06ba00aa31a137f7bc7978d84f962cb4ac413515a5bb7f
7
+ data.tar.gz: d2d192c9ceda0d7eed4de38ec1a2cce70f36d468cf3dc9de345cb7b3929fd4cd93df1b8fbda1d7deeb11546af6dea4cf0910291238ccb98393d9227572065599
@@ -57,7 +57,7 @@ module PumaMetricsEngine
57
57
 
58
58
  def extract_request_start_time(env)
59
59
  # Try X-Request-Start header (common in nginx, HAProxy, etc.)
60
- # Format: "t=1234567890.123" or "1234567890.123" or Unix timestamp in microseconds
60
+ # Format: "t=1234567890.123" or "1234567890.123" or Unix timestamp in milliseconds/microseconds
61
61
  header_value = env["HTTP_X_REQUEST_START"] || env["X-Request-Start"]
62
62
 
63
63
  return nil unless header_value
@@ -75,10 +75,25 @@ module PumaMetricsEngine
75
75
 
76
76
  timestamp = timestamp_str.to_f
77
77
 
78
- # If timestamp is in microseconds (common with nginx), convert to seconds
79
- # Timestamps > year 2100 are likely in microseconds
78
+ # Detect timestamp format based on magnitude:
79
+ # - 10 digits or less: seconds (e.g., 1764410986)
80
+ # - 11-13 digits: milliseconds (e.g., 1764410986245)
81
+ # - 14+ digits: microseconds (e.g., 1764410986245000)
80
82
  if timestamp > 4_102_444_800 # Year 2100 in seconds
81
- timestamp = timestamp / 1_000_000.0
83
+ # Count digits in integer part to determine format
84
+ integer_part = timestamp.to_i.to_s
85
+ digit_count = integer_part.length
86
+
87
+ if digit_count <= 10
88
+ # Already in seconds
89
+ timestamp
90
+ elsif digit_count <= 13
91
+ # Milliseconds - convert to seconds
92
+ timestamp = timestamp / 1_000.0
93
+ else
94
+ # Microseconds - convert to seconds
95
+ timestamp = timestamp / 1_000_000.0
96
+ end
82
97
  end
83
98
 
84
99
  timestamp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PumaMetricsEngine
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma_metrics_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeto