-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Allow to pass start/end timestamp for spans flexibly #10060
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { Span, TraceContext } from '@sentry/types'; | ||
import { dropUndefinedKeys, generateSentryTraceHeader } from '@sentry/utils'; | ||
import type { Span, SpanTimeInput, TraceContext } from '@sentry/types'; | ||
import { dropUndefinedKeys, generateSentryTraceHeader, timestampInSeconds } from '@sentry/utils'; | ||
|
||
/** | ||
* Convert a span to a trace context, which can be sent as the `trace` context in an event. | ||
|
@@ -26,3 +26,31 @@ export function spanToTraceContext(span: Span): TraceContext { | |
export function spanToTraceHeader(span: Span): string { | ||
return generateSentryTraceHeader(span.traceId, span.spanId, span.sampled); | ||
} | ||
|
||
/** | ||
* Convert a span time input intp a timestamp in seconds. | ||
*/ | ||
export function spanTimeInputToSeconds(input: SpanTimeInput | undefined): number { | ||
if (typeof input === 'number') { | ||
return ensureTimestampInSeconds(input); | ||
} | ||
|
||
if (Array.isArray(input)) { | ||
// See {@link HrTime} for the array-based time format | ||
return input[0] + input[1] / 1e9; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is vendored we need to add license There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is only inspired, not copied - only the comment I took verbatim 🤔 but we can also move this to it's own file, then we can still add the licence even if it is adapted from there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with these kind of things, better be safe than sorry - let's move to it's own file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
} | ||
|
||
if (input instanceof Date) { | ||
return ensureTimestampInSeconds(input.getTime()); | ||
} | ||
|
||
return timestampInSeconds(); | ||
} | ||
|
||
/** | ||
* Converts a timestamp to second, if it was in milliseconds, or keeps it as second. | ||
*/ | ||
function ensureTimestampInSeconds(timestamp: number): number { | ||
const isMs = timestamp > 9999999999; | ||
return isMs ? timestamp / 1000 : timestamp; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a small comment explaining what is normalized and why things need normalization?