-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathSentryHttpInstrumentation.test.ts
More file actions
48 lines (40 loc) · 1.78 KB
/
SentryHttpInstrumentation.test.ts
File metadata and controls
48 lines (40 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type * as http from 'node:http';
import { describe, expect, it } from 'vitest';
import { _getOutgoingRequestEndedSpanData } from '../../src/integrations/http/SentryHttpInstrumentation';
function createResponse(overrides: Partial<http.IncomingMessage>): http.IncomingMessage {
return {
statusCode: 200,
statusMessage: 'OK',
httpVersion: '1.1',
headers: {},
socket: undefined,
...overrides,
} as unknown as http.IncomingMessage;
}
describe('_getOutgoingRequestEndedSpanData', () => {
it('sets ip_tcp transport for HTTP/1.1', () => {
const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: '1.1' }));
expect(attributes['network.transport']).toBe('ip_tcp');
expect(attributes['net.transport']).toBe('ip_tcp');
expect(attributes['network.protocol.version']).toBe('1.1');
expect(attributes['http.flavor']).toBe('1.1');
});
it('sets ip_udp transport for QUIC', () => {
const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: 'QUIC' }));
expect(attributes['network.transport']).toBe('ip_udp');
expect(attributes['net.transport']).toBe('ip_udp');
});
it('does not throw when httpVersion is null', () => {
expect(() =>
_getOutgoingRequestEndedSpanData(createResponse({ httpVersion: null as unknown as string })),
).not.toThrow();
const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: null as unknown as string }));
expect(attributes['network.transport']).toBe('ip_tcp');
expect(attributes['net.transport']).toBe('ip_tcp');
});
it('does not throw when httpVersion is undefined', () => {
expect(() =>
_getOutgoingRequestEndedSpanData(createResponse({ httpVersion: undefined as unknown as string })),
).not.toThrow();
});
});