diff --git a/packages/deno/src/wrap-deno-request-handler.ts b/packages/deno/src/wrap-deno-request-handler.ts index 886b5a6d67ed..510b903dc722 100644 --- a/packages/deno/src/wrap-deno-request-handler.ts +++ b/packages/deno/src/wrap-deno-request-handler.ts @@ -73,10 +73,7 @@ export const wrapDenoRequestHandler = ( assignIfSet(attributes, 'client.port', (info?.remoteAddr as Deno.NetAddr)?.port); } - Object.assign( - attributes, - httpHeadersToSpanAttributes(winterCGHeadersToDict(request.headers), client.getOptions().sendDefaultPii ?? false), - ); + Object.assign(attributes, httpHeadersToSpanAttributes(winterCGHeadersToDict(request.headers), sendDefaultPii)); attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server'; isolationScope.setSDKProcessingMetadata({ normalizedRequest: winterCGRequestToRequestData(request), @@ -95,9 +92,11 @@ export const wrapDenoRequestHandler = ( res = await handler(); setHttpStatus(span, res.status); isolationScope.setContext('response', { - headers: Object.fromEntries(res.headers), status_code: res.status, }); + span.setAttributes( + httpHeadersToSpanAttributes(Object.fromEntries(res.headers), sendDefaultPii, 'response'), + ); } catch (e) { span.end(); captureException(e, { diff --git a/packages/deno/test/deno-serve.test.ts b/packages/deno/test/deno-serve.test.ts index 9c2283e365b4..6f76ce2781ab 100644 --- a/packages/deno/test/deno-serve.test.ts +++ b/packages/deno/test/deno-serve.test.ts @@ -317,9 +317,8 @@ Deno.test('Deno.serve should capture request headers and set response context', // Check response context assertEquals(transaction?.contexts?.response?.status_code, 201); - assertExists(transaction?.contexts?.response?.headers); - assertEquals(transaction?.contexts?.response?.headers?.['content-type'], 'text/plain'); - assertEquals(transaction?.contexts?.response?.headers?.['x-custom-header'], 'test'); + assertEquals(transaction?.contexts?.trace?.data?.['http.response.header.content_type'], 'text/plain'); + assertEquals(transaction?.contexts?.trace?.data?.['http.response.header.x_custom_header'], 'test'); }); Deno.test('Deno.serve should support distributed tracing with sentry-trace header', async () => {