UNPKG

2.91 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright The OpenTelemetry Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.NoopTracer = void 0;
19var context_1 = require("../api/context");
20var context_utils_1 = require("../trace/context-utils");
21var NonRecordingSpan_1 = require("./NonRecordingSpan");
22var spancontext_utils_1 = require("./spancontext-utils");
23var context = context_1.ContextAPI.getInstance();
24/**
25 * No-op implementations of {@link Tracer}.
26 */
27var NoopTracer = /** @class */ (function () {
28 function NoopTracer() {
29 }
30 // startSpan starts a noop span.
31 NoopTracer.prototype.startSpan = function (name, options, context) {
32 var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
33 if (root) {
34 return new NonRecordingSpan_1.NonRecordingSpan();
35 }
36 var parentFromContext = context && context_utils_1.getSpanContext(context);
37 if (isSpanContext(parentFromContext) &&
38 spancontext_utils_1.isSpanContextValid(parentFromContext)) {
39 return new NonRecordingSpan_1.NonRecordingSpan(parentFromContext);
40 }
41 else {
42 return new NonRecordingSpan_1.NonRecordingSpan();
43 }
44 };
45 NoopTracer.prototype.startActiveSpan = function (name, arg2, arg3, arg4) {
46 var opts;
47 var ctx;
48 var fn;
49 if (arguments.length < 2) {
50 return;
51 }
52 else if (arguments.length === 2) {
53 fn = arg2;
54 }
55 else if (arguments.length === 3) {
56 opts = arg2;
57 fn = arg3;
58 }
59 else {
60 opts = arg2;
61 ctx = arg3;
62 fn = arg4;
63 }
64 var parentContext = ctx !== null && ctx !== void 0 ? ctx : context.active();
65 var span = this.startSpan(name, opts, parentContext);
66 var contextWithSpanSet = context_utils_1.setSpan(parentContext, span);
67 return context.with(contextWithSpanSet, fn, undefined, span);
68 };
69 return NoopTracer;
70}());
71exports.NoopTracer = NoopTracer;
72function isSpanContext(spanContext) {
73 return (typeof spanContext === 'object' &&
74 typeof spanContext['spanId'] === 'string' &&
75 typeof spanContext['traceId'] === 'string' &&
76 typeof spanContext['traceFlags'] === 'number');
77}
78//# sourceMappingURL=NoopTracer.js.map
\No newline at end of file