Skip to content

Commit aa28800

Browse files
ref(tracing): Make sure error status is set on transactions (#2818)
* ref: Make sure error status is set on transactions Co-authored-by: Rodolfo Carvalho <[email protected]>
1 parent 5ed3135 commit aa28800

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { DEFAULT_IDLE_TIMEOUT, IdleTransaction } from '../idletransaction';
77
import { Span } from '../span';
88
import { SpanStatus } from '../spanstatus';
99
import { registerBackgroundTabDetection } from './backgroundtab';
10-
import { registerErrorInstrumentation } from './errors';
1110
import { MetricsInstrumentation } from './metrics';
1211
import {
1312
defaultRequestInstrumentionOptions,
@@ -171,9 +170,6 @@ export class BrowserTracing implements Integration {
171170
startTransactionOnLocationChange,
172171
);
173172

174-
// TODO: Should this be default behaviour?
175-
registerErrorInstrumentation();
176-
177173
if (markBackgroundTransactions) {
178174
registerBackgroundTabDetection();
179175
}

packages/tracing/src/browser/errors.ts renamed to packages/tracing/src/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { addInstrumentationHandler, logger } from '@sentry/utils';
22

3-
import { SpanStatus } from '../spanstatus';
4-
import { getActiveTransaction } from './utils';
3+
import { getActiveTransaction } from './browser/utils';
4+
import { SpanStatus } from './spanstatus';
55

66
/**
77
* Configures global error listeners

packages/tracing/src/hubextensions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getMainCarrier, Hub } from '@sentry/hub';
22
import { TransactionContext } from '@sentry/types';
33

4+
import { registerErrorInstrumentation } from './errors';
45
import { IdleTransaction } from './idletransaction';
56
import { Transaction } from './transaction';
67

@@ -63,9 +64,9 @@ export function startIdleTransaction(
6364
}
6465

6566
/**
66-
* This patches the global object and injects the Tracing extensions methods
67+
* @private
6768
*/
68-
export function addExtensionMethods(): void {
69+
export function _addTracingExtensions(): void {
6970
const carrier = getMainCarrier();
7071
if (carrier.__SENTRY__) {
7172
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
@@ -77,3 +78,13 @@ export function addExtensionMethods(): void {
7778
}
7879
}
7980
}
81+
82+
/**
83+
* This patches the global object and injects the Tracing extensions methods
84+
*/
85+
export function addExtensionMethods(): void {
86+
_addTracingExtensions();
87+
88+
// If an error happens globally, we should make sure transaction status is set to error.
89+
registerErrorInstrumentation();
90+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ jest.mock('@sentry/utils', () => {
3535
if (type === 'xhr') {
3636
mockXHRCallback = jest.fn(callback);
3737
}
38-
return mockAddInstrumentationHandler({ callback, type });
38+
if (typeof mockAddInstrumentationHandler === 'function') {
39+
return mockAddInstrumentationHandler({ callback, type });
40+
}
3941
},
4042
};
4143
});

packages/tracing/test/browser/errors.test.ts renamed to packages/tracing/test/errors.test.ts

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

4-
import { SpanStatus } from '../../src';
5-
import { registerErrorInstrumentation } from '../../src/browser/errors';
6-
import { addExtensionMethods } from '../../src/hubextensions';
4+
import { SpanStatus } from '../src';
5+
import { registerErrorInstrumentation } from '../src/errors';
6+
import { _addTracingExtensions } from '../src/hubextensions';
77

88
const mockAddInstrumentationHandler = jest.fn();
99
let mockErrorCallback: () => void = () => undefined;
@@ -19,13 +19,15 @@ jest.mock('@sentry/utils', () => {
1919
if (type === 'unhandledrejection') {
2020
mockUnhandledRejectionCallback = callback;
2121
}
22-
return mockAddInstrumentationHandler({ callback, type });
22+
if (typeof mockAddInstrumentationHandler === 'function') {
23+
return mockAddInstrumentationHandler({ callback, type });
24+
}
2325
},
2426
};
2527
});
2628

2729
beforeAll(() => {
28-
addExtensionMethods();
30+
_addTracingExtensions();
2931
});
3032

3133
describe('registerErrorHandlers()', () => {

0 commit comments

Comments
 (0)