8000 fix(tracing): Ensure we use s instead of ms for startTimestamp (#7877) · jchatard/sentry-javascript@e3313ad · GitHub
[go: up one dir, main page]

Skip to content

Commit e3313ad

Browse files
authored
fix(tracing): Ensure we use s instead of ms for startTimestamp (getsentry#7877)
Let's deprecate `timestampWithMs` in a follow up PR.
1 parent dce2831 commit e3313ad

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

packages/angular/src/tracing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Router } from '@angular/router';
1010
import { NavigationEnd, NavigationStart, ResolveEnd } from '@angular/router';
1111
import { getCurrentHub, WINDOW } from '@sentry/browser';
1212
import type { Span, Transaction, TransactionContext } from '@sentry/types';
13-
import { logger, stripUrlQueryAndFragment, timestampWithMs } from '@sentry/utils';
13+
import { logger, stripUrlQueryAndFragment, timestampInSeconds } from '@sentry/utils';
1414
import type { Observable } from 'rxjs';
1515
import { Subscription } from 'rxjs';
1616
import { filter, tap } from 'rxjs/operators';
@@ -258,7 +258,7 @@ export function TraceMethodDecorator(): MethodDecorator {
258258
const originalMethod = descriptor.value;
259259
// eslint-disable-next-line @typescript-eslint/no-explicit-any
260260
descriptor.value = function (...args: any[]): ReturnType<typeof originalMethod> {
261-
const now = timestampWithMs();
261+
const now = timestampInSeconds();
262262
const activeTransaction = getActiveTransaction();
263263
if (activeTransaction) {
264264
activeTransaction.startChild({

packages/core/src/tracing/idletransaction.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import type { TransactionContext } from '@sentry/types';
3-
import { logger, timestampWithMs } from '@sentry/utils';
3+
import { logger, timestampInSeconds } from '@sentry/utils';
44

55
import type { Hub } from '../hub';
66
import type { Span } from './span';
@@ -46,7 +46,7 @@ export class IdleTransactionSpanRecorder extends SpanRecorder {
4646
if (span.spanId !== this.transactionSpanId) {
4747
// We patch span.finish() to pop an activity after setting an endTimestamp.
4848
span.finish = (endTimestamp?: number) => {
49-
span.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs();
49+
span.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampInSeconds();
5050
this._popActivity(span.spanId);
5151
};
5252

@@ -128,7 +128,7 @@ export class IdleTransaction extends Transaction {
128128
}
129129

130130
/** {@inheritDoc} */
131-
public finish(endTimestamp: number = timestampWithMs()): string | undefined {
131+
public finish(endTimestamp: number = timestampInSeconds()): string | undefined {
132132
this._finished = true;
133133
this.activities = {};
134134

@@ -301,13 +301,13 @@ export class IdleTransaction extends Transaction {
301301
}
302302

303303
if (Object.keys(this.activities).length === 0) {
304-
const endTimestamp = timestampWithMs();
304+
const endTimestamp = timestampInSeconds();
305305
if (this._idleTimeoutCanceledPermanently) {
306306
this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[5];
307307
this.finish(endTimestamp);
308308
} else {
309309
// We need to add the timeout here to have the real endtimestamp of the transaction
310-
// Remember timestampWithMs is in seconds, timeout is in ms
310+
// Remember timestampInSeconds is in seconds, timeout is in ms
311311
this._restartIdleTimeout(endTimestamp + this._idleTimeout / 1000);
312312
}
313313
}

packages/core/src/tracing/span.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
TraceContext,
88
Transaction,
99
} from '@sentry/types';
10-
import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils';
10+
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
1111

1212
/**
1313
* Keeps track of finished spans for a given transaction
@@ -71,7 +71,7 @@ export class Span implements SpanInterface {
7171
/**
7272
* Timestamp in seconds when the span was created.
7373
*/
74-
public startTimestamp: number = timestampWithMs();
74+
public startTimestamp: number = timestampInSeconds();
7575

7676
/**
7777
* Timestamp in seconds when the span ended.
@@ -257,7 +257,7 @@ export class Span implements SpanInterface {
257257
}
258258
}
259259

260-
this.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs();
260+
this.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampInSeconds();
261261
}
262262

263263
/**

packages/ember/addon/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { macroCondition, isDevelopingApp, getOwnConfig } from '@embroider/macros
44
import { next } from '@ember/runloop';
55
import { assert, warn } from '@ember/debug';
66
import Ember from 'ember';
7-
import { timestampWithMs, GLOBAL_OBJ } from '@sentry/utils';
7+
import { timestampInSeconds, GLOBAL_OBJ } from '@sentry/utils';
88
import { GlobalConfig, OwnConfig } from './types';
99

1010
function _getSentryInitConfig() {
@@ -68,7 +68,7 @@ export const getActiveTransaction = () => {
6868

6969
export const instrumentRoutePerformance = (BaseRoute: any) => {
7070
const instrumentFunction = async (op: string, description: string, fn: Function, args: any) => {
71-
const startTimestamp = timestampWithMs();
71+
const startTimestamp = timestampInSeconds();
7272
const result = await fn(...args);
7373

7474
const currentTransaction = getActiveTransaction();

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ExtendedBackburner } from '@sentry/ember/runloop';
66
import { Span, Transaction } from '@sentry/types';
77
import { EmberRunQueues } from '@ember/runloop/-private/types';
88
import { getActiveTransaction } from '..';
9-
import { browserPerformanceTimeOrigin, GLOBAL_OBJ, timestampWithMs } from '@sentry/utils';
9+
import { browserPerformanceTimeOrigin, GLOBAL_OBJ, timestampInSeconds } from '@sentry/utils';
1010
import { macroCondition, isTesting, getOwnConfig } from '@embroider/macros';
1111
import { EmberSentryConfig, GlobalConfig, OwnConfig } from '../types';
1212
import RouterService from '@ember/routing/router-service';
@@ -182,14 +182,14 @@ function _instrumentEmberRunloop(config: EmberSentryConfig) {
182182
if (currentQueueSpan) {
183183
currentQueueSpan.finish();
184184
}
185-
currentQueueStart = timestampWithMs();
185+
currentQueueStart = timestampInSeconds();
186186

187187
instrumentedEmberQueues.forEach(queue => {
188188
scheduleOnce(queue, null, () => {
189189
scheduleOnce(queue, null, () => {
190190
// Process this queue using the end of the previous queue.
191191
if (currentQueueStart) {
192-
const now = timestampWithMs();
192+
const now = timestampInSeconds();
193193
const minQueueDuration = minimumRunloopQueueDuration ?? 5;
194194

195195
if ((now - currentQueueStart) * 1000 >= minQueueDuration) {
@@ -210,7 +210,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig) {
210210
if (!stillActiveTransaction) {
211211
return;
212212
}
213-
currentQueueStart = timestampWithMs();
213+
currentQueueStart = timestampInSeconds();
214214
});
215215
});
216216
});
@@ -244,7 +244,7 @@ interface RenderEntries {
244244
function processComponentRenderBefore(payload: Payload, beforeEntries: RenderEntries) {
245245
const info = {
246246
payload,
247-
now: timestampWithMs(),
247+
now: timestampInSeconds(),
248248
};
249249
beforeEntries[payload.object] = info;
250250
}
@@ -261,7 +261,7 @@ function processComponentRenderAfter(
261261
return;
262262
}
263263

264-
const now = timestampWithMs();
264+
const now = timestampInSeconds();
265265
const componentRenderDuration = now - begin.now;
266266

267267
if (componentRenderDuration * 1000 >= minComponentDuration) {

packages/react/src/profiler.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type { Hub } from '@sentry/browser';
44
import { getCurrentHub } from '@sentry/browser';
55
import type { Span, Transaction } from '@sentry/types';
6-
import { timestampWithMs } from '@sentry/utils';
6+
import { timestampInSeconds } from '@sentry/utils';
77
import hoistNonReactStatics from 'hoist-non-react-statics';
88
import * as React from 'react';
99

@@ -82,7 +82,7 @@ class Profiler extends React.Component<ProfilerProps> {
8282
// set as data on the span. We just store the prop keys as the values could be potenially very large.
8383
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
8484
if (changedProps.length > 0) {
85-
const now = timestampWithMs();
85+
const now = timestampInSeconds();
8686
this._updateSpan = this._mountSpan.startChild({
8787
data: {
8888
changedProps,
@@ -114,7 +114,7 @@ class Profiler extends React.Component<ProfilerProps> {
114114
// next activity as a child to the component mount activity.
115115
this._mountSpan.startChild({
116116
description: `<${name}>`,
117-
endTimestamp: timestampWithMs(),
117+
endTimestamp: timestampInSeconds(),
118118
op: REACT_RENDER_OP,
119119
startTimestamp: this._mountSpan.endTimestamp,
120120
});
@@ -195,7 +195,7 @@ function useProfiler(
195195
if (mountSpan && options.hasRenderSpan) {
196196
mountSpan.startChild({
197197
description: `<${name}>`,
198-
endTimestamp: timestampWithMs(),
198+
endTimestamp: timestampInSeconds(),
199199
op: REACT_RENDER_OP,
200200
startTimestamp: mountSpan.endTimestamp,
201201
});

packages/tracing-internal/src/browser/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export function instrumentRoutingWithDefaults<T extends Transaction>(
2222
if (startTransactionOnPageLoad) {
2323
activeTransaction = customStartTransaction({
2424
name: WINDOW.location.pathname,
25-
// pageload should always start at timeOrigin
26-
startTimestamp: browserPerformanceTimeOrigin,
25+
// pageload should always start at timeOrigin (and needs to be in s, not ms)
26+
startTimestamp: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined,
2727
op: 'pageload',
2828
metadata: { source: 'url' },
2929
});

0 commit comments

Comments
 (0)
0