@@ -12,6 +12,7 @@ import type {
1212 TransactionSource ,
1313} from '@sentry/core' ;
1414import {
15+ _INTERNAL_safeDateNow ,
1516 captureEvent ,
1617 convertSpanLinksForEnvelope ,
1718 debounce ,
@@ -82,7 +83,7 @@ export class SentrySpanExporter {
8283 } ) {
8384 this . _finishedSpanBucketSize = options ?. timeout || DEFAULT_TIMEOUT ;
8485 this . _finishedSpanBuckets = new Array ( this . _finishedSpanBucketSize ) . fill ( undefined ) ;
85- this . _lastCleanupTimestampInS = Math . floor ( Date . now ( ) / 1000 ) ;
86+ this . _lastCleanupTimestampInS = Math . floor ( _INTERNAL_safeDateNow ( ) / 1000 ) ;
8687 this . _spansToBucketEntry = new WeakMap ( ) ;
8788 this . _sentSpans = new Map < string , number > ( ) ;
8889 this . _debouncedFlush = debounce ( this . flush . bind ( this ) , 1 , { maxWait : 100 } ) ;
@@ -93,7 +94,7 @@ export class SentrySpanExporter {
9394 * This is called by the span processor whenever a span is ended.
9495 */
9596 public export ( span : ReadableSpan ) : void {
96- const currentTimestampInS = Math . floor ( Date . now ( ) / 1000 ) ;
97+ const currentTimestampInS = Math . floor ( _INTERNAL_safeDateNow ( ) / 1000 ) ;
9798
9899 if ( this . _lastCleanupTimestampInS !== currentTimestampInS ) {
99100 let droppedSpanCount = 0 ;
@@ -146,7 +147,7 @@ export class SentrySpanExporter {
146147 `SpanExporter exported ${ sentSpanCount } spans, ${ remainingOpenSpanCount } spans are waiting for their parent spans to finish` ,
147148 ) ;
148149
149- const expirationDate = Date . now ( ) + DEFAULT_TIMEOUT * 1000 ;
150+ const expirationDate = _INTERNAL_safeDateNow ( ) + DEFAULT_TIMEOUT * 1000 ;
150151
151152 for ( const span of sentSpans ) {
152153 this . _sentSpans . set ( span . spanContext ( ) . spanId , expirationDate ) ;
@@ -226,7 +227,7 @@ export class SentrySpanExporter {
226227
227228 /** Remove "expired" span id entries from the _sentSpans cache. */
228229 private _flushSentSpanCache ( ) : void {
229- const currentTimestamp = Date . now ( ) ;
230+ const currentTimestamp = _INTERNAL_safeDateNow ( ) ;
230231 // Note, it is safe to delete items from the map as we go: https://stackoverflow.com/a/35943995/90297
231232 for ( const [ spanId , expirationTime ] of this . _sentSpans . entries ( ) ) {
232233 if ( expirationTime <= currentTimestamp ) {
0 commit comments