-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest-otel-basic.js
More file actions
85 lines (76 loc) · 2.4 KB
/
test-otel-basic.js
File metadata and controls
85 lines (76 loc) · 2.4 KB
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
// Flags: --dns-result-order=ipv4first
'use strict';
// Test the Tracer.startSpan() and Span interfaces with a single span.
const common = require('../../common');
const assert = require('assert');
const { checkTracesOnExit } = require('../../common/nsolid-traces');
const { setupNSolid } = require('./utils');
const { fixturesDir } = require('../../common/fixtures');
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const binding = require(bindingPath);
const nsolid = require('nsolid');
const api = require(require.resolve('@opentelemetry/api',
{ paths: [fixturesDir] }));
const expectedTraces = [
{
attributes: {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
latin1: 'Espa\u00f1a',
},
events: [
{
name: 'my_event 1',
},
{
attributes: {
attr1: 'val1',
attr2: 'val2',
},
name: 'my_event 2',
},
{
attributes: {
'exception.message': 'my_exception',
'exception.type': 'Error',
},
name: 'exception',
},
],
end_reason: binding.kSpanEndOk,
name: 'my name',
parentId: '0000000000000000',
thread_id: 0,
kind: binding.kClient,
type: binding.kSpanCustom,
status: {
code: api.SpanStatusCode.OK,
},
},
];
checkTracesOnExit(binding, expectedTraces);
setupNSolid(common.mustCall(() => {
if (!nsolid.otel.register(api)) {
throw new Error('Error registering api');
}
const tracer = api.trace.getTracer('test');
const span = tracer.startSpan('initial_name', { attributes: { a: 1, b: 2 },
kind: api.SpanKind.CLIENT });
assert.strictEqual(span.updateName('my name'), span);
assert.strictEqual(span.setAttributes({ c: 3, d: 4 }), span);
assert.strictEqual(span.setAttribute('e', 5), span);
assert.strictEqual(span.setAttribute('latin1', 'Espa\u00f1a'), span);
assert.strictEqual(span.addEvent('my_event 1', Date.now()), span);
assert.strictEqual(
span.addEvent('my_event 2', { attr1: 'val1', attr2: 'val2' }, Date.now()),
span);
span.recordException(new Error('my_exception'));
span.setStatus({ code: api.SpanStatusCode.OK });
span.setStatus({ code: api.SpanStatusCode.ERROR, message: 'my_message' });
span.end();
// Give a little time to reach out to the nsolid thread.
setTimeout(() => {}, 100);
}));