humanmade / aws-xray

HM Platform AWS X-Ray Integration
23 stars 4 forks source link

Fix timestamp calculations #81

Closed rmccue closed 2 years ago

rmccue commented 2 years ago

Fixes https://github.com/humanmade/product-dev/issues/851, see 6adf8ca4816c27bcc3a471aa5c28ac661e729731 for explanation of the problem:

In cases where the rounded figure differed by a large amount, this lead to a large discrepency in the timestamps being calculated.

For example, if there are 1001 frames, we take every second item ($pluck_every_n = 2). However, we calculate the duration as $original * ( 1001 / 1000 ), whereas by halving the number of frames, we actually need to double the duration.

Using the same variable corrects for this inaccuracy and ensures consistency across the calculation.