UNPKG

@finos/legend-shared

Version:
72 lines 2.42 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { AbstractPlugin, } from '../application/AbstractPluginManager.js'; export var CORE_TRACER_TAG; (function (CORE_TRACER_TAG) { CORE_TRACER_TAG["USER"] = "user"; CORE_TRACER_TAG["ENV"] = "env"; CORE_TRACER_TAG["RESULT"] = "result"; CORE_TRACER_TAG["ERROR"] = "error"; CORE_TRACER_TAG["HTTP_STATUS"] = "status"; CORE_TRACER_TAG["HTTP_REQUEST_METHOD"] = "method"; CORE_TRACER_TAG["HTTP_REQUEST_URL"] = "url"; })(CORE_TRACER_TAG || (CORE_TRACER_TAG = {})); export class TracerServicePlugin extends AbstractPlugin { install(pluginManager) { pluginManager.registerTracerServicePlugin(this); } } export class Trace { traceEntries = []; setup(traceEntries) { this.traceEntries = traceEntries; } bootstrap(response) { this.traceEntries.forEach((entry) => { entry.plugin.bootstrap(entry.clientSpan, response); }); } reportSuccess() { this.traceEntries.forEach((entry) => { entry.plugin.concludeClientSpan(entry.clientSpan, undefined); }); } reportError(error) { this.traceEntries.forEach((entry) => { entry.plugin.concludeClientSpan(entry.clientSpan, error); }); } } export class TracerService { plugins = []; registerPlugins(plugins) { this.plugins = plugins; } createTrace(traceData, method, url, headers) { const trace = new Trace(); if (traceData) { trace.setup(this.plugins.map((plugin) => { const clientSpan = plugin.createClientSpan(traceData, method, url, headers); return { clientSpan, plugin, }; })); } return trace; } } //# sourceMappingURL=TracerService.js.map