forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
45 lines (36 loc) · 1 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const http = require('http');
const opentracing = require('opentracing');
const shim = require('./shim').shim('http_client_opentracing');
opentracing.initGlobalTracer(shim);
const tracer = opentracing.globalTracer();
makeRequest();
async function makeRequest() {
const span = tracer.startSpan('make_request');
const headers = {};
tracer.inject(span, opentracing.FORMAT_HTTP_HEADERS, headers);
http
.get(
{
host: 'localhost',
port: 3000,
path: '/',
headers,
},
(resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', async () => {
console.log(JSON.parse(data));
span.finish();
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
});
},
)
.on('error', (err) => {
console.log(`Error: ${err.message}`);
});
}