@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
30 lines (29 loc) • 1.01 kB
JavaScript
import { SENTRY_TIMESTAMP_SEQUENCE } from "@sentry/conventions/attributes";
// src/utils/timestampSequence.ts
let _sequenceNumber = 0;
let _previousTimestampMs;
/**
* Returns the `sentry.timestamp.sequence` attribute entry for a serialized telemetry item.
*
* The sequence number starts at 0 and increments by 1 for each item captured.
* It resets to 0 when the current item's integer millisecond timestamp differs
* from the previous item's integer millisecond timestamp.
*
* @param timestampInSeconds - The timestamp of the telemetry item in seconds.
*/
function getSequenceAttribute(timestampInSeconds) {
const nowMs = Math.floor(timestampInSeconds * 1e3);
if (_previousTimestampMs !== void 0 && nowMs !== _previousTimestampMs) _sequenceNumber = 0;
const value = _sequenceNumber;
_sequenceNumber++;
_previousTimestampMs = nowMs;
return {
key: SENTRY_TIMESTAMP_SEQUENCE,
value: {
value,
type: "integer"
}
};
}
export { getSequenceAttribute };
//# sourceMappingURL=timestampSequence.js.map