Description
Since PR #2230 (v0.98.0), the span metric php.compilation.total_time_ms reports values in microseconds rather than milliseconds, inflating reported values by 1000x.
Root cause
PR #2230 replaced the _get_microseconds() helper (which used clock_gettime and returned microseconds) with zend_hrtime() (which returns nanoseconds) in ext/engine_hooks.c, but did not update the accumulator or the serializer divisor:
// Before (correct): _get_microseconds() returned microseconds
DDTRACE_G(compile_time_microseconds) += (int64_t)(_get_microseconds() - start);
// After (incorrect): zend_hrtime() returns nanoseconds, stored as-is
DDTRACE_G(compile_time_microseconds) += (int64_t)(zend_hrtime() - start);
The serializer in ext/serializer.c divides by 1000. expecting microseconds → milliseconds, but now receives nanoseconds, producing microseconds labeled as milliseconds.
Notably, the same PR correctly handled this conversion in circuit_breaker.c:
return zend_hrtime() / 1000; // correctly converts nanoseconds → microseconds
Evidence
A request with a total duration of ~4,350 ms reported php.compilation.total_time_ms of ~28,346 — impossible if in milliseconds (exceeds request duration), but perfectly reasonable as ~28.3 ms in microseconds.
PHP version
All versions (the bug is in the tracer, not PHP)
Tracer version
>= 0.98.0
Installed extensions
N/A — affects the tracer itself
Output of phpinfo()
N/A
Description
Since PR #2230 (v0.98.0), the span metric
php.compilation.total_time_msreports values in microseconds rather than milliseconds, inflating reported values by 1000x.Root cause
PR #2230 replaced the
_get_microseconds()helper (which usedclock_gettimeand returned microseconds) withzend_hrtime()(which returns nanoseconds) inext/engine_hooks.c, but did not update the accumulator or the serializer divisor:The serializer in
ext/serializer.cdivides by1000.expecting microseconds → milliseconds, but now receives nanoseconds, producing microseconds labeled as milliseconds.Notably, the same PR correctly handled this conversion in
circuit_breaker.c:Evidence
A request with a total duration of ~4,350 ms reported
php.compilation.total_time_msof ~28,346 — impossible if in milliseconds (exceeds request duration), but perfectly reasonable as ~28.3 ms in microseconds.PHP version
All versions (the bug is in the tracer, not PHP)
Tracer version
>= 0.98.0
Installed extensions
N/A — affects the tracer itself
Output of phpinfo()
N/A