Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(otel): custom span start + end times are fractional ms #27995

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/telemetry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ impl OtelTracer {
let start_time = start_time
.map(|start_time| {
SystemTime::UNIX_EPOCH
.checked_add(std::time::Duration::from_secs_f64(start_time))
.checked_add(std::time::Duration::from_secs_f64(start_time / 1000.0))
.ok_or_else(|| JsErrorBox::generic("invalid start time"))
})
.unwrap_or_else(|| Ok(SystemTime::now()))?;
Expand Down Expand Up @@ -1251,7 +1251,7 @@ impl OtelTracer {
let start_time = start_time
.map(|start_time| {
SystemTime::UNIX_EPOCH
.checked_add(std::time::Duration::from_secs_f64(start_time))
.checked_add(std::time::Duration::from_secs_f64(start_time / 1000.0))
.ok_or_else(|| JsErrorBox::generic("invalid start time"))
})
.unwrap_or_else(|| Ok(SystemTime::now()))?;
Expand Down Expand Up @@ -1366,7 +1366,7 @@ impl OtelSpan {
SystemTime::now()
} else {
SystemTime::UNIX_EPOCH
.checked_add(Duration::from_secs_f64(end_time))
.checked_add(Duration::from_secs_f64(end_time / 1000.0))
.unwrap()
};

Expand Down
8 changes: 4 additions & 4 deletions ext/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ interface IKeyValue {
value: IAnyValue;
}

function hrToSecs(hr: [number, number]): number {
return (hr[0] * 1e3 + hr[1] / 1e6) / 1000;
function hrToMs(hr: [number, number]): number {
return (hr[0] * 1e3 + hr[1] / 1e6);
}

export function enterSpan(span: Span): Context | undefined {
Expand Down Expand Up @@ -276,7 +276,7 @@ class Tracer {

let startTime = options?.startTime;
if (startTime && ArrayIsArray(startTime)) {
startTime = hrToSecs(startTime);
startTime = hrToMs(startTime);
} else if (startTime && isDate(startTime)) {
startTime = DatePrototypeGetTime(startTime);
}
Expand Down Expand Up @@ -383,7 +383,7 @@ class Span {

end(endTime?: TimeInput): void {
if (endTime && ArrayIsArray(endTime)) {
endTime = hrToSecs(endTime);
endTime = hrToMs(endTime);
} else if (endTime && isDate(endTime)) {
endTime = DatePrototypeGetTime(endTime);
}
Expand Down