This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
http.integration.test.js
157 lines (131 loc) · 6.54 KB
/
http.integration.test.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import HttpIntegration from '../../dist/plugins/integrations/HttpIntegration';
import ThundraTracer from '../../dist/opentracing/Tracer';
import Http from './utils/http.integration.utils';
import InvocationSupport from '../../dist/plugins/support/InvocationSupport';
describe('HTTP integration', () => {
test('should instrument HTTP GET calls ', () => {
const integration = new HttpIntegration({
httpPathDepth: 2,
});
const sdk = require('http');
const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');
return Http.get(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
expect(span.operationName).toBe('jsonplaceholder.typicode.com/users/1');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
expect(span.tags['operation.type']).toBe('GET');
expect(span.tags['http.method']).toBe('GET');
expect(span.tags['http.host']).toBe('jsonplaceholder.typicode.com');
expect(span.tags['http.path']).toBe('/users/1');
expect(span.tags['http.url']).toBe('jsonplaceholder.typicode.com/users/1?q=123');
expect(span.tags['http.query_params']).toBe('q=123');
expect(span.tags['http.status_code']).toBe(200);
expect(span.tags['topology.vertex']).toEqual(true);
expect(span.tags['trigger.domainName']).toEqual('API');
expect(span.tags['trigger.className']).toEqual('AWS-Lambda');
expect(span.tags['trigger.operationNames']).toEqual(['functionName']);
expect(span.tags['http.body']).not.toBeTruthy();
});
});
test('should set 4XX 5XX errors on HTTP calls', () => {
const integration = new HttpIntegration({
httpPathDepth: 2,
});
const sdk = require('http');
const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');
return Http.getError(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
console.log(span);
expect(span.operationName).toBe('httpstat.us/404');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
expect(span.tags['operation.type']).toBe('GET');
expect(span.tags['http.method']).toBe('GET');
expect(span.tags['http.host']).toBe('httpstat.us');
expect(span.tags['http.path']).toBe('/404');
expect(span.tags['http.url']).toBe('httpstat.us/404');
expect(span.tags['http.status_code']).toBe(404);
expect(span.tags['error']).toBe(true);
expect(span.tags['error.kind']).toBe('HttpError');
expect(span.tags['error.message']).toBe('Not Found');
expect(span.tags['topology.vertex']).toEqual(true);
expect(span.tags['trigger.domainName']).toEqual('API');
expect(span.tags['trigger.className']).toEqual('AWS-Lambda');
expect(span.tags['trigger.operationNames']).toEqual(['functionName']);
expect(span.tags['http.body']).not.toBeTruthy();
});
});
test('should disable 4XX 5XX errors on HTTP calls', () => {
const integration = new HttpIntegration({
httpPathDepth: 2,
disableHttp4xxError:true
});
const sdk = require('http');
const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');
return Http.getError(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
console.log(span);
expect(span.operationName).toBe('httpstat.us/404');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
expect(span.tags['operation.type']).toBe('GET');
expect(span.tags['http.method']).toBe('GET');
expect(span.tags['http.host']).toBe('httpstat.us');
expect(span.tags['http.path']).toBe('/404');
expect(span.tags['http.url']).toBe('httpstat.us/404');
expect(span.tags['http.status_code']).toBe(404);
expect(span.tags['error']).toBe(undefined);
expect(span.tags['error.kind']).toBe(undefined);
expect(span.tags['error.message']).toBe(undefined);
expect(span.tags['topology.vertex']).toEqual(true);
expect(span.tags['trigger.domainName']).toEqual('API');
expect(span.tags['trigger.className']).toEqual('AWS-Lambda');
expect(span.tags['trigger.operationNames']).toEqual(['functionName']);
expect(span.tags['http.body']).not.toBeTruthy();
});
});
test('should instrument HTTPS POST calls', () => {
const integration = new HttpIntegration({
httpPathDepth: 0,
});
const sdk = require('https');
const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');
return Http.post(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
expect(span.operationName).toBe('flaviocopes.com');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
expect(span.tags['http.method']).toBe('POST');
expect(span.tags['http.body']).toBe('{"todo":"Buy the milk"}');
});
});
test('should mask body in post', () => {
const integration = new HttpIntegration({
maskHttpBody: true
});
const sdk = require('https');
const tracer = new ThundraTracer();
InvocationSupport.setFunctionName('functionName');
return Http.post(sdk).then(() => {
const span = tracer.getRecorder().spanList[0];
expect(span.operationName).toBe('flaviocopes.com/todos');
expect(span.className).toBe('HTTP');
expect(span.domainName).toBe('API');
expect(span.tags['http.method']).toBe('POST');
expect(span.tags['http.body']).not.toBeTruthy();
});
});
test('should instrument api gateway calls ', () => {
const apiGatewayEndpoint = 'hivcx7cj2j.execute-api.us-west-2.amazonaws.com/dev';
const okEndpoint = 'google.com';
const awsEndPoint = 'dynamodb.us-west-2.amazonaws.com';
expect(HttpIntegration.isValidUrl(apiGatewayEndpoint)).toBe(true);
expect(HttpIntegration.isValidUrl(awsEndPoint)).toBe(false);
expect(HttpIntegration.isValidUrl(okEndpoint)).toBe(true);
});
});