Skip to content

Commit

Permalink
fix(tracing): Change where content-length gets added (#8139)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
  • Loading branch information
k-fish and AbhiPrasad committed May 17, 2023
1 parent e52847e commit aa5286e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/tracing-internal/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export function fetchCallback(
// TODO (kmclb) remove this once types PR goes through
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
span.setHttpStatus(handlerData.response.status);

const contentLength =
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
handlerData.response && handlerData.response.headers && handlerData.response.headers.get('content-length');
if (contentLength > 0) {
span.setData('http.response_content_length', contentLength);
}
} else if (handlerData.error) {
span.setStatus('internal_error');
}
Expand All @@ -186,9 +193,6 @@ export function fetchCallback(
return;
}

const contentLength =
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
handlerData.response && handlerData.response.headers && handlerData.response.headers.get('content-length');
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;
Expand All @@ -199,7 +203,6 @@ export function fetchCallback(
data: {
url,
type: 'fetch',
...(contentLength ? { 'http.response_content_length': contentLength } : {}),
'http.method': method,
},
description: `${method} ${url}`,
Expand Down

0 comments on commit aa5286e

Please sign in to comment.