1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.NoopTracer = void 0;
|
19 | const context_1 = require("../api/context");
|
20 | const context_utils_1 = require("../trace/context-utils");
|
21 | const NonRecordingSpan_1 = require("./NonRecordingSpan");
|
22 | const spancontext_utils_1 = require("./spancontext-utils");
|
23 | const contextApi = context_1.ContextAPI.getInstance();
|
24 |
|
25 |
|
26 |
|
27 | class NoopTracer {
|
28 |
|
29 | startSpan(name, options, context = contextApi.active()) {
|
30 | const root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
31 | if (root) {
|
32 | return new NonRecordingSpan_1.NonRecordingSpan();
|
33 | }
|
34 | const parentFromContext = context && (0, context_utils_1.getSpanContext)(context);
|
35 | if (isSpanContext(parentFromContext) &&
|
36 | (0, spancontext_utils_1.isSpanContextValid)(parentFromContext)) {
|
37 | return new NonRecordingSpan_1.NonRecordingSpan(parentFromContext);
|
38 | }
|
39 | else {
|
40 | return new NonRecordingSpan_1.NonRecordingSpan();
|
41 | }
|
42 | }
|
43 | startActiveSpan(name, arg2, arg3, arg4) {
|
44 | let opts;
|
45 | let ctx;
|
46 | let fn;
|
47 | if (arguments.length < 2) {
|
48 | return;
|
49 | }
|
50 | else if (arguments.length === 2) {
|
51 | fn = arg2;
|
52 | }
|
53 | else if (arguments.length === 3) {
|
54 | opts = arg2;
|
55 | fn = arg3;
|
56 | }
|
57 | else {
|
58 | opts = arg2;
|
59 | ctx = arg3;
|
60 | fn = arg4;
|
61 | }
|
62 | const parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
63 | const span = this.startSpan(name, opts, parentContext);
|
64 | const contextWithSpanSet = (0, context_utils_1.setSpan)(parentContext, span);
|
65 | return contextApi.with(contextWithSpanSet, fn, undefined, span);
|
66 | }
|
67 | }
|
68 | exports.NoopTracer = NoopTracer;
|
69 | function isSpanContext(spanContext) {
|
70 | return (typeof spanContext === 'object' &&
|
71 | typeof spanContext['spanId'] === 'string' &&
|
72 | typeof spanContext['traceId'] === 'string' &&
|
73 | typeof spanContext['traceFlags'] === 'number');
|
74 | }
|
75 |
|
\ | No newline at end of file |