Skip to content

Commit aa5286e

Browse files
k-fishAbhiPrasad
andauthored
fix(tracing): Change where content-length gets added (#8139)
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
1 parent e52847e commit aa5286e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ export function fetchCallback(
175175
// TODO (kmclb) remove this once types PR goes through
176176
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
177177
span.setHttpStatus(handlerData.response.status);
178+
179+
const contentLength =
180+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
181+
handlerData.response && handlerData.response.headers && handlerData.response.headers.get('content-length');
182+
if (contentLength > 0) {
183+
span.setData('http.response_content_length', contentLength);
184+
}
178185
} else if (handlerData.error) {
179186
span.setStatus('internal_error');
180187
}
@@ -186,9 +193,6 @@ export function fetchCallback(
186193
return;
187194
}
188195

189-
const contentLength =
190-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
191-
handlerData.response && handlerData.response.headers && handlerData.response.headers.get('content-length');
192196
const currentScope = getCurrentHub().getScope();
193197
const currentSpan = currentScope && currentScope.getSpan();
194198
const activeTransaction = currentSpan && currentSpan.transaction;
@@ -199,7 +203,6 @@ export function fetchCallback(
199203
data: {
200204
url,
201205
type: 'fetch',
202-
...(contentLength ? { 'http.response_content_length': contentLength } : {}),
203206
'http.method': method,
204207
},
205208
description: `${method} ${url}`,

0 commit comments

Comments
 (0)