UNPKG

1.95 kBJavaScriptView Raw
1/*
2 * Copyright The OpenTelemetry Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { NoopTracer } from './NoopTracer';
17var NOOP_TRACER = new NoopTracer();
18/**
19 * Proxy tracer provided by the proxy tracer provider
20 */
21var ProxyTracer = /** @class */ (function () {
22 function ProxyTracer(_provider, name, version, options) {
23 this._provider = _provider;
24 this.name = name;
25 this.version = version;
26 this.options = options;
27 }
28 ProxyTracer.prototype.startSpan = function (name, options, context) {
29 return this._getTracer().startSpan(name, options, context);
30 };
31 ProxyTracer.prototype.startActiveSpan = function (_name, _options, _context, _fn) {
32 var tracer = this._getTracer();
33 return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
34 };
35 /**
36 * Try to get a tracer from the proxy tracer provider.
37 * If the proxy tracer provider has no delegate, return a noop tracer.
38 */
39 ProxyTracer.prototype._getTracer = function () {
40 if (this._delegate) {
41 return this._delegate;
42 }
43 var tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
44 if (!tracer) {
45 return NOOP_TRACER;
46 }
47 this._delegate = tracer;
48 return this._delegate;
49 };
50 return ProxyTracer;
51}());
52export { ProxyTracer };
53//# sourceMappingURL=ProxyTracer.js.map
\No newline at end of file