-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
36 lines (32 loc) · 1.18 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
'use strict';
const api = require('@opentelemetry/api');
const tracer = require('./tracer')('example-https-client');
// eslint-disable-next-line import/order
const https = require('https');
/** A function which makes requests and handles response. */
function makeRequest() {
// span corresponds to outgoing requests. Here, we have manually created
// the span, which is created to track work that happens outside of the
// request lifecycle entirely.
const span = tracer.startSpan('makeRequest');
api.context.with(api.setSpan(api.context.active(), span), () => {
https.get({
host: 'localhost',
port: 443,
path: '/helloworld',
}, (response) => {
const body = [];
response.on('data', (chunk) => body.push(chunk));
response.on('end', () => {
console.log(body.toString());
span.end();
});
});
});
// 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();