UNPKG

@azure/cosmos

Version:
115 lines (114 loc) 4.41 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var diagnostics_exports = {}; __export(diagnostics_exports, { addDiagnosticChild: () => addDiagnosticChild, getEmptyCosmosDiagnostics: () => getEmptyCosmosDiagnostics, withDiagnostics: () => withDiagnostics, withMetadataDiagnostics: () => withMetadataDiagnostics }); module.exports = __toCommonJS(diagnostics_exports); var import_CosmosDiagnostics = require("../CosmosDiagnostics.js"); var import_DiagnosticNodeInternal = require("../diagnostics/DiagnosticNodeInternal.js"); var import_time = require("./time.js"); var import_CosmosDbDiagnosticLevel = require("../diagnostics/CosmosDbDiagnosticLevel.js"); var import_core_util = require("@azure/core-util"); function getEmptyCosmosDiagnostics() { return new import_CosmosDiagnostics.CosmosDiagnostics( { requestDurationInMs: 0, requestStartTimeUTCInMs: (0, import_time.getCurrentTimestampInMs)(), totalRequestPayloadLengthInBytes: 0, totalResponsePayloadLengthInBytes: 0, locationEndpointsContacted: [], retryDiagnostics: { failedAttempts: [] }, metadataDiagnostics: { metadataLookups: [] }, gatewayStatistics: [] }, { id: (0, import_core_util.randomUUID)(), nodeType: import_DiagnosticNodeInternal.DiagnosticNodeType.CLIENT_REQUEST_NODE, children: [], data: {}, startTimeUTCInMs: (0, import_time.getCurrentTimestampInMs)(), durationInMs: 0 } ); } async function addDiagnosticChild(callback, node, type, data = {}) { const childNode = node.initializeChildNode(type, import_CosmosDbDiagnosticLevel.CosmosDbDiagnosticLevel.debug, data); try { const response = await callback(childNode); childNode.updateTimestamp(); return response; } catch (e) { childNode.addData({ failure: true }); childNode.updateTimestamp(); throw e; } } async function withMetadataDiagnostics(callback, node, type) { const diagnosticNodeForMetadataCall = new import_DiagnosticNodeInternal.DiagnosticNodeInternal( node.diagnosticLevel, import_DiagnosticNodeInternal.DiagnosticNodeType.METADATA_REQUEST_NODE, null ); try { const response = await callback(diagnosticNodeForMetadataCall); node.addChildNode(diagnosticNodeForMetadataCall, import_CosmosDbDiagnosticLevel.CosmosDbDiagnosticLevel.debug, type); return response; } catch (e) { node.addChildNode(diagnosticNodeForMetadataCall, import_CosmosDbDiagnosticLevel.CosmosDbDiagnosticLevel.debug, type); throw e; } } async function withDiagnostics(callback, clientContext, type = import_DiagnosticNodeInternal.DiagnosticNodeType.CLIENT_REQUEST_NODE) { const diagnosticNode = new import_DiagnosticNodeInternal.DiagnosticNodeInternal(clientContext.diagnosticLevel, type, null); try { const response = await callback(diagnosticNode); diagnosticNode.updateTimestamp(); const diagnostics = diagnosticNode.toDiagnostic(clientContext.getClientConfig()); if (typeof response === "object" && response !== null) { response.diagnostics = diagnostics; } clientContext.recordDiagnostics(diagnostics); return response; } catch (e) { diagnosticNode.updateTimestamp(); diagnosticNode.addData({ failure: true }); const diagnostics = diagnosticNode.toDiagnostic(clientContext.getClientConfig()); e.diagnostics = diagnostics; clientContext.recordDiagnostics(diagnostics); throw e; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { addDiagnosticChild, getEmptyCosmosDiagnostics, withDiagnostics, withMetadataDiagnostics });