UNPKG

2.83 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var tracer_1 = require("./tracer");
17var noopTracer = new tracer_1.default();
18var _globalTracer = null;
19// Allows direct importing/requiring of the global tracer:
20//
21// let globalTracer = require('opentracing/global');
22// OR
23// import globalTracer from 'opentracing/global';
24//
25// Acts a bridge to the global tracer that can be safely called before the
26// global tracer is initialized. The purpose of the delegation is to avoid the
27// sometimes nearly intractible initialization order problems that can arise in
28// applications with a complex set of dependencies, while also avoiding the
29// case where
30var GlobalTracerDelegate = /** @class */ (function (_super) {
31 __extends(GlobalTracerDelegate, _super);
32 function GlobalTracerDelegate() {
33 return _super !== null && _super.apply(this, arguments) || this;
34 }
35 GlobalTracerDelegate.prototype.startSpan = function () {
36 var tracer = _globalTracer || noopTracer;
37 return tracer.startSpan.apply(tracer, arguments);
38 };
39 GlobalTracerDelegate.prototype.inject = function () {
40 var tracer = _globalTracer || noopTracer;
41 return tracer.inject.apply(tracer, arguments);
42 };
43 GlobalTracerDelegate.prototype.extract = function () {
44 var tracer = _globalTracer || noopTracer;
45 return tracer.extract.apply(tracer, arguments);
46 };
47 return GlobalTracerDelegate;
48}(tracer_1.default));
49var globalTracerDelegate = new GlobalTracerDelegate();
50/**
51 * Set the global Tracer.
52 *
53 * The behavior is undefined if this function is called more than once.
54 *
55 * @param {Tracer} tracer - the Tracer implementation
56 */
57function initGlobalTracer(tracer) {
58 _globalTracer = tracer;
59}
60exports.initGlobalTracer = initGlobalTracer;
61/**
62 * Returns the global tracer.
63 */
64function globalTracer() {
65 // Return the delegate. Since the global tracer is largely a convenience
66 // (the user can always create their own tracers), the delegate is used to
67 // give the added convenience of not needing to worry about initialization
68 // order.
69 return globalTracerDelegate;
70}
71exports.globalTracer = globalTracer;
72//# sourceMappingURL=global_tracer.js.map
\No newline at end of file