|
1 | 1 | // <reference lib="deno.ns" /> |
2 | 2 |
|
3 | 3 | 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'; |
6 | 6 | import { assert } from 'https://deno.land/std@0.212.0/assert/assert.ts'; |
7 | 7 | import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; |
8 | 8 | import { assertExists } from 'https://deno.land/std@0.212.0/assert/assert_exists.ts'; |
9 | 9 | import type { DenoClient } from '../build/esm/index.js'; |
10 | 10 | import { init, startSpan } from '../build/esm/index.js'; |
| 11 | +import { makeTestTransport } from './transport.ts'; |
11 | 12 |
|
12 | 13 | function resetGlobals(): void { |
13 | 14 | getMainCarrier().__SENTRY__ = undefined; |
@@ -110,6 +111,52 @@ Deno.test({ |
110 | 111 | }, |
111 | 112 | }); |
112 | 113 |
|
| 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 | + |
113 | 160 | Deno.test({ |
114 | 161 | name: 'denoHttpIntegration: node:http outgoing request creates a child http.client span', |
115 | 162 | async fn() { |
|
0 commit comments