mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
1 line
28 KiB
JSON
1 line
28 KiB
JSON
|
|
{"ast":null,"code":"import { timestampWithMs, logger } from '@sentry/utils';\nimport { SpanRecorder } from './span.js';\nimport { Transaction } from './transaction.js';\nvar DEFAULT_IDLE_TIMEOUT = 1000;\nvar DEFAULT_FINAL_TIMEOUT = 30000;\nvar HEARTBEAT_INTERVAL = 5000;\n\n/**\n * @inheritDoc\n */\nclass IdleTransactionSpanRecorder extends SpanRecorder {\n constructor(_pushActivity, _popActivity, transactionSpanId, maxlen) {\n super(maxlen);\n this._pushActivity = _pushActivity;\n this._popActivity = _popActivity;\n this.transactionSpanId = transactionSpanId;\n ;\n }\n\n /**\n * @inheritDoc\n */\n add(span) {\n // We should make sure we do not push and pop activities for\n // the transaction that this span recorder belongs to.\n if (span.spanId !== this.transactionSpanId) {\n // We patch span.finish() to pop an activity after setting an endTimestamp.\n span.finish = endTimestamp => {\n span.endTimestamp = typeof endTimestamp === 'number' ? endTimestamp : timestampWithMs();\n this._popActivity(span.spanId);\n };\n\n // We should only push new activities if the span does not have an end timestamp.\n if (span.endTimestamp === undefined) {\n this._pushActivity(span.spanId);\n }\n }\n super.add(span);\n }\n}\n\n/**\n * An IdleTransaction is a transaction that automatically finishes. It does this by tracking child spans as activities.\n * You can have multiple IdleTransactions active, but if the `onScope` option is specified, the idle transaction will\n * put itself on the scope on creation.\n */\nclass IdleTransaction extends Transaction {\n // Activities store a list of active spans\n __init() {\n this.activities = {};\n }\n\n // Track state of activities in previous heartbeat\n\n // Amount of times heartbeat has counted. Will cause transaction to finish after 3 beats.\n __init2() {\n this._heartbeatCounter = 0;\n }\n\n // We should not use heartbeat if we finished a transaction\n __init3() {\n this._finished = false;\n }\n __init4() {\n this._beforeFinishCallbacks = [];\n }\n\n /**\n * Timer that tracks Transaction idleTimeout\n */\n\n constructor(transactionContext, _idleHub,\n /**\n * The time to wait in ms until the idle transaction will be finished. This timer is started each time\n * there are no active spans on this transaction.\n */\n _idleTimeout = DEFAULT_IDLE_TIMEOUT,\n /**\n * The final value in ms that a transaction cannot exceed\n */\n _finalTimeout = DEFAULT_FINAL_TIMEOUT,\n // Whether or not the transaction should put itself on the scope when it starts and pop itself off when it ends\n _onScope = false) {\n super(transactionContext, _idleHub);\n this._idleHub = _idleHub;\n this._idleTimeout = _idleTimeout;\n this._finalTimeout = _finalTimeout;\n this._onScope = _onScope;\n IdleTransaction.prototype.__init.call(this);\n IdleTransaction.prototype.__init2.call(this);\n IdleTransaction.prototype.__init3.call(this);\n IdleTransaction.prototype.__init4.call(this);\n ;\n if (_onScope) {\n // There should only be one active transaction on the scope\n clearActiveTransaction(_idleHub);\n\n // We set the transaction here on the scope so error events pick up the trace\n // context and attach it to the error.\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log(`Setting idle transaction on scope. Span ID: ${this.spanId}`);\n _idleHub.configureScope(scope => scope.setSpan(this));\n }\n this._startIdleTimeout();\n setTimeout(() => {\n if (!this._finished) {\n this.setStatus('deadline_exceeded');\n this.finish();\n }\n }, this._finalTimeout);\n }\n\n /** {@inheritDoc} */\n finish(endTimestamp = timestampWithMs()) {\n this._finished = true;\n this.activities = {};\n if (this.spanRecorder) {\n (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log('[Tracing] finishing IdleTransaction', new Date(endTimestamp * 1000).toISOString(), thi
|