From 6a13d451eff6512e09e562338790caebd36d6fb7 Mon Sep 17 00:00:00 2001 From: Emanuel Lauria Date: Tue, 20 Mar 2018 15:17:29 +0100 Subject: [PATCH] remove old index --- src/index.js.old | 128 ----------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 src/index.js.old diff --git a/src/index.js.old b/src/index.js.old deleted file mode 100644 index c1bb2b4..0000000 --- a/src/index.js.old +++ /dev/null @@ -1,128 +0,0 @@ -(function(w, d) { - - /** - * List of supported Opentracing JS Libraries - */ - const libraries = { - lightstep: { - class: 'lightstep', - src: 'https://rawgit.com/lightstep/lightstep-tracer-javascript/v0.20.3/dist/lightstep-tracer.min.js', - } - }; - - /** - * get current working directory to load getDependencies - */ - let currentPath = () => { - let scripts = Array.from(d.getElementsByTagName("script")); - let ix = scripts.findIndex( - (s) => s.src.indexOf('opentracing-javascript-utils.js') >= 0 - ) - let path = scripts[ix].src.split('opentracing-javascript-utils.js')[0]; - return path - } - - /** - * OpenTracing Tracer loads dependencies and initializes a global - * tracer with specified library implementation; defaults to no-op. - */ - class Tracer { - - constructor() { - this.dependencies = []; - } - - /** - * Load external script and return a Promise - * to be resolved when script is loaded - */ - getScript(url) { - - let head = d.documentElement; - let script = null; - - return new Promise(function(resolve, reject) { - - let s = document.createElement('script'); - s.type = 'text/javascript'; - s.src = url; - s.async = true; - - s.onload = function() { - resolve(url); - } - - s.onerror = function(e, x) { - reject(url); - } - - d.documentElement.appendChild(s); - }); - }; - - /** - * List of dependencies to load sync - */ - getDependencies(lib) { - if (lib && !w[lib.class]) { - this.dependencies.push(lib.src); - } - let d = this.dependencies.map(this.getScript) - return d - } - - /** - * Initializes Global Tracer with Custom library - */ - initGlobalTracer(lib) { - if (lib && w[lib.class]) { - opentracing.initGlobalTracer(new w[lib.class].Tracer(this.config)); - } else { - opentracing.initGlobalTracer(); - } - } - - getTracerPromise(lib, resolve, reject) { - return new Promise((resolve, reject) => { - this.initGlobalTracer(lib) - resolve(opentracing.globalTracer()) - }); - } - - - /** - * Load dependencies and initialize Tracer - */ - initOpenTracing(tracerConfig, resolve, reject) { - - this.name = tracerConfig ? tracerConfig.name : 'opentracing' - this.config = tracerConfig ? tracerConfig.config : {} - - let lib = libraries[this.name]; - - if (this.name !== 'opentracing' && !lib) { - let m = `Unkown Tracing Library: "${this.name}". Currently supported: ${Object.keys(libraries)}`; - console.log(m); - } - - return new Promise((resolve, reject) => { - Promise - .all(this.getDependencies(lib)) - .then( () => { - this.initGlobalTracer(lib) - resolve(opentracing.globalTracer()) - }) - .catch( (e) => { - console.log("Can't load Tracing library, defaulting to no-op.", e) - this.initGlobalTracer() - resolve(opentracing.globalTracer()) - }) - }) - - } - - } - - w.opentracingJavascriptUtils = new Tracer(); - -})(window, document);