1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { ContextAPI } from '../api/context';
|
17 | import { getSpanContext, setSpan } from '../trace/context-utils';
|
18 | import { NonRecordingSpan } from './NonRecordingSpan';
|
19 | import { isSpanContextValid } from './spancontext-utils';
|
20 | var context = ContextAPI.getInstance();
|
21 |
|
22 |
|
23 |
|
24 | var NoopTracer = (function () {
|
25 | function NoopTracer() {
|
26 | }
|
27 |
|
28 | NoopTracer.prototype.startSpan = function (name, options, context) {
|
29 | var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
30 | if (root) {
|
31 | return new NonRecordingSpan();
|
32 | }
|
33 | var parentFromContext = context && getSpanContext(context);
|
34 | if (isSpanContext(parentFromContext) &&
|
35 | isSpanContextValid(parentFromContext)) {
|
36 | return new NonRecordingSpan(parentFromContext);
|
37 | }
|
38 | else {
|
39 | return new NonRecordingSpan();
|
40 | }
|
41 | };
|
42 | NoopTracer.prototype.startActiveSpan = function (name, arg2, arg3, arg4) {
|
43 | var opts;
|
44 | var ctx;
|
45 | var fn;
|
46 | if (arguments.length < 2) {
|
47 | return;
|
48 | }
|
49 | else if (arguments.length === 2) {
|
50 | fn = arg2;
|
51 | }
|
52 | else if (arguments.length === 3) {
|
53 | opts = arg2;
|
54 | fn = arg3;
|
55 | }
|
56 | else {
|
57 | opts = arg2;
|
58 | ctx = arg3;
|
59 | fn = arg4;
|
60 | }
|
61 | var parentContext = ctx !== null && ctx !== void 0 ? ctx : context.active();
|
62 | var span = this.startSpan(name, opts, parentContext);
|
63 | var contextWithSpanSet = setSpan(parentContext, span);
|
64 | return context.with(contextWithSpanSet, fn, undefined, span);
|
65 | };
|
66 | return NoopTracer;
|
67 | }());
|
68 | export { 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 |