forked from yurishkuro/opentracing-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.js
More file actions
42 lines (35 loc) · 1007 Bytes
/
Copy pathhello.js
File metadata and controls
42 lines (35 loc) · 1007 Bytes
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
const assert = require("assert");
const { initTracer } = require("../../lib/tracing");
const tracer = initTracer("hello-world");
const sayHello = helloTo => {
const span = tracer.startSpan("say-hello");
const ctx = { span };
span.setTag("hello-to", helloTo);
const helloStr = formatString(ctx, helloTo);
printHello(ctx, helloStr);
span.finish();
};
const formatString = (ctx, helloTo) => {
ctx = {
span: tracer.startSpan("formatString", { childOf: ctx.span }),
};
const helloStr = `Hello, ${helloTo}!`;
ctx.span.log({
event: "string-format",
value: helloStr,
});
ctx.span.finish();
return helloStr;
};
const printHello = (ctx, helloStr) => {
ctx = {
span: tracer.startSpan("printHello", { childOf: ctx.span }),
};
console.log(helloStr);
ctx.span.log({ event: "print-string" });
ctx.span.finish();
};
assert(process.argv.length == 3, "Expecting one argument");
const helloTo = process.argv[2];
sayHello(helloTo);
tracer.close(() => process.exit());