forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
32 lines (27 loc) · 931 Bytes
/
client.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
'use strict';
const tracer = require('./tracer')('postgres-client-service');
// eslint-disable-next-line import/order
const http = require('http');
function makeRequest() {
const span = tracer.startSpan('makeRequest');
const randomId = Math.floor(Math.random() * 10);
tracer.withSpan(span, () => {
console.log('Client traceId ', span.context().traceId);
http.get({
host: 'localhost',
port: 3000,
path: `/insert?id=${randomId}&text=randomstring`,
});
http.get({
host: 'localhost',
port: 3000,
path: `/get?id=${randomId}`,
});
});
// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
}
makeRequest();