From dd4d05b44e3c2bff7977c5b8905a199cbd52b363 Mon Sep 17 00:00:00 2001 From: Brett Beutell Date: Thu, 29 Aug 2024 07:29:34 +0200 Subject: [PATCH] Use integers in span attributes again --- packages/client-library-otel/src/utils/request.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/client-library-otel/src/utils/request.ts b/packages/client-library-otel/src/utils/request.ts index 4fca2fb01..fefa1f118 100644 --- a/packages/client-library-otel/src/utils/request.ts +++ b/packages/client-library-otel/src/utils/request.ts @@ -271,7 +271,7 @@ export async function getResponseAttributes( response: GlobalResponse | HonoResponse, ) { const attributes: Attributes = { - [EXTRA_SEMATTRS_HTTP_RESPONSE_STATUS_CODE]: String(response.status), + [EXTRA_SEMATTRS_HTTP_RESPONSE_STATUS_CODE]: response.status, [SEMATTRS_HTTP_SCHEME]: response.url.split(":")[0], }; @@ -283,7 +283,14 @@ export async function getResponseAttributes( const contentLength = response.headers.get("content-length"); if (contentLength) { - attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH] = contentLength; + try { + attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH] = Number.parseInt( + contentLength, + 10, + ); + } catch { + // ignore errors + } } const headers = response.headers;