Repository navigation
feat(deno): Record request sessions for Deno.serve
#25496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
isaacs
merged 1 commit into
isaacschlueter/js-3955-deno-denoserveintegration-lacks-the-incoming-request-options
from
isaacschlueter/js-3956-deno-denoserve-does-not-record-request-sessions
Oct 19, 2026
+390
−19
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
packages/core/test/lib/integrations/http/record-request-session.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { EventEmitter } from 'node:events'; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { recordRequestSession, startRequestSession } from '../../../../src/integrations/http/record-request-session'; | ||
| import { Scope } from '../../../../src/scope'; | ||
| import { getDefaultTestClientOptions, TestClient } from '../../../mocks/client'; | ||
|
|
||
| function createTestClient(): TestClient { | ||
| return new TestClient(getDefaultTestClientOptions({ release: '1.0.0' })); | ||
| } | ||
|
|
||
| describe('startRequestSession()', () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date('March 19, 1999 06:12:34 UTC')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it('counts the session when end() is called', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
| const requestIsolationScope = new Scope(); | ||
|
|
||
| const end = startRequestSession(client, { requestIsolationScope }); | ||
| vi.runAllTimers(); | ||
| expect(sendSessionSpy).not.toHaveBeenCalled(); | ||
|
|
||
| end(); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(sendSessionSpy).toHaveBeenCalledWith({ | ||
| aggregates: [{ crashed: 0, errored: 0, exited: 1, started: '1999-03-19T06:12:00.000Z' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('counts the status set on the request isolation scope before end()', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
| const requestIsolationScope = new Scope(); | ||
|
|
||
| const end = startRequestSession(client, { requestIsolationScope }); | ||
| requestIsolationScope.getScopeData().sdkProcessingMetadata.requestSession!.status = 'crashed'; | ||
| end(); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(sendSessionSpy).toHaveBeenCalledWith({ | ||
| aggregates: [{ crashed: 1, errored: 0, exited: 0, started: '1999-03-19T06:12:00.000Z' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('counts a session once when end() is called more than once', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
| const requestIsolationScope = new Scope(); | ||
|
|
||
| const end = startRequestSession(client, { requestIsolationScope }); | ||
| end(); | ||
| end(); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(sendSessionSpy).toHaveBeenCalledTimes(1); | ||
| expect(sendSessionSpy).toHaveBeenCalledWith({ | ||
| aggregates: [{ crashed: 0, errored: 0, exited: 1, started: '1999-03-19T06:12:00.000Z' }], | ||
| }); | ||
| }); | ||
|
|
||
| it('emits the "startRequestSession" hook when the session starts', () => { | ||
| const client = createTestClient(); | ||
| const onStartRequestSession = vi.fn(); | ||
| client.on('startRequestSession', onStartRequestSession); | ||
|
|
||
| startRequestSession(client, { requestIsolationScope: new Scope() }); | ||
|
|
||
| expect(onStartRequestSession).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('uses sessionFlushingDelayMS to schedule the aggregate', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
|
|
||
| startRequestSession(client, { requestIsolationScope: new Scope(), sessionFlushingDelayMS: 1_000 })(); | ||
|
|
||
| vi.advanceTimersByTime(999); | ||
| expect(sendSessionSpy).not.toHaveBeenCalled(); | ||
| vi.advanceTimersByTime(1); | ||
| expect(sendSessionSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| it('sends the aggregate after 60 seconds by default', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
|
|
||
| startRequestSession(client, { requestIsolationScope: new Scope() })(); | ||
|
|
||
| vi.advanceTimersByTime(59_999); | ||
| expect(sendSessionSpy).not.toHaveBeenCalled(); | ||
| vi.advanceTimersByTime(1); | ||
| expect(sendSessionSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('recordRequestSession()', () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date('March 19, 1999 06:12:34 UTC')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it('counts the session when the response emits close', () => { | ||
| const client = createTestClient(); | ||
| const sendSessionSpy = vi.spyOn(client, 'sendSession'); | ||
| const response = Object.assign(new EventEmitter(), { statusCode: 200, headers: {} }); | ||
|
|
||
| recordRequestSession(client, { requestIsolationScope: new Scope(), response }); | ||
| vi.runAllTimers(); | ||
| expect(sendSessionSpy).not.toHaveBeenCalled(); | ||
|
|
||
| response.emit('close'); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(sendSessionSpy).toHaveBeenCalledWith({ | ||
| aggregates: [{ crashed: 0, errored: 0, exited: 1, started: '1999-03-19T06:12:00.000Z' }], | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.