Skip to content

Commit 71f66dc

Browse files
AG0708codex
andcommitted
fix(deno): Enable sessions for HTTP requests
Deno disabled release-health sessions for incoming node:http requests even though the shared HTTP instrumentation defaults them on. Preserve the shared default and cover it with a real request regression test. Co-Authored-By: OpenAI Codex <codex@openai.com> Signed-off-by: Abhinav Gorrepati <gorrepatiabhinav1@gmail.com>
1 parent e721a37 commit 71f66dc

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

packages/deno/src/integrations/http.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ const _denoHttpIntegration = ((options: DenoHttpIntegrationOptions = {}) => {
104104
onSpanCreated: options.onIncomingSpanCreated,
105105
onSpanEnd: options.onIncomingSpanEnd,
106106
errorMonitor,
107-
sessions: false,
108107
});
109108
subscribe(HTTP_ON_SERVER_REQUEST, onHttpServerRequest);
110109

packages/deno/test/deno-http.test.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// <reference lib="deno.ns" />
22

33
import * as http from 'node:http';
4-
import type { TransactionEvent } from '@sentry/core';
5-
import { getMainCarrier } from '@sentry/core';
4+
import type { Envelope, SessionAggregates, TransactionEvent } from '@sentry/core';
5+
import { forEachEnvelopeItem, getMainCarrier } from '@sentry/core';
66
import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts';
77
import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts';
88
import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts';
99
import type { DenoClient } from '../build/esm/index.js';
1010
import { init, startSpan } from '../build/esm/index.js';
11+
import { makeTestTransport } from './transport.ts';
1112

1213
function resetGlobals(): void {
1314
getMainCarrier().__SENTRY__ = undefined;
@@ -110,6 +111,52 @@ Deno.test({
110111
},
111112
});
112113

114+
Deno.test({
115+
name: 'denoHttpIntegration: node:http incoming request records a release-health session',
116+
async fn() {
117+
resetGlobals();
118+
const envelopes: Envelope[] = [];
119+
const client = init({
120+
dsn: 'https://username@domain/123',
121+
release: '1.0.0',
122+
transport: makeTestTransport(envelope => {
123+
envelopes.push(envelope);
124+
}),
125+
});
126+
127+
const server = http.createServer((_req, res) => {
128+
res.end('ok');
129+
});
130+
const port: number = await new Promise(resolve => {
131+
server.listen(0, '127.0.0.1', () => {
132+
resolve((server.address() as { port: number }).port);
133+
});
134+
});
135+
136+
const response = await fetch(`http://127.0.0.1:${port}/health`);
137+
assertEquals(await response.text(), 'ok');
138+
await new Promise<void>(resolve => server.close(() => resolve()));
139+
await client.flush(2_000);
140+
141+
let sessionAggregates: SessionAggregates | undefined;
142+
for (const envelope of envelopes) {
143+
forEachEnvelopeItem(envelope, item => {
144+
const [headers, body] = item;
145+
if (headers.type === 'sessions') {
146+
sessionAggregates = body as SessionAggregates;
147+
}
148+
});
149+
}
150+
151+
assertExists(sessionAggregates);
152+
assertEquals(sessionAggregates.attrs?.release, '1.0.0');
153+
assertEquals(sessionAggregates.aggregates.length, 1);
154+
assertEquals(sessionAggregates.aggregates[0]?.exited, 1);
155+
assertEquals(sessionAggregates.aggregates[0]?.errored, 0);
156+
assertEquals(sessionAggregates.aggregates[0]?.crashed, 0);
157+
},
158+
});
159+
113160
Deno.test({
114161
name: 'denoHttpIntegration: node:http outgoing request creates a child http.client span',
115162
async fn() {

0 commit comments

Comments
 (0)