UNPKG

javascript-typescript-langserver

Version:

Implementation of the Language Server Protocol for JavaScript and TypeScript

91 lines 3.55 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const rxjs_1 = require("rxjs"); /** * Traces a synchronous function by passing it a new child span. * The span is finished when the function returns. * If the function throws an Error, it is logged and the `error` tag set. * * @param operationName The operation name for the new span * @param childOf The parent span * @param operation The function to call */ function traceSync(operationName, childOf, operation) { const span = childOf.tracer().startSpan(operationName, { childOf }); try { return operation(span); } catch (err) { span.setTag('error', true); span.log({ event: 'error', 'error.object': err, stack: err.stack, message: err.message }); throw err; } finally { span.finish(); } } exports.traceSync = traceSync; /** * Traces a Promise-returning (or async) function by passing it a new child span. * The span is finished when the Promise is resolved. * If the Promise is rejected, the Error is logged and the `error` tag set. * * @param operationName The operation name for the new span * @param childOf The parent span * @param operation The function to call */ function tracePromise(operationName, childOf, operation) { return __awaiter(this, void 0, void 0, function* () { const span = childOf.tracer().startSpan(operationName, { childOf }); try { return yield operation(span); } catch (err) { span.setTag('error', true); span.log({ event: 'error', 'error.object': err, stack: err.stack, message: err.message }); throw err; } finally { span.finish(); } }); } exports.tracePromise = tracePromise; /** * Traces an Observable-returning function by passing it a new child span. * The span is finished when the Observable completes or is unsubscribed from. * If the Observable errors or the function throws an Error, the Error is logged and the `error` tag set. * * @param operationName The operation name for the new span * @param childOf The parent span * @param operation The function to call */ function traceObservable(operationName, childOf, operation) { const span = childOf.tracer().startSpan(operationName, { childOf }); try { return operation(span) .do(undefined, err => { span.setTag('error', true); span.log({ event: 'error', 'error.object': err, stack: err.stack, message: err.message }); }) .finally(() => { span.finish(); }); } catch (err) { span.setTag('error', true); span.log({ event: 'error', 'error.object': err, stack: err.stack, message: err.message }); span.finish(); return rxjs_1.Observable.throw(err); } } exports.traceObservable = traceObservable; //# sourceMappingURL=tracing.js.map