Skip to content

Commit d9e6976

Browse files
authored
fix: Mark span as failed when fetch API call fails (#3351)
1 parent 6587399 commit d9e6976

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/tracing/src/browser/request.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getCurrentHub } from '@sentry/hub';
22
import { addInstrumentationHandler, isInstanceOf, isMatchingPattern } from '@sentry/utils';
33

44
import { Span } from '../span';
5+
import { SpanStatus } from '../spanstatus';
56
import { getActiveTransaction, hasTracingEnabled } from '../utils';
67

78
export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//];
@@ -53,6 +54,7 @@ export interface FetchData {
5354
// TODO Should this be unknown instead? If we vendor types, make it a Response
5455
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5556
response?: any;
57+
error?: unknown;
5658

5759
startTimestamp: number;
5860
endTimestamp?: number;
@@ -156,11 +158,12 @@ export function fetchCallback(
156158
if (handlerData.endTimestamp && handlerData.fetchData.__span) {
157159
const span = spans[handlerData.fetchData.__span];
158160
if (span) {
159-
const response = handlerData.response;
160-
if (response) {
161+
if (handlerData.response) {
161162
// TODO (kmclb) remove this once types PR goes through
162163
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
163-
span.setHttpStatus(response.status);
164+
span.setHttpStatus(handlerData.response.status);
165+
} else if (handlerData.error) {
166+
span.setStatus(SpanStatus.InternalError);
164167
}
165168
span.finish();
166169

0 commit comments

Comments
 (0)