forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
34 lines (30 loc) · 1.08 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
'use strict';
const tracer = require('./tracer')('example-dns');
// eslint-disable-next-line import/order
const dns = require('dns').promises;
/** A function which makes a dns lookup and handles response. */
function makeLookup() {
// span corresponds to dns lookup. Here, we have manually created
// the span, which is created to track work that happens outside of the
// dns lookup query.
const span = tracer.startSpan('dnsLookup');
tracer.withSpan(span, async () => {
try {
await dns.lookup('montreal.ca');
} catch (error) {
span.setAttributes({
'error.name': error.name,
'error.message': error.message,
});
} finally {
console.log(`traceid: ${span.context().traceId}`);
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);
}
makeLookup();