Skip to content

Commit 234a598

Browse files
committed
fix: Address PR review
1 parent d0a4be8 commit 234a598

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

packages/apm/src/integrations/tracing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ export class Tracing implements Integration {
660660
break;
661661
case 'resource':
662662
const resourceName = entry.name.replace(window.location.origin, '');
663-
if (entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch') {
664-
// do nothing, we can't adjust timings just based on urls
665-
} else {
663+
// we already instrument based on fetch and xhr, so we don't need to
664+
// duplicate spans here.
665+
if (entry.initiatorType !== 'xmlhttprequest' && entry.initiatorType !== 'fetch') {
666666
const resource = transactionSpan.startChild({
667667
description: `${entry.initiatorType} ${resourceName}`,
668668
op: `resource`,

packages/tracing/src/browser/metrics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ function addResourceSpans(
214214
duration: number,
215215
timeOrigin: number,
216216
): number | undefined {
217+
// we already instrument based on fetch and xhr, so we don't need to
218+
// duplicate spans here.
217219
if (entry.initiatorType === 'xmlhttprequest' || entry.initiatorType === 'fetch') {
218220
return undefined;
219221
}

packages/tracing/src/browser/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function registerRequestInstrumentation(_options?: Partial<RequestInstrum
104104
if (traceFetch) {
105105
addInstrumentationHandler({
106106
callback: (handlerData: FetchData) => {
107-
fetchCallback(handlerData, shouldCreateSpan, spans);
107+
_fetchCallback(handlerData, shouldCreateSpan, spans);
108108
},
109109
type: 'fetch',
110110
});
@@ -123,7 +123,7 @@ export function registerRequestInstrumentation(_options?: Partial<RequestInstrum
123123
/**
124124
* Create and track fetch request spans
125125
*/
126-
export function fetchCallback(
126+
export function _fetchCallback(
127127
handlerData: FetchData,
128128
shouldCreateSpan: (url: string) => boolean,
129129
spans: Record<string, Span>,

packages/tracing/src/idletransaction.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export class IdleTransaction extends Transaction {
118118
this._prevHeartbeatString = heartbeatString;
119119

120120
if (this._heartbeatCounter >= 3) {
121-
logger.log(
122-
`[Tracing] Transaction: ${SpanStatus.DeadlineExceeded} -> Heartbeat safeguard kicked in since content hasn't changed for 3 beats`,
123-
);
121+
logger.log(`[Tracing] Transaction finished because of no change for 3 heart beats`);
124122
this.setStatus(SpanStatus.DeadlineExceeded);
125123
this.setTag('heartbeat', 'failed');
126124
this.finish();

packages/tracing/test/browser/request.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BrowserClient } from '@sentry/browser';
22
import { Hub, makeMain } from '@sentry/hub';
33

44
import { Span, Transaction } from '../../src';
5-
import { fetchCallback, FetchData, registerRequestInstrumentation } from '../../src/browser/request';
5+
import { _fetchCallback, FetchData, registerRequestInstrumentation } from '../../src/browser/request';
66
import { addExtensionMethods } from '../../src/hubextensions';
77

88
declare global {
@@ -69,21 +69,17 @@ describe('registerRequestInstrumentation', () => {
6969
});
7070
});
7171

72-
describe('fetchCallback', () => {
72+
describe('_fetchCallback()', () => {
7373
let hub: Hub;
7474
let transaction: Transaction;
75-
beforeEach(() => {
75+
beforeAll(() => {
7676
hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
7777
makeMain(hub);
78-
transaction = hub.startTransaction({ name: 'organizations/users/:userid', op: 'pageload' }) as Transaction;
79-
hub.configureScope(scope => scope.setSpan(transaction));
8078
});
8179

82-
afterEach(() => {
83-
if (transaction) {
84-
transaction.finish();
85-
}
86-
hub.configureScope(scope => scope.setSpan(undefined));
80+
beforeEach(() => {
81+
transaction = hub.startTransaction({ name: 'organizations/users/:userid', op: 'pageload' }) as Transaction;
82+
hub.configureScope(scope => scope.setSpan(transaction));
8783
});
8884

8985
it('does not create span if it should not be created', () => {
@@ -98,7 +94,7 @@ describe('fetchCallback', () => {
9894
};
9995
const spans = {};
10096

101-
fetchCallback(data, shouldCreateSpan, spans);
97+
_fetchCallback(data, shouldCreateSpan, spans);
10298
expect(spans).toEqual({});
10399
});
104100

@@ -110,7 +106,7 @@ describe('fetchCallback', () => {
110106
};
111107
const spans = {};
112108

113-
fetchCallback(data, shouldCreateSpan, spans);
109+
_fetchCallback(data, shouldCreateSpan, spans);
114110
expect(spans).toEqual({});
115111
});
116112

@@ -127,7 +123,7 @@ describe('fetchCallback', () => {
127123
const spans: Record<string, Span> = {};
128124

129125
// Start fetch request
130-
fetchCallback(data, shouldCreateSpan, spans);
126+
_fetchCallback(data, shouldCreateSpan, spans);
131127
const spanKey = Object.keys(spans)[0];
132128

133129
const fetchSpan = spans[spanKey];
@@ -151,7 +147,7 @@ describe('fetchCallback', () => {
151147
};
152148

153149
// End fetch request
154-
fetchCallback(newData, shouldCreateSpan, spans);
150+
_fetchCallback(newData, shouldCreateSpan, spans);
155151
expect(spans).toEqual({});
156152
if (transaction.spanRecorder) {
157153
expect(transaction.spanRecorder.spans[1].endTimestamp).toBeDefined();

0 commit comments

Comments
 (0)