Skip to content

Commit 148ff6f

Browse files
Lms24claude
andcommitted
ref(core): Export performanceTimeToSeconds with the _INTERNAL_ prefix
It is only meant for other Sentry packages, not for users. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ef9f589 commit 148ff6f

14 files changed

Lines changed: 48 additions & 42 deletions

File tree

‎packages/browser-utils/src/performance/entries.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
BROWSER_NAVIGATION_TIMING_SPAN_NAMES,
55
getActiveSpan,
66
parseUrl,
7-
performanceTimeToSeconds,
7+
_INTERNAL_performanceTimeToSeconds,
88
RESOURCE_SPAN_NAME_FALLBACK,
99
setMeasurement,
1010
spanToJSON,
@@ -108,7 +108,7 @@ export function startTrackingLongTasks(): void {
108108
const { attributes: parentAttributes, start_timestamp: parentStartTimestamp } = spanToJSON(parent);
109109

110110
for (const entry of entries) {
111-
const startTime = performanceTimeToSeconds(entry.startTime);
111+
const startTime = _INTERNAL_performanceTimeToSeconds(entry.startTime);
112112
if (!startTime) {
113113
continue;
114114
}
@@ -146,7 +146,7 @@ export function startTrackingLongAnimationFrames(): void {
146146
return;
147147
}
148148
for (const entry of list.getEntries() as PerformanceLongAnimationFrameTiming[]) {
149-
const startTime = performanceTimeToSeconds(entry.startTime);
149+
const startTime = _INTERNAL_performanceTimeToSeconds(entry.startTime);
150150
if (!startTime || !entry.scripts[0]) {
151151
continue;
152152
}
@@ -223,7 +223,7 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries
223223
const { attributes, start_timestamp: transactionStartTime } = spanToJSON(span);
224224

225225
performanceEntries.slice(_performanceCursor).forEach(entry => {
226-
const startTimestamp = performanceTimeToSeconds(entry.startTime);
226+
const startTimestamp = _INTERNAL_performanceTimeToSeconds(entry.startTime);
227227
if (!startTimestamp) {
228228
return;
229229
}
@@ -313,7 +313,7 @@ export function _addNavigationSpans(
313313
*/
314314
function _navigationTimeToSeconds(entry: PerformanceNavigationTiming, time: number): number {
315315
// The cast is safe: `addPerformanceEntries` only adds navigation spans if the time origin is available.
316-
return performanceTimeToSeconds(time, entry.startTime) as number;
316+
return _INTERNAL_performanceTimeToSeconds(time, entry.startTime) as number;
317317
}
318318

319319
type StartEventName =

‎packages/browser-utils/src/performance/interactions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
getActiveSpan,
2323
getRootSpan,
2424
hasSpanStreamingEnabled,
25-
performanceTimeToSeconds,
25+
_INTERNAL_performanceTimeToSeconds,
2626
spanToJSON,
2727
UI_ACTION_CLICK_SPAN_NAME_FALLBACK,
2828
UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,
@@ -242,7 +242,7 @@ function trackInteractionsAsSpans(client: Client): void {
242242
}
243243
for (const entry of entries) {
244244
if (entry.name === 'click') {
245-
const startTime = performanceTimeToSeconds(entry.startTime);
245+
const startTime = _INTERNAL_performanceTimeToSeconds(entry.startTime);
246246
if (!startTime) {
247247
continue;
248248
}

‎packages/browser-utils/src/performance/resourceTiming.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SpanAttributes } from '@sentry/core';
2-
import { performanceTimeToSeconds } from '@sentry/core';
2+
import { _INTERNAL_performanceTimeToSeconds } from '@sentry/core';
33
import { extractNetworkProtocol, msToSec } from './utils';
44

55
/**
@@ -22,15 +22,15 @@ export function resourceTimingToSpanAttributes(resourceTiming: PerformanceResour
2222
timingSpanData['network.protocol.name'] = name;
2323
}
2424

25-
if (performanceTimeToSeconds(resourceTiming.startTime) === undefined) {
25+
if (_INTERNAL_performanceTimeToSeconds(resourceTiming.startTime) === undefined) {
2626
return timingSpanData;
2727
}
2828

2929
// Use the origin from the request start for all timings, so the durations between them stay correct.
3030
const getAbsoluteTime = (time: number | undefined): number | undefined =>
3131
// falsy values should be preserved so that we can later on drop undefined values and
3232
// preserve 0 vals for cross-origin resources without proper `Timing-Allow-Origin` header.
33-
time ? performanceTimeToSeconds(time, resourceTiming.startTime) : time;
33+
time ? _INTERNAL_performanceTimeToSeconds(time, resourceTiming.startTime) : time;
3434

3535
return dropUndefinedKeysFromObject({
3636
...timingSpanData,

‎packages/browser-utils/src/performance/userTiming.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { IntegrationFn, Span, SpanAttributes, SpanAttributeValue } from '@s
33
import {
44
defineIntegration,
55
isPrimitive,
6-
performanceTimeToSeconds,
6+
_INTERNAL_performanceTimeToSeconds,
77
spanToJSON,
88
stringMatchesSomePattern,
99
} from '@sentry/core';
@@ -47,7 +47,7 @@ const _userTimingIntegration = ((options: UserTimingOptions = {}) => {
4747
continue;
4848
}
4949

50-
const startTimestamp = performanceTimeToSeconds(entry.startTime);
50+
const startTimestamp = _INTERNAL_performanceTimeToSeconds(entry.startTime);
5151
if (!startTimestamp) {
5252
continue;
5353
}
@@ -56,14 +56,14 @@ const _userTimingIntegration = ((options: UserTimingOptions = {}) => {
5656
continue;
5757
}
5858

59-
const endTimestamp = performanceTimeToSeconds(
59+
const endTimestamp = _INTERNAL_performanceTimeToSeconds(
6060
entry.startTime + Math.max(0, entry.duration),
6161
entry.startTime,
6262
) as number;
6363

6464
// We convert the request start with the entry's time origin, so that the clamp in `_addUserTimingSpan` compares
6565
// timestamps on the same timeline, even if the time origin was corrected between the request and the entry.
66-
const requestTimestamp = performanceTimeToSeconds(requestStart, entry.startTime) as number;
66+
const requestTimestamp = _INTERNAL_performanceTimeToSeconds(requestStart, entry.startTime) as number;
6767

6868
_addUserTimingSpan(idleSpan, entry, startTimestamp, endTimestamp, requestTimestamp, options.ignore ?? []);
6969
}

‎packages/browser-utils/src/web-vitals/spans.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getClient,
88
getRootSpan,
99
hasSpanStreamingEnabled,
10-
performanceTimeToSeconds,
10+
_INTERNAL_performanceTimeToSeconds,
1111
spanToJSON,
1212
timestampInSeconds,
1313
UI_INTERACTION_CLICK_SPAN_NAME_FALLBACK,
@@ -196,11 +196,11 @@ export function _sendLcpSpan(
196196
// keeps its duration equal to the reported value. The span's end uses the same origin, even if
197197
// the time origin was corrected in between.
198198
const navigationStart = navigationStartTime || 0;
199-
const startTime = performanceTimeToSeconds(navigationStart) ?? msToSec(navigationStart);
199+
const startTime = _INTERNAL_performanceTimeToSeconds(navigationStart) ?? msToSec(navigationStart);
200200
// Without an entry there is no render time to end at, so the span lasts the value it reports,
201201
// like an entry-less INP does. Ending at the time origin instead would invert the span.
202202
const endTime = entry
203-
? (performanceTimeToSeconds(entry.startTime, navigationStart) ?? msToSec(entry.startTime))
203+
? (_INTERNAL_performanceTimeToSeconds(entry.startTime, navigationStart) ?? msToSec(entry.startTime))
204204
: startTime + msToSec(lcpValue);
205205
const selector = entry ? htmlTreeAsString(entry.element) : undefined;
206206
const componentName = entry?.element ? getComponentName(entry.element) : null;
@@ -303,7 +303,7 @@ export function _sendClsSpan(
303303
// land it outside that navigation, on the route that follows it.
304304
const offset = entry?.startTime ?? navigationStartTime ?? 0;
305305
// CLS is only reported on pagehide, so we use the time origin from when the layout shift happened.
306-
const startTime = performanceTimeToSeconds(offset) ?? timestampInSeconds();
306+
const startTime = _INTERNAL_performanceTimeToSeconds(offset) ?? timestampInSeconds();
307307
const firstSourceNode = entry?.sources[0]?.node;
308308
const selector = entry ? htmlTreeAsString(firstSourceNode) : undefined;
309309
const componentName = firstSourceNode ? getComponentName(firstSourceNode) : null;
@@ -412,7 +412,7 @@ export function _sendInpSpan(
412412
// at the start of the navigation it belongs to rather than at the interaction.
413413
// INP is reported on pagehide, often long after the interaction, so we use the time origin from when the
414414
// interaction happened.
415-
const startTime = performanceTimeToSeconds(entry?.startTime ?? metric?.navigationStartTime ?? 0);
415+
const startTime = _INTERNAL_performanceTimeToSeconds(entry?.startTime ?? metric?.navigationStartTime ?? 0);
416416
if (!startTime) {
417417
return;
418418
}

‎packages/browser-utils/test/performance/addPerformanceEntries.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vi.mock('@sentry/core', async () => {
1313
return {
1414
...actual,
1515
browserPerformanceTimeOrigin,
16-
performanceTimeToSeconds: (time: number, entryStartTime = time) =>
16+
_INTERNAL_performanceTimeToSeconds: (time: number, entryStartTime = time) =>
1717
(browserPerformanceTimeOrigin(entryStartTime) + time) / 1000,
1818
};
1919
});

‎packages/browser-utils/test/performance/resourceTiming.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('resourceTimingToSpanAttributes', () => {
1111
beforeEach(() => {
1212
vi.clearAllMocks();
1313
browserPerformanceTimeOriginSpy = vi.spyOn(utils, 'browserPerformanceTimeOrigin');
14-
vi.spyOn(utils, 'performanceTimeToSeconds').mockImplementation((time, entryStartTime = time) => {
14+
vi.spyOn(utils, '_INTERNAL_performanceTimeToSeconds').mockImplementation((time, entryStartTime = time) => {
1515
const origin = utils.browserPerformanceTimeOrigin(entryStartTime);
1616
return origin ? (origin + time) / 1000 : undefined;
1717
});

‎packages/browser-utils/test/performance/userTiming.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type * as SentryCore from '@sentry/core';
22
import type { Span } from '@sentry/core';
3-
import { getMainCarrier, performanceTimeToSeconds, SentrySpan, setCurrentClient, spanToJSON } from '@sentry/core';
3+
import {
4+
getMainCarrier,
5+
_INTERNAL_performanceTimeToSeconds,
6+
SentrySpan,
7+
setCurrentClient,
8+
spanToJSON,
9+
} from '@sentry/core';
410
import { beforeEach, describe, expect, it, vi } from 'vitest';
511
import { _addUserTimingSpan, userTimingIntegration } from '../../src/performance/userTiming';
612
import * as utils from '../../src/performance/utils';
@@ -9,7 +15,7 @@ import { getDefaultClientOptions, TestClient } from '../utils/TestClient';
915

1016
vi.mock('@sentry/core', async importOriginal => {
1117
const actual = await importOriginal<typeof SentryCore>();
12-
return { ...actual, performanceTimeToSeconds: vi.fn(actual.performanceTimeToSeconds) };
18+
return { ...actual, _INTERNAL_performanceTimeToSeconds: vi.fn(actual._INTERNAL_performanceTimeToSeconds) };
1319
});
1420

1521
describe('userTimingIntegration', () => {
@@ -19,7 +25,7 @@ describe('userTimingIntegration', () => {
1925

2026
beforeEach(() => {
2127
vi.restoreAllMocks();
22-
vi.mocked(performanceTimeToSeconds).mockReset();
28+
vi.mocked(_INTERNAL_performanceTimeToSeconds).mockReset();
2329
getMainCarrier().__SENTRY__ = undefined;
2430

2531
client = new TestClient(getDefaultClientOptions({ tracesSampleRate: 1 }));
@@ -147,14 +153,14 @@ describe('userTimingIntegration', () => {
147153

148154
client.emit('beforeIdleSpanEnd', new SentrySpan({ op: 'pageload', name: '/', sampled: true }));
149155

150-
expect(spanToJSON(spans[i]!).start_timestamp).toBe(performanceTimeToSeconds(requestStart, 0));
156+
expect(spanToJSON(spans[i]!).start_timestamp).toBe(_INTERNAL_performanceTimeToSeconds(requestStart, 0));
151157
}
152158
});
153159

154160
it('keeps measures recorded after the wall clock was corrected backwards', () => {
155161
const timeOrigin = performance.timeOrigin;
156162
// The time origin was corrected 60s backwards at 1000ms, e.g. by NTP.
157-
vi.mocked(performanceTimeToSeconds).mockImplementation(
163+
vi.mocked(_INTERNAL_performanceTimeToSeconds).mockImplementation(
158164
(monotonicTimeInMs, entryStartTimeInMs = monotonicTimeInMs) =>
159165
((entryStartTimeInMs < 1000 ? timeOrigin : timeOrigin - 60_000) + monotonicTimeInMs) / 1000,
160166
);

‎packages/browser-utils/test/web-vitals/spans.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ vi.mock('@sentry/core', async () => {
2222
return {
2323
...actual,
2424
browserPerformanceTimeOrigin: vi.fn(),
25-
performanceTimeToSeconds: vi.fn(),
25+
_INTERNAL_performanceTimeToSeconds: vi.fn(),
2626
timestampInSeconds: vi.fn(),
2727
getCurrentScope: vi.fn(),
2828
getClient: vi.fn(),
@@ -379,7 +379,7 @@ describe('_sendLcpSpan', () => {
379379
beforeEach(() => {
380380
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
381381
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
382-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(
382+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(
383383
(time, entryStartTime = time) => (SentryCore.browserPerformanceTimeOrigin(entryStartTime)! + time) / 1000,
384384
);
385385
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
@@ -517,7 +517,7 @@ describe('_sendClsSpan', () => {
517517
beforeEach(() => {
518518
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
519519
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
520-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
520+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
521521
vi.mocked(SentryCore.timestampInSeconds).mockReturnValue(1.5);
522522
vi.mocked(htmlTreeAsString).mockImplementation((node: any) => `<${node?.tagName || 'div'}>`);
523523
vi.mocked(SentryCoreBrowser.startInactiveSpan).mockReturnValue(mockSpan as any);
@@ -611,7 +611,7 @@ describe('_sendClsSpan', () => {
611611

612612
it('falls back to the current time when there is no performance time origin', () => {
613613
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(undefined);
614-
vi.mocked(SentryCore.performanceTimeToSeconds).mockReturnValue(undefined);
614+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockReturnValue(undefined);
615615

616616
_sendClsSpan(0, undefined);
617617

@@ -634,7 +634,7 @@ describe('_sendInpSpan', () => {
634634
beforeEach(() => {
635635
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
636636
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
637-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
637+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
638638
vi.mocked(htmlTreeAsString).mockReturnValue('<button>');
639639
vi.mocked(SentryCoreBrowser.startInactiveSpan).mockReturnValue(mockSpan as any);
640640
vi.mocked(SentryCore.getActiveSpan).mockReturnValue(undefined);
@@ -697,7 +697,7 @@ describe('_sendInpSpan', () => {
697697
// should still use the old one.
698698
const sleepDurationMs = 3_600_000;
699699
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000 + sleepDurationMs);
700-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(time =>
700+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(time =>
701701
time < 500 ? (1000 + sleepDurationMs + time) / 1000 : (1000 + time) / 1000,
702702
);
703703

@@ -838,7 +838,7 @@ describe('trackInpAsSpan', () => {
838838

839839
beforeEach(() => {
840840
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
841-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
841+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
842842
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
843843
vi.mocked(SentryCore.getActiveSpan).mockReturnValue(undefined);
844844
vi.mocked(SentryCoreBrowser.startInactiveSpan).mockReturnValue({ end: vi.fn() } as any);
@@ -937,7 +937,7 @@ describe('soft navigation web vitals', () => {
937937
supportedEntryTypes: ['largest-contentful-paint', 'layout-shift', 'soft-navigation'],
938938
});
939939
vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockReturnValue(1000);
940-
vi.mocked(SentryCore.performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
940+
vi.mocked(SentryCore._INTERNAL_performanceTimeToSeconds).mockImplementation(time => (1000 + time) / 1000);
941941
vi.mocked(SentryCore.getCurrentScope).mockReturnValue(mockScope as any);
942942
vi.mocked(SentryCoreBrowser.startInactiveSpan).mockReturnValue({ end: vi.fn() } as any);
943943
vi.mocked(SentryCore.spanToJSON).mockImplementation(

‎packages/browser/src/profiling/utils.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getClient,
66
getDebugImagesForResources,
77
GLOBAL_OBJ,
8-
performanceTimeToSeconds,
8+
_INTERNAL_performanceTimeToSeconds,
99
uuid4,
1010
} from '@sentry/core';
1111
import type { BrowserOptions } from '../client';
@@ -155,7 +155,7 @@ function convertToContinuousProfile(input: {
155155
}
156156
// Sample timestamps are relative to `performance.timeOrigin`, so we convert them like performance entries.
157157
// The cast is safe: the JS Self-Profiling API only exists if the Performance API does.
158-
const timestampSeconds = performanceTimeToSeconds(sample.timestamp) as number;
158+
const timestampSeconds = _INTERNAL_performanceTimeToSeconds(sample.timestamp) as number;
159159
samples[i] = {
160160
stack_id: sample.stackId ?? 0,
161161
thread_id: PROFILER_THREAD_ID_STRING,

0 commit comments

Comments
 (0)