UNPKG

@itwin/core-backend

Version:
45 lines 2.64 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module RpcInterface */ Object.defineProperty(exports, "__esModule", { value: true }); exports.WebAppRpcLoggingBackend = void 0; const core_bentley_1 = require("@itwin/core-bentley"); const core_common_1 = require("@itwin/core-common"); const os = require("os"); /* eslint-disable @typescript-eslint/no-deprecated */ class WebAppRpcLoggingBackend extends core_common_1.WebAppRpcLogging { async logProtocolEvent(event, object) { switch (event) { case core_common_1.RpcProtocolEvent.RequestReceived: return this.logRequest(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, "RpcInterface.backend.request", object.request); case core_common_1.RpcProtocolEvent.BackendErrorOccurred: return this.logErrorBackend("RpcInterface.backend.error", object); case core_common_1.RpcProtocolEvent.BackendResponseCreated: return this.logResponse(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, "RpcInterface.backend.response", object.request, object.status, object.elapsed); } } getHostname() { return os.hostname(); } async logErrorBackend(message, invocation) { const operationDescriptor = this.buildOperationDescriptor(invocation.operation); const pathIds = this.findPathIds(invocation.request.path); const result = await invocation.result; const errorMessage = result.message ? result.message : result.objects; // Can be an error or an RpcSerializedValue const metadata = { method: invocation.request.method, path: invocation.request.path, status: invocation.status, errorMessage, // Alert! The following properties are required by Bentley DevOps standards. Do not change their names! ActivityId: invocation.request.id, // eslint-disable-line @typescript-eslint/naming-convention MachineName: this.getHostname(), // eslint-disable-line @typescript-eslint/naming-convention ...pathIds, }; core_bentley_1.Logger.logError(core_common_1.CommonLoggerCategory.RpcInterfaceBackend, `${message}.${operationDescriptor}`, metadata); } } exports.WebAppRpcLoggingBackend = WebAppRpcLoggingBackend; //# sourceMappingURL=logging.js.map