|
| 1 | +import type * as http from 'node:http'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | +import { _getOutgoingRequestEndedSpanData } from '../../src/integrations/http/SentryHttpInstrumentation'; |
| 4 | + |
| 5 | +function createResponse(overrides: Partial<http.IncomingMessage>): http.IncomingMessage { |
| 6 | + return { |
| 7 | + statusCode: 200, |
| 8 | + statusMessage: 'OK', |
| 9 | + httpVersion: '1.1', |
| 10 | + headers: {}, |
| 11 | + socket: undefined, |
| 12 | + ...overrides, |
| 13 | + } as unknown as http.IncomingMessage; |
| 14 | +} |
| 15 | + |
| 16 | +describe('_getOutgoingRequestEndedSpanData', () => { |
| 17 | + it('sets ip_tcp transport for HTTP/1.1', () => { |
| 18 | + const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: '1.1' })); |
| 19 | + |
| 20 | + expect(attributes['network.transport']).toBe('ip_tcp'); |
| 21 | + expect(attributes['net.transport']).toBe('ip_tcp'); |
| 22 | + expect(attributes['network.protocol.version']).toBe('1.1'); |
| 23 | + expect(attributes['http.flavor']).toBe('1.1'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('sets ip_udp transport for QUIC', () => { |
| 27 | + const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: 'QUIC' })); |
| 28 | + |
| 29 | + expect(attributes['network.transport']).toBe('ip_udp'); |
| 30 | + expect(attributes['net.transport']).toBe('ip_udp'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('does not throw when httpVersion is null', () => { |
| 34 | + expect(() => |
| 35 | + _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: null as unknown as string })), |
| 36 | + ).not.toThrow(); |
| 37 | + |
| 38 | + const attributes = _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: null as unknown as string })); |
| 39 | + expect(attributes['network.transport']).toBe('ip_tcp'); |
| 40 | + expect(attributes['net.transport']).toBe('ip_tcp'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('does not throw when httpVersion is undefined', () => { |
| 44 | + expect(() => |
| 45 | + _getOutgoingRequestEndedSpanData(createResponse({ httpVersion: undefined as unknown as string })), |
| 46 | + ).not.toThrow(); |
| 47 | + }); |
| 48 | +}); |
0 commit comments