UNPKG

3.23 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.TraceAPI = void 0;
19var global_utils_1 = require("../internal/global-utils");
20var ProxyTracerProvider_1 = require("../trace/ProxyTracerProvider");
21var spancontext_utils_1 = require("../trace/spancontext-utils");
22var context_utils_1 = require("../trace/context-utils");
23var diag_1 = require("./diag");
24var API_NAME = 'trace';
25/**
26 * Singleton object which represents the entry point to the OpenTelemetry Tracing API
27 */
28var TraceAPI = /** @class */ (function () {
29 /** Empty private constructor prevents end users from constructing a new instance of the API */
30 function TraceAPI() {
31 this._proxyTracerProvider = new ProxyTracerProvider_1.ProxyTracerProvider();
32 this.wrapSpanContext = spancontext_utils_1.wrapSpanContext;
33 this.isSpanContextValid = spancontext_utils_1.isSpanContextValid;
34 this.deleteSpan = context_utils_1.deleteSpan;
35 this.getSpan = context_utils_1.getSpan;
36 this.getSpanContext = context_utils_1.getSpanContext;
37 this.setSpan = context_utils_1.setSpan;
38 this.setSpanContext = context_utils_1.setSpanContext;
39 }
40 /** Get the singleton instance of the Trace API */
41 TraceAPI.getInstance = function () {
42 if (!this._instance) {
43 this._instance = new TraceAPI();
44 }
45 return this._instance;
46 };
47 /**
48 * Set the current global tracer.
49 *
50 * @returns true if the tracer provider was successfully registered, else false
51 */
52 TraceAPI.prototype.setGlobalTracerProvider = function (provider) {
53 var success = global_utils_1.registerGlobal(API_NAME, this._proxyTracerProvider, diag_1.DiagAPI.instance());
54 if (success) {
55 this._proxyTracerProvider.setDelegate(provider);
56 }
57 return success;
58 };
59 /**
60 * Returns the global tracer provider.
61 */
62 TraceAPI.prototype.getTracerProvider = function () {
63 return global_utils_1.getGlobal(API_NAME) || this._proxyTracerProvider;
64 };
65 /**
66 * Returns a tracer from the global tracer provider.
67 */
68 TraceAPI.prototype.getTracer = function (name, version) {
69 return this.getTracerProvider().getTracer(name, version);
70 };
71 /** Remove the global tracer provider */
72 TraceAPI.prototype.disable = function () {
73 global_utils_1.unregisterGlobal(API_NAME, diag_1.DiagAPI.instance());
74 this._proxyTracerProvider = new ProxyTracerProvider_1.ProxyTracerProvider();
75 };
76 return TraceAPI;
77}());
78exports.TraceAPI = TraceAPI;
79//# sourceMappingURL=trace.js.map
\No newline at end of file