mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
1 line
11 KiB
JSON
1 line
11 KiB
JSON
|
|
{"ast":null,"code":"import { dropUndefinedKeys } from '@sentry/utils';\nimport { getCurrentHub } from './hub.js';\n\n/**\n * @inheritdoc\n */\nclass SessionFlusher {\n __init() {\n this.flushTimeout = 60;\n }\n __init2() {\n this._pendingAggregates = {};\n }\n __init3() {\n this._isEnabled = true;\n }\n constructor(client, attrs) {\n ;\n SessionFlusher.prototype.__init.call(this);\n SessionFlusher.prototype.__init2.call(this);\n SessionFlusher.prototype.__init3.call(this);\n this._client = client;\n // Call to setInterval, so that flush is called every 60 seconds\n this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);\n this._sessionAttrs = attrs;\n }\n\n /** Checks if `pendingAggregates` has entries, and if it does flushes them by calling `sendSession` */\n flush() {\n var sessionAggregates = this.getSessionAggregates();\n if (sessionAggregates.aggregates.length === 0) {\n return;\n }\n this._pendingAggregates = {};\n this._client.sendSession(sessionAggregates);\n }\n\n /** Massages the entries in `pendingAggregates` and returns aggregated sessions */\n getSessionAggregates() {\n var aggregates = Object.keys(this._pendingAggregates).map(key => {\n return this._pendingAggregates[parseInt(key)];\n });\n var sessionAggregates = {\n attrs: this._sessionAttrs,\n aggregates\n };\n return dropUndefinedKeys(sessionAggregates);\n }\n\n /** JSDoc */\n close() {\n clearInterval(this._intervalId);\n this._isEnabled = false;\n this.flush();\n }\n\n /**\n * Wrapper function for _incrementSessionStatusCount that checks if the instance of SessionFlusher is enabled then\n * fetches the session status of the request from `Scope.getRequestSession().status` on the scope and passes them to\n * `_incrementSessionStatusCount` along with the start date\n */\n incrementSessionStatusCount() {\n if (!this._isEnabled) {\n return;\n }\n var scope = getCurrentHub().getScope();\n var requestSession = scope && scope.getRequestSession();\n if (requestSession && requestSession.status) {\n this._incrementSessionStatusCount(requestSession.status, new Date());\n // This is not entirely necessarily but is added as a safe guard to indicate the bounds of a request and so in\n // case captureRequestSession is called more than once to prevent double count\n if (scope) {\n scope.setRequestSession(undefined);\n }\n }\n }\n\n /**\n * Increments status bucket in pendingAggregates buffer (internal state) corresponding to status of\n * the session received\n */\n _incrementSessionStatusCount(status, date) {\n // Truncate minutes and seconds on Session Started attribute to have one minute bucket keys\n var sessionStartedTrunc = new Date(date).setSeconds(0, 0);\n this._pendingAggregates[sessionStartedTrunc] = this._pendingAggregates[sessionStartedTrunc] || {};\n\n // corresponds to aggregated sessions in one specific minute bucket\n // for example, {\"started\":\"2021-03-16T08:00:00.000Z\",\"exited\":4, \"errored\": 1}\n var aggregationCounts = this._pendingAggregates[sessionStartedTrunc];\n if (!aggregationCounts.started) {\n aggregationCounts.started = new Date(sessionStartedTrunc).toISOString();\n }\n switch (status) {\n case 'errored':\n aggregationCounts.errored = (aggregationCounts.errored || 0) + 1;\n return aggregationCounts.errored;\n case 'ok':\n aggregationCounts.exited = (aggregationCounts.exited || 0) + 1;\n return aggregationCounts.exited;\n default:\n aggregationCounts.crashed = (aggregationCounts.crashed || 0) + 1;\n return aggregationCounts.crashed;\n }\n }\n}\nexport { SessionFlusher };","map":{"version":3,"names":["dropUndefinedKeys","getCurrentHub","SessionFlusher","__init","flushTimeout","__init2","_pendingAggregates","__init3","_isEnabled","constructor","client","attrs","prototype","call","_client","_intervalId","setInterval","flush","_sessionAttrs","s
|