@ooopsstudio/performance 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/budget-engine-KDA4FRYU.js +160 -0
  4. package/dist/budget-engine-KDA4FRYU.js.map +1 -0
  5. package/dist/chunk-2XXIOHOO.js +58 -0
  6. package/dist/chunk-2XXIOHOO.js.map +1 -0
  7. package/dist/chunk-3GMKPRQP.js +197 -0
  8. package/dist/chunk-3GMKPRQP.js.map +1 -0
  9. package/dist/chunk-J6KBSLYO.js +118 -0
  10. package/dist/chunk-J6KBSLYO.js.map +1 -0
  11. package/dist/chunk-MMO5UEUU.js +20 -0
  12. package/dist/chunk-MMO5UEUU.js.map +1 -0
  13. package/dist/chunk-RL2752FW.js +31 -0
  14. package/dist/chunk-RL2752FW.js.map +1 -0
  15. package/dist/chunk-RY65GERM.js +159 -0
  16. package/dist/chunk-RY65GERM.js.map +1 -0
  17. package/dist/chunk-W72QW2AD.js +29 -0
  18. package/dist/chunk-W72QW2AD.js.map +1 -0
  19. package/dist/chunk-ZAXGEDZW.js +1184 -0
  20. package/dist/chunk-ZAXGEDZW.js.map +1 -0
  21. package/dist/custom/exporters/http.d.ts +11 -0
  22. package/dist/custom/exporters/http.js +364 -0
  23. package/dist/custom/exporters/http.js.map +1 -0
  24. package/dist/custom/exporters/raw.d.ts +8 -0
  25. package/dist/custom/exporters/raw.js +6 -0
  26. package/dist/custom/exporters/raw.js.map +1 -0
  27. package/dist/custom.d.ts +58 -0
  28. package/dist/custom.js +299 -0
  29. package/dist/custom.js.map +1 -0
  30. package/dist/development.d.ts +19 -0
  31. package/dist/development.js +55 -0
  32. package/dist/development.js.map +1 -0
  33. package/dist/event-export-manager-DEB64LWZ.js +632 -0
  34. package/dist/event-export-manager-DEB64LWZ.js.map +1 -0
  35. package/dist/index.d.ts +26 -0
  36. package/dist/index.js +205 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/monitors-VNNUIKAK.js +753 -0
  39. package/dist/monitors-VNNUIKAK.js.map +1 -0
  40. package/dist/n1-detector-6IQ2DINP.js +247 -0
  41. package/dist/n1-detector-6IQ2DINP.js.map +1 -0
  42. package/dist/observability.d.ts +32 -0
  43. package/dist/observability.js +76 -0
  44. package/dist/observability.js.map +1 -0
  45. package/dist/ports-DwUYdKj-.d.ts +23 -0
  46. package/dist/production.d.ts +19 -0
  47. package/dist/production.js +42 -0
  48. package/dist/production.js.map +1 -0
  49. package/dist/public/types.d.ts +11 -0
  50. package/dist/public/types.js +3 -0
  51. package/dist/public/types.js.map +1 -0
  52. package/package.json +74 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/performance/core/event-export-lifecycle.ts","../src/performance/core/event-export-manager.ts"],"names":[],"mappings":";;;;;;AAWO,SAAS,sCAAA,GAA2E;AAC1F,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAY;AAClC,EAAA,MAAM,OAAA,uBAAc,GAAA,EAA2B;AAC/C,EAAA,OAAO;AAAA,IACN,GAAA,CAAI,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM;AACzB,MAAA,MAAM,GAAA,GAAM,CAAA,EAAG,QAAQ,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAC/B,MAAA,IAAI,UAAU,GAAA,CAAI,GAAG,CAAA,EAAG,OAAO,QAAQ,OAAA,EAAQ;AAC/C,MAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,GAAG,CAAA;AAChC,MAAA,IAAI,UAAU,OAAO,QAAA;AACrB,MAAA,MAAM,SAAA,GAAY,QAAQ,OAAA,EAAQ,CAAE,KAAK,YAAW,MAAM,MAAM,CAAA;AAChE,MAAA,OAAA,CAAQ,GAAA,CAAI,KAAK,SAAS,CAAA;AAC1B,MAAA,KAAK,SAAA,CAAU,IAAA;AAAA,QACd,MAAM;AACL,UAAA,SAAA,CAAU,IAAI,GAAG,CAA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WAAW,YAAA,CAAa,MAAA;AAAA,QACxB,YAAA,EAAc,aAAA;AAAA,QACd,YAAA;AAAA,QACA,WAAW,OAAA,GAAU,QAAA,GAAW,YAAY,WAAA,GAAc,aAAA,GAAgB,IAAI,UAAA,GAAa,SAAA;AAAA,QAC3F,GAAI,eAAA,GAAkB,EAAC,eAAA,KAAmB;AAAC,OAC3C,CAAA;AAAA,IACF;AAAA,GACD;AACD","file":"event-export-manager-DEB64LWZ.js","sourcesContent":["type ExporterLifecycleHook = 'flush' | 'shutdown'\n\nexport interface EventExporterLifecycleOperations {\n\trun(\n\t\tname: string,\n\t\thookName: ExporterLifecycleHook,\n\t\thook: () => void | Promise<void>\n\t): Promise<void>\n}\n\n/** Reuses pending hooks and remembers late success after an external timeout. */\nexport function createEventExporterLifecycleOperations(): EventExporterLifecycleOperations {\n\tconst completed = new Set<string>()\n\tconst pending = new Map<string, Promise<void>>()\n\treturn {\n\t\trun(name, hookName, hook) {\n\t\t\tconst key = `${hookName}:${name}`\n\t\t\tif (completed.has(key)) return Promise.resolve()\n\t\t\tconst existing = pending.get(key)\n\t\t\tif (existing) return existing\n\t\t\tconst operation = Promise.resolve().then(async() => await hook())\n\t\t\tpending.set(key, operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => {\n\t\t\t\t\tcompleted.add(key)\n\t\t\t\t\tpending.delete(key)\n\t\t\t\t},\n\t\t\t\t() => pending.delete(key)\n\t\t\t)\n\t\t\treturn operation\n\t\t}\n\t}\n}\n","import type {PerformanceEventRecord} from '@ooopsstudio/core/contracts/performance'\nimport type {Errors} from '@ooopsstudio/core/ports/errors'\nimport type {PerformanceEventExporterPort} from '@ooopsstudio/core/ports/performance'\nimport {normalizeError} from '@ooopsstudio/core/utils/error/normalize-error'\n\nimport type {PerformanceSinkState} from '../types/ports'\nimport {ignoreRuntimePromiseRejection, isRuntimePromise, isRuntimeProxy} from '../utils/safe-object'\n\nimport {createEventExporterLifecycleOperations} from './event-export-lifecycle'\nimport {\n\tMAX_PERFORMANCE_EXPORT_BATCH_BYTES,\n\tMAX_PERFORMANCE_EXPORT_BATCH_COUNT,\n\tMAX_PERFORMANCE_TIMER_MS,\n\tserializePerformanceEventRecord,\n\tsleep,\n\twithPerformanceExportTimeout\n} from './event-export-utils'\nimport {createPerformanceExportError, getPerformanceExportErrorMetadata} from './export-errors'\nimport {deepFreezePerformanceValue} from './utils/event-helpers'\n\nconst MAX_EXPORT_OPERATION_TIMEOUT_MS = 5_000\nconst MAX_EXPORT_RETRY_DELAY_MS = 5_000\nconst MAX_EXPORT_DELIVERY_BUDGET_MS = 30_000\nconst KNOWN_EXPORT_FAILURE_CODE = /^(?:performance_export_timeout|http_(?:rate_limited|server_error|client_error|unexpected_status)|fetch_(?:aborted|failed)|invalid_fetch_response|event_serialization_failed)$/\nconst DROPPED_TOTAL_METRIC = '_performance_dropped_total'\nconst QUEUE_SIZE_METRIC = '_performance_export_queue_size'\n\ntype ExporterMethod = 'export' | 'flush' | 'shutdown'\n\nconst captureExporterMethod = (\n\ttarget: unknown,\n\tkey: ExporterMethod\n): ((...args: never[]) => unknown) | undefined => {\n\tif (isRuntimeProxy(target) || (typeof target !== 'object' && typeof target !== 'function') || target === null) return undefined\n\ttry {\n\t\tlet owner: object | null = target\n\t\tfor (let depth = 0; owner && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return undefined\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(owner, key)\n\t\t\tif (descriptor) {\n\t\t\t\tif (!('value' in descriptor) || typeof descriptor.value !== 'function') return undefined\n\t\t\t\tconst method = descriptor.value as (...args: never[]) => unknown\n\t\t\t\treturn (...args: never[]) => {\n\t\t\t\t\tconst result = Reflect.apply(method, target, args)\n\t\t\t\t\tif (result !== undefined && !isRuntimePromise(result)) throw createPerformanceExportError('', {\n\t\t\t\t\t\tretryable: false, code: 'invalid_exporter_result'\n\t\t\t\t\t})\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t}\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return undefined }\n\treturn undefined\n}\n\nconst hasExporterProperty = (target: unknown, key: ExporterMethod): boolean => {\n\tif (isRuntimeProxy(target) || (typeof target !== 'object' && typeof target !== 'function') || target === null) return false\n\ttry {\n\t\tlet owner: object | null = target\n\t\tfor (let depth = 0; owner && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return true\n\t\t\tif (Object.getOwnPropertyDescriptor(owner, key)) return true\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return true }\n\treturn false\n}\n\nconst captureErrorsReport = (errors: unknown): ((...args: unknown[]) => unknown) | undefined => {\n\tif (!errors || (typeof errors !== 'object' && typeof errors !== 'function') || isRuntimeProxy(errors)) return undefined\n\ttry {\n\t\tlet owner: object | null = errors\n\t\tfor (let depth = 0; owner && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(owner)) return undefined\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(owner, 'report')\n\t\t\tif (descriptor) {\n\t\t\t\tif (!('value' in descriptor) || typeof descriptor.value !== 'function') return undefined\n\t\t\t\tconst report = descriptor.value as (...args: unknown[]) => unknown\n\t\t\t\treturn (...args: unknown[]) => Reflect.apply(report, errors, args)\n\t\t\t}\n\t\t\towner = Object.getPrototypeOf(owner) as object | null\n\t\t}\n\t} catch { return undefined }\n\treturn undefined\n}\n\nconst captureExporter = (name: string, exporter: unknown): PerformanceEventExporterPort => {\n\tconst exportBatch = captureExporterMethod(exporter, 'export')\n\tconst flush = captureExporterMethod(exporter, 'flush')\n\tconst shutdown = captureExporterMethod(exporter, 'shutdown')\n\tif (!exportBatch) throw new Error(`Performance event exporter \"${name}\" must provide a data-method export function`)\n\tif (hasExporterProperty(exporter, 'flush') && !flush) {\n\t\tthrow new Error(`Performance event exporter \"${name}\" flush must be a data-method function`)\n\t}\n\tif (hasExporterProperty(exporter, 'shutdown') && !shutdown) {\n\t\tthrow new Error(`Performance event exporter \"${name}\" shutdown must be a data-method function`)\n\t}\n\treturn Object.freeze({\n\t\texport: exportBatch as PerformanceEventExporterPort['export'],\n\t\t...(flush ? {flush: flush as NonNullable<PerformanceEventExporterPort['flush']>} : {}),\n\t\t...(shutdown ? {shutdown: shutdown as NonNullable<PerformanceEventExporterPort['shutdown']>} : {})\n\t})\n}\n\nexport interface EventExportManagerOptions {\n\texporters: ReadonlyArray<{name: string; exporter: PerformanceEventExporterPort}>\n\tmaxBufferCount: number\n\tmaxBufferBytes: number\n\tflushIntervalMs: number\n\tretryAttempts: number\n\tretryBaseDelayMs: number\n\toperationTimeoutMs?: number\n\terrors?: Errors\n\tobserve?: (name: string, value: number, labels?: Record<string, string>) => void\n}\n\nexport interface EventExportStatus {\n\tqueueSize: number\n\tdroppedTotal: number\n\tretriedTotal: number\n\tsinkState: PerformanceSinkState\n\tlastFailureCode?: string\n}\n\nexport interface EventExportManager {\n\tenqueue(record: PerformanceEventRecord): void\n\tflush(): Promise<void>\n\tshutdown(): Promise<void>\n\tgetStatus(): EventExportStatus\n}\n\nexport function createEventExportManager(\n\toptions: EventExportManagerOptions\n): EventExportManager {\n\tif (!options || typeof options !== 'object') {\n\t\tthrow new Error('Performance event export options must be an object')\n\t}\n\tconst {\n\t\texporters: configuredExporters,\n\t\tmaxBufferCount,\n\t\tmaxBufferBytes,\n\t\tflushIntervalMs,\n\t\tretryAttempts,\n\t\tretryBaseDelayMs,\n\t\toperationTimeoutMs = 5_000,\n\t\terrors,\n\t\tobserve\n\t} = options\n\tif (isRuntimeProxy(configuredExporters) || !Array.isArray(configuredExporters)) {\n\t\tthrow new Error('Performance event exporters must be an array')\n\t}\n\tconst lengthDescriptor = Object.getOwnPropertyDescriptor(configuredExporters, 'length')\n\tconst configuredExporterCount = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : -1\n\tif (!Number.isSafeInteger(configuredExporterCount) || configuredExporterCount > 2) {\n\t\tthrow new Error('Performance event export supports at most two exporters')\n\t}\n\tconst configuredEntries: Array<{name: string; exporter: unknown}> = []\n\tfor (let index = 0; index < configuredExporterCount; index += 1) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(configuredExporters, String(index))\n\t\tif (!descriptor || !('value' in descriptor)) {\n\t\t\tthrow new Error('Performance event exporters must use data properties')\n\t\t}\n\t\tconst configured: unknown = descriptor.value\n\t\tif (!configured || typeof configured !== 'object' || isRuntimeProxy(configured)) {\n\t\t\tthrow new Error('Performance event exporters must be valid objects')\n\t\t}\n\t\tlet name: unknown\n\t\tlet exporter: unknown\n\t\ttry {\n\t\t\tconst nameDescriptor = Object.getOwnPropertyDescriptor(configured, 'name')\n\t\t\tconst exporterDescriptor = Object.getOwnPropertyDescriptor(configured, 'exporter')\n\t\t\tif (!nameDescriptor || !('value' in nameDescriptor) || !exporterDescriptor || !('value' in exporterDescriptor)) {\n\t\t\t\tthrow new TypeError()\n\t\t\t}\n\t\t\tname = nameDescriptor.value\n\t\t\texporter = exporterDescriptor.value\n\t\t} catch { throw new Error('Performance event exporters must use data properties') }\n\t\tconfiguredEntries.push({name: name as string, exporter})\n\t}\n\tif (!Number.isInteger(maxBufferCount) || maxBufferCount <= 0 || maxBufferCount > 100_000) {\n\t\tthrow new Error('Performance event export maxBufferCount must be between 1 and 100000')\n\t}\n\tif (!Number.isSafeInteger(maxBufferBytes) || maxBufferBytes <= 0 || maxBufferBytes > 100 * 1024 * 1024) {\n\t\tthrow new Error('Performance event export maxBufferBytes must be between 1 and 104857600')\n\t}\n\tif (!Number.isSafeInteger(flushIntervalMs) || flushIntervalMs < 0 || flushIntervalMs > MAX_PERFORMANCE_TIMER_MS) {\n\t\tthrow new Error(`Performance flushIntervalMs must be between 0 and ${MAX_PERFORMANCE_TIMER_MS}`)\n\t}\n\tif (!Number.isInteger(retryAttempts) || retryAttempts < 0 || retryAttempts > 10) {\n\t\tthrow new Error('Performance event export retryAttempts must be between 0 and 10')\n\t}\n\tif (!Number.isSafeInteger(retryBaseDelayMs) || retryBaseDelayMs < 0 || retryBaseDelayMs > MAX_EXPORT_RETRY_DELAY_MS) {\n\t\tthrow new Error(`Performance retryBaseDelayMs must be between 0 and ${MAX_EXPORT_RETRY_DELAY_MS}`)\n\t}\n\tif (!Number.isSafeInteger(operationTimeoutMs) || operationTimeoutMs <= 0 || operationTimeoutMs > MAX_EXPORT_OPERATION_TIMEOUT_MS) {\n\t\tthrow new Error(`Performance operationTimeoutMs must be between 1 and ${MAX_EXPORT_OPERATION_TIMEOUT_MS}`)\n\t}\n\tif (operationTimeoutMs * (retryAttempts + 1)\n\t\t+ retryBaseDelayMs * ((retryAttempts * (retryAttempts + 1)) / 2)\n\t\t> MAX_EXPORT_DELIVERY_BUDGET_MS) {\n\t\tthrow new Error(`Performance event export retry policy must fit within ${MAX_EXPORT_DELIVERY_BUDGET_MS}ms`)\n\t}\n\tconst exporterNames = new Set<string>()\n\tconst exporters: Array<{name: string; exporter: PerformanceEventExporterPort}> = []\n\tfor (const configured of configuredEntries) {\n\t\tconst {name} = configured\n\t\tif (typeof name !== 'string' || name.length > 64 ||\n\t\t\t!/^[a-z][a-z0-9_.-]{0,63}$/i.test(name) || exporterNames.has(name)) {\n\t\t\tthrow new Error('Performance event exporter names must be unique safe identifiers')\n\t\t}\n\t\texporters.push({name, exporter: captureExporter(name, configured.exporter)})\n\t\texporterNames.add(name)\n\t}\n\ttype QueueItem = {serialized: string; bytes: number; pending: Set<string>; partial: boolean; id: number}\n\tconst logicalQueue: QueueItem[] = []\n\tlet logicalQueueBytes = 0\n\tlet partiallyCommittedRecords = 0\n\tlet nextSequence = 0\n\tconst exporterHealth = new Map<string, {isHealthy: boolean; failures: number}>()\n\tconst terminalExporters = new Set<string>()\n\tconst completedExporterLifecycles = new Set<string>()\n\tconst pendingDeliveries = new Map<string, Promise<void>>()\n\tconst pendingFlushHooks = new Map<string, Promise<void>>()\n\tconst exportersNeedingFlush = new Set<string>()\n\tconst lifecycleOperations = createEventExporterLifecycleOperations()\n\tfor (const {name} of exporters) {\n\t\texporterHealth.set(name, {isHealthy: true, failures: 0})\n\t}\n\tlet droppedEvents = 0\n\tlet retriedTotal = 0\n\tlet activeRetries = 0\n\tlet lastFailureCode: string | undefined\n\tlet stopped = false\n\tlet closing = false\n\tlet flushPromise: Promise<void> | null = null\n\tlet requestedFlushGeneration = 0\n\tlet completedFlushGeneration = 0\n\tlet requestedExporterHooks = false\n\tlet shutdownPromise: Promise<void> | null = null\n\tlet timer: ReturnType<typeof setInterval> | undefined\n\tconst errorsReport = captureErrorsReport(errors)\n\tlet pendingErrorReport: Promise<unknown> | true | undefined\n\tlet pendingObservation: Promise<unknown> | true | undefined\n\tconst reportError = (context: Record<string, string>): void => {\n\t\tif (pendingErrorReport) return\n\t\tpendingErrorReport = true\n\t\ttry {\n\t\t\tconst result = errorsReport?.(normalizeError(new Error('performance_export_failed')), context)\n\t\t\tignoreRuntimePromiseRejection(result)\n\t\t\tif (isRuntimePromise(result)) {\n\t\t\t\tconst reportPromise = result as Promise<unknown>\n\t\t\t\tpendingErrorReport = reportPromise\n\t\t\t\tconst release = () => { if (pendingErrorReport === reportPromise) pendingErrorReport = undefined }\n\t\t\t\tvoid Reflect.apply(Promise.prototype.then, reportPromise, [\n\t\t\t\t\trelease,\n\t\t\t\t\trelease\n\t\t\t\t])\n\t\t\t} else pendingErrorReport = undefined\n\t\t} catch {\n\t\t\t// Error reporting must not affect exporter state or create an unhandled rejection.\n\t\t}\n\t}\n\tconst emit = (name: string, value: number, labels?: Record<string, string>) => {\n\t\tif (pendingObservation) return\n\t\tpendingObservation = true\n\t\ttry {\n\t\t\tconst result: unknown = observe?.(name, value, labels)\n\t\t\tignoreRuntimePromiseRejection(result)\n\t\t\tif (isRuntimePromise(result)) {\n\t\t\t\tconst observation = result as Promise<unknown>\n\t\t\t\tpendingObservation = observation\n\t\t\t\tconst release = () => { if (pendingObservation === observation) pendingObservation = undefined }\n\t\t\t\ttry {\n\t\t\t\t\tvoid Reflect.apply(Promise.prototype.then, observation, [release, release])\n\t\t\t\t} catch { release() }\n\t\t\t} else pendingObservation = undefined\n\t\t} catch { /* broken telemetry stays disabled */ }\n\t}\n\tconst setExporterFailure = (name: string, error: unknown) => {\n\t\tconst previous = exporterHealth.get(name) ?? {isHealthy: true, failures: 0}\n\t\tconst safeError = getPerformanceExportErrorMetadata(error)?.code ?? 'performance_export_failed'\n\t\tlastFailureCode = KNOWN_EXPORT_FAILURE_CODE.test(safeError)\n\t\t\t? safeError.toUpperCase()\n\t\t\t: 'PERFORMANCE_EXPORT_FAILURE'\n\t\texporterHealth.set(name, {\n\t\t\tisHealthy: false,\n\t\t\tfailures: previous.failures + 1\n\t\t})\n\t\temit('_performance_export_failures_total', 1)\n\t\treportError({stage: 'performance', operation: 'event_export', exporter: name})\n\t}\n\tconst setExporterSuccess = (name: string) => {\n\t\tconst previous = exporterHealth.get(name) ?? {isHealthy: true, failures: 0}\n\t\texporterHealth.set(name, {\n\t\t\tisHealthy: true,\n\t\t\tfailures: previous.failures\n\t\t})\n\t\tif ([...exporterHealth.values()].every(({isHealthy}) => isHealthy)) lastFailureCode = undefined\n\t}\n\tconst getActiveExporterNames = () =>\n\t\texporters\n\t\t\t.map(({name}) => name)\n\t\t\t.filter((name) => !terminalExporters.has(name))\n\tconst countPending = (name: string, through: number) =>\n\t\tlogicalQueue.filter((item) => item.id <= through && item.pending.has(name)).length\n\tconst pruneCommitted = (): void => {\n\t\t// Every destination consumes records in queue order, so the intersection of\n\t\t// their committed prefixes is itself one prefix. Remove it in one splice;\n\t\t// per-record splices turn a maximum-size drain into quadratic work.\n\t\tlet committedCount = 0\n\t\tlet committedBytes = 0\n\t\twhile (logicalQueue[committedCount]?.pending.size === 0) {\n\t\t\tcommittedBytes += logicalQueue[committedCount]!.bytes\n\t\t\tcommittedCount += 1\n\t\t}\n\t\tif (committedCount > 0) {\n\t\t\tlogicalQueue.splice(0, committedCount)\n\t\t\tlogicalQueueBytes -= committedBytes\n\t\t}\n\t}\n\tconst removePendingDestination = (item: QueueItem, name: string): boolean => {\n\t\tif (!item.pending.delete(name)) return false\n\t\tif (item.pending.size > 0 && !item.partial) {\n\t\t\titem.partial = true\n\t\t\tpartiallyCommittedRecords += 1\n\t\t} else if (item.pending.size === 0 && item.partial) {\n\t\t\titem.partial = false\n\t\t\tpartiallyCommittedRecords -= 1\n\t\t}\n\t\treturn true\n\t}\n\tconst abandonDestination = (name: string): void => {\n\t\tlet terminalDrops = 0\n\t\tfor (const item of logicalQueue) {\n\t\t\tif (removePendingDestination(item, name)) terminalDrops += 1\n\t\t}\n\t\tpruneCommitted()\n\t\tdroppedEvents += terminalDrops\n\t\tif (terminalDrops > 0) emit(DROPPED_TOTAL_METRIC, terminalDrops, {reason: 'terminal_exporter_error'})\n\t\temit(QUEUE_SIZE_METRIC, logicalQueue.length)\n\t}\n\tconst terminateDestination = (name: string, error: unknown): void => {\n\t\tif (terminalExporters.has(name)) return\n\t\tterminalExporters.add(name)\n\t\tsetExporterFailure(name, error)\n\t\tabandonDestination(name)\n\t}\n\tconst releasePartiallyCommittedRecord = (activeDestinationCount: number): boolean => {\n\t\tif (partiallyCommittedRecords === 0 || activeDestinationCount < 2) return false\n\t\tconst index = logicalQueue.findIndex((item) => item.partial && item.pending.size < activeDestinationCount)\n\t\tif (index < 0) return false\n\t\tconst releasedBytes = logicalQueue[index]!.bytes\n\t\tlogicalQueue[index]!.partial = false\n\t\tpartiallyCommittedRecords -= 1\n\t\tlogicalQueue.splice(index, 1)\n\t\tlogicalQueueBytes -= releasedBytes\n\t\tdroppedEvents += 1\n\t\temit(DROPPED_TOTAL_METRIC, 1, {reason: 'partial_fanout_backpressure'})\n\t\temit(QUEUE_SIZE_METRIC, logicalQueue.length)\n\t\treturn true\n\t}\n\tconst deliverBatch = (\n\t\tname: string,\n\t\texporter: PerformanceEventExporterPort,\n\t\tthrough: number\n\t): Promise<void> => {\n\t\tconst existing = pendingDeliveries.get(name)\n\t\tif (existing) return existing\n\t\tconst items: QueueItem[] = []\n\t\tlet batchBytes = 0\n\t\tfor (const item of logicalQueue) {\n\t\t\tif (item.id > through) break\n\t\t\tif (!item.pending.has(name)) continue\n\t\t\tif (items.length >= MAX_PERFORMANCE_EXPORT_BATCH_COUNT\n\t\t\t\t|| batchBytes + item.bytes > MAX_PERFORMANCE_EXPORT_BATCH_BYTES) break\n\t\t\titems.push(item)\n\t\t\tbatchBytes += item.bytes\n\t\t}\n\t\tconst attemptBatch = deepFreezePerformanceValue(\n\t\t\titems.map((item) => JSON.parse(item.serialized) as PerformanceEventRecord)\n\t\t)\n\t\tconst operation = Promise.resolve()\n\t\t\t.then(async() => await exporter.export(attemptBatch))\n\t\t\t.then(() => {\n\t\t\t\tsetExporterSuccess(name)\n\t\t\t\tif (exporter.flush) exportersNeedingFlush.add(name)\n\t\t\t\tfor (const item of items) removePendingDestination(item, name)\n\t\t\t\tpruneCommitted()\n\t\t\t\temit(QUEUE_SIZE_METRIC, logicalQueue.length)\n\t\t\t\tif (pendingDeliveries.get(name) === operation) pendingDeliveries.delete(name)\n\t\t\t})\n\t\tpendingDeliveries.set(name, operation)\n\t\tvoid operation.catch((error) => {\n\t\t\tif (pendingDeliveries.get(name) === operation) pendingDeliveries.delete(name)\n\t\t\tconst metadata = getPerformanceExportErrorMetadata(error)\n\t\t\tif (metadata?.retryable === false) terminateDestination(name, error)\n\t\t})\n\t\treturn operation\n\t}\n\tconst runExporterFlush = (name: string, exporter: PerformanceEventExporterPort): Promise<void> => {\n\t\tconst existing = pendingFlushHooks.get(name)\n\t\tif (existing) return existing\n\t\tconst operation = Promise.resolve().then(async() => await exporter.flush?.())\n\t\tpendingFlushHooks.set(name, operation)\n\t\tvoid operation.then(\n\t\t\t() => pendingFlushHooks.delete(name),\n\t\t\t() => pendingFlushHooks.delete(name)\n\t\t)\n\t\treturn operation\n\t}\n\tconst runFlushCycle = async(flushExporterHooks: boolean) => {\n\t\tif (stopped || exporters.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst failures: unknown[] = []\n\t\tawait Promise.all(exporters.map(async({name, exporter}) => {\n\t\t\tif (terminalExporters.has(name)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst boundary = logicalQueue.at(-1)?.id ?? -1\n\t\t\tlet remainingBatchCount = countPending(name, boundary)\n\t\t\tlet deliverySucceeded = remainingBatchCount === 0\n\t\t\tlet failedAttempts = 0\n\t\t\twhile (remainingBatchCount > 0) {\n\t\t\t\t// A timed-out operation can settle successfully while this loop is in\n\t\t\t\t// retry backoff. Its completion commits the records asynchronously, so\n\t\t\t\t// the local count is no longer authoritative. Re-read destination state\n\t\t\t\t// before materializing another batch; otherwise an empty batch has count\n\t\t\t\t// zero and the loop can spin forever without making progress.\n\t\t\t\tif (terminalExporters.has(name)) {\n\t\t\t\t\tfailures.push(new Error('Exporter failed'))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tremainingBatchCount = countPending(name, boundary)\n\t\t\t\tif (remainingBatchCount === 0) {\n\t\t\t\t\tdeliverySucceeded = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tlet delivery: Promise<void> | undefined\n\t\t\t\ttry {\n\t\t\t\t\tdelivery = deliverBatch(name, exporter, boundary)\n\t\t\t\t\tawait withPerformanceExportTimeout(\n\t\t\t\t\t\tdelivery,\n\t\t\t\t\t\toperationTimeoutMs,\n\t\t\t\t\t\t`Exporter \"${name}\"`\n\t\t\t\t\t)\n\t\t\t\t\tremainingBatchCount = countPending(name, boundary)\n\t\t\t\t\tdeliverySucceeded = remainingBatchCount === 0\n\t\t\t\t\tfailedAttempts = 0\n\t\t\t\t} catch(error) {\n\t\t\t\t\tconst errorMetadata = getPerformanceExportErrorMetadata(error)\n\t\t\t\t\tif (errorMetadata?.code !== 'performance_export_timeout'\n\t\t\t\t\t\t&& delivery && pendingDeliveries.get(name) === delivery) {\n\t\t\t\t\t\tpendingDeliveries.delete(name)\n\t\t\t\t\t}\n\t\t\t\t\tconst retryable = errorMetadata?.retryable ?? true\n\t\t\t\t\tif (!retryable || failedAttempts >= retryAttempts) {\n\t\t\t\t\t\tif (retryable) setExporterFailure(name, error)\n\t\t\t\t\t\telse terminateDestination(name, error)\n\t\t\t\t\t\tfailures.push(error)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tfailedAttempts += 1\n\t\t\t\t\tretriedTotal += 1\n\t\t\t\t\temit('_performance_export_retries_total', 1)\n\t\t\t\t\tactiveRetries += 1\n\t\t\t\t\ttry { await sleep(retryBaseDelayMs * failedAttempts) } finally { activeRetries -= 1 }\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!deliverySucceeded || !flushExporterHooks || !exporter.flush || !exportersNeedingFlush.has(name)) return\n\t\t\tfor (let attempt = 0; attempt <= retryAttempts; attempt += 1) {\n\t\t\t\ttry {\n\t\t\t\t\tawait withPerformanceExportTimeout(\n\t\t\t\t\t\trunExporterFlush(name, exporter),\n\t\t\t\t\t\toperationTimeoutMs,\n\t\t\t\t\t\t`Exporter \"${name}\" flush`\n\t\t\t\t\t)\n\t\t\t\t\tsetExporterSuccess(name)\n\t\t\t\t\texportersNeedingFlush.delete(name)\n\t\t\t\t\tbreak\n\t\t\t\t} catch(error) {\n\t\t\t\t\tif (attempt >= retryAttempts) {\n\t\t\t\t\t\tsetExporterFailure(name, error)\n\t\t\t\t\t\tfailures.push(error)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tretriedTotal += 1\n\t\t\t\t\temit('_performance_export_retries_total', 1)\n\t\t\t\t\tactiveRetries += 1\n\t\t\t\t\ttry { await sleep(retryBaseDelayMs * (attempt + 1)) } finally { activeRetries -= 1 }\n\t\t\t\t}\n\t\t\t}\n\n\t\t})).then(() => {\n\t\t\tif (failures.length > 0) {\n\t\t\t\tthrow new AggregateError(failures, 'Performance event export flush failed')\n\t\t\t}\n\t\t})\n\t}\n\n\tconst flush = async(flushExporterHooks = true) => {\n\t\tif (stopped || exporters.length === 0) return\n\t\t// One generation drains the current queue; at most one follow-up generation\n\t\t// is needed for work admitted while that drain is active. Coalescing here\n\t\t// prevents concurrent callers from manufacturing unbounded empty cycles.\n\t\trequestedFlushGeneration = Math.max(\n\t\t\trequestedFlushGeneration,\n\t\t\tcompletedFlushGeneration + (flushPromise ? 2 : 1)\n\t\t)\n\t\trequestedExporterHooks ||= flushExporterHooks\n\t\tif (!flushPromise) {\n\t\t\tflushPromise = (async() => {\n\t\t\t\twhile (completedFlushGeneration < requestedFlushGeneration) {\n\t\t\t\t\tconst targetGeneration = requestedFlushGeneration\n\t\t\t\t\tconst runExporterHooks = requestedExporterHooks\n\t\t\t\t\trequestedExporterHooks = false\n\t\t\t\t\tawait runFlushCycle(runExporterHooks)\n\t\t\t\t\tcompletedFlushGeneration = targetGeneration\n\t\t\t\t}\n\t\t\t})().finally(() => {\n\t\t\t\tflushPromise = null\n\t\t\t})\n\t\t}\n\t\treturn flushPromise\n\t}\n\n\tif (exporters.length > 0 && flushIntervalMs > 0) {\n\t\ttimer = setInterval(() => {\n\t\t\tvoid flush().catch(() => reportError({\n\t\t\t\tstage: 'performance', operation: 'event_export_timer_flush'\n\t\t\t}))\n\t\t}, flushIntervalMs)\n\t\ttry { timer.unref?.() } catch { /* optional process-lifetime optimization */ }\n\t}\n\n\treturn {\n\t\tenqueue(record: PerformanceEventRecord): void {\n\t\t\tif (stopped || closing || exporters.length === 0) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst activeNames = getActiveExporterNames()\n\t\t\tif (activeNames.length === 0) {\n\t\t\t\tdroppedEvents += 1\n\t\t\t\temit(DROPPED_TOTAL_METRIC, 1, {reason: 'terminal_exporter_unavailable'})\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst saturatedReason = logicalQueue.length >= maxBufferCount ? 'count_limit'\n\t\t\t\t: logicalQueueBytes >= maxBufferBytes ? 'byte_limit' : undefined\n\t\t\tif (saturatedReason && (partiallyCommittedRecords === 0 || activeNames.length < 2)) {\n\t\t\t\tdroppedEvents += 1\n\t\t\t\temit(DROPPED_TOTAL_METRIC, 1, {reason: saturatedReason})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst snapshot = serializePerformanceEventRecord(record)\n\t\t\tif (snapshot === null || snapshot.bytes > MAX_PERFORMANCE_EXPORT_BATCH_BYTES) {\n\t\t\t\tdroppedEvents += 1\n\t\t\t\temit(DROPPED_TOTAL_METRIC, 1, {\n\t\t\t\t\treason: snapshot ? 'record_size_limit' : 'serialization_error'\n\t\t\t\t})\n\t\t\t\tif (!snapshot) reportError({\n\t\t\t\t\tstage: 'performance', operation: 'event_export_enqueue'\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tlet dropReason = logicalQueue.length >= maxBufferCount ? 'count_limit'\n\t\t\t\t: logicalQueueBytes + snapshot.bytes > maxBufferBytes ? 'byte_limit' : undefined\n\t\t\twhile (dropReason && releasePartiallyCommittedRecord(activeNames.length)) {\n\t\t\t\tdropReason = logicalQueue.length >= maxBufferCount ? 'count_limit'\n\t\t\t\t\t: logicalQueueBytes + snapshot.bytes > maxBufferBytes ? 'byte_limit' : undefined\n\t\t\t}\n\t\t\tif (dropReason) {\n\t\t\t\tdroppedEvents += 1\n\t\t\t\temit(DROPPED_TOTAL_METRIC, 1, {reason: dropReason})\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlogicalQueue.push({\n\t\t\t\tserialized: snapshot.serialized,\n\t\t\t\tbytes: snapshot.bytes,\n\t\t\t\tpending: new Set(activeNames),\n\t\t\t\tpartial: false,\n\t\t\t\tid: nextSequence++\n\t\t\t})\n\t\t\tlogicalQueueBytes += snapshot.bytes\n\t\t\temit(QUEUE_SIZE_METRIC, logicalQueue.length)\n\t\t},\n\t\tflush,\n\t\tasync shutdown(): Promise<void> {\n\t\t\tif (shutdownPromise) {\n\t\t\t\treturn shutdownPromise\n\t\t\t}\n\t\t\tshutdownPromise = (async() => {\n\t\t\t\tclosing = true\n\t\t\t\tif (timer !== undefined) {\n\t\t\t\t\tconst activeTimer = timer\n\t\t\t\t\ttimer = undefined\n\t\t\t\t\ttry { clearInterval(activeTimer) } catch { /* finalization must continue */ }\n\t\t\t\t}\n\t\t\t\tconst failures: unknown[] = []\n\t\t\t\ttry {\n\t\t\t\t\tawait flush(false)\n\t\t\t\t} catch(error) {\n\t\t\t\t\tfailures.push(error)\n\t\t\t\t}\n\t\t\t\tconst undelivered = logicalQueue.length\n\t\t\t\tif (undelivered > 0) {\n\t\t\t\t\tfailures.push(new Error(`Performance event exporter shutdown left ${undelivered} event(s) undelivered`))\n\t\t\t\t\t// Retryable records are still owned by active exporters. Do not call\n\t\t\t\t\t// their lifecycle hooks yet: doing so can close the very exporter that\n\t\t\t\t\t// a later shutdown attempt must use to deliver the retained records.\n\t\t\t\t\tthrow new AggregateError(failures, 'Performance event exporter shutdown failed')\n\t\t\t\t}\n\t\t\t\tawait Promise.all(exporters.map(async({name, exporter}) => {\n\t\t\t\t\tif (completedExporterLifecycles.has(name)) return\n\t\t\t\t\tlet failed = false\n\t\t\t\t\tif (exporter.flush) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait withPerformanceExportTimeout(\n\t\t\t\t\t\t\t\tlifecycleOperations.run(name, 'flush', () => runExporterFlush(name, exporter)),\n\t\t\t\t\t\t\t\toperationTimeoutMs,\n\t\t\t\t\t\t\t\t'Exporter flush'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} catch(error) { failed = true; failures.push(error) }\n\t\t\t\t\t}\n\t\t\t\t\tlet shutdownCompleted = false\n\t\t\t\t\tif (exporter.shutdown) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait withPerformanceExportTimeout(\n\t\t\t\t\t\t\t\tlifecycleOperations.run(name, 'shutdown', () => exporter.shutdown?.()),\n\t\t\t\t\t\t\t\toperationTimeoutMs,\n\t\t\t\t\t\t\t\t'Exporter shutdown'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tshutdownCompleted = true\n\t\t\t\t\t\t} catch(error) { failed = true; failures.push(error) }\n\t\t\t\t\t}\n\t\t\t\t\tif (!failed || shutdownCompleted) completedExporterLifecycles.add(name)\n\t\t\t\t}))\n\t\t\t\tif (failures.length > 0) {\n\t\t\t\t\tthrow new AggregateError(failures, 'Performance event exporter shutdown failed')\n\t\t\t\t}\n\t\t\t\tstopped = true\n\t\t\t})().catch((error) => {\n\t\t\t\tshutdownPromise = null\n\t\t\t\t// Admission and background delivery stay closed after finalization has\n\t\t\t\t// started. A later shutdown call retries only the unresolved physical\n\t\t\t\t// work; it never reopens the periodic exporter interval.\n\t\t\t\tthrow error\n\t\t\t})\n\t\t\treturn shutdownPromise\n\t\t},\n\t\tgetStatus(): EventExportStatus {\n\t\t\tconst unhealthy = terminalExporters.size > 0 || [...exporterHealth.values()].some(({isHealthy}) => !isHealthy)\n\t\t\treturn Object.freeze({\n\t\t\t\tqueueSize: logicalQueue.length,\n\t\t\t\tdroppedTotal: droppedEvents,\n\t\t\t\tretriedTotal,\n\t\t\t\tsinkState: stopped ? 'closed' : unhealthy ? 'unhealthy' : activeRetries > 0 ? 'degraded' : 'healthy',\n\t\t\t\t...(lastFailureCode ? {lastFailureCode} : {})\n\t\t\t})\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { Container } from '@ooopsstudio/core/runtime';
2
+ import { CustomPerformanceOptions } from './custom.js';
3
+ import { DevelopmentPerformanceOptions } from './development.js';
4
+ import { ProductionPerformanceOptions } from './production.js';
5
+ export { PerformanceEventExporterPort, PerformancePort } from '@ooopsstudio/core/ports/performance';
6
+ export { M as ManagedPerformance, a as PerformanceRuntimeState, b as PerformanceSinkState, c as PerformanceStatus } from './ports-DwUYdKj-.js';
7
+ import '@ooopsstudio/core/contracts/clock';
8
+ import '@ooopsstudio/core/contracts/observability-shared';
9
+ import '@ooopsstudio/core/ports/errors';
10
+ import '@ooopsstudio/core/ports/lifecycle';
11
+ import '@ooopsstudio/core/ports/tracing';
12
+ import '@ooopsstudio/core/contracts/performance';
13
+
14
+ type PerformanceOptions = {
15
+ preset: 'development';
16
+ options?: Omit<DevelopmentPerformanceOptions, 'clock'>;
17
+ } | {
18
+ preset: 'production';
19
+ options?: Omit<ProductionPerformanceOptions, 'clock'>;
20
+ } | {
21
+ preset: 'custom';
22
+ options: Omit<CustomPerformanceOptions, 'clock'>;
23
+ };
24
+ declare function registerPerformance(container: Container, config: PerformanceOptions): Promise<void>;
25
+
26
+ export { CustomPerformanceOptions, DevelopmentPerformanceOptions, type PerformanceOptions, ProductionPerformanceOptions, registerPerformance };
package/dist/index.js ADDED
@@ -0,0 +1,205 @@
1
+ import { isRuntimeProxy, ignoreRuntimePromiseRejection } from './chunk-RL2752FW.js';
2
+ import { TOK } from '@ooopsstudio/core/tokens';
3
+
4
+ var registrationsInProgress = /* @__PURE__ */ new WeakSet();
5
+ var ROOT_FIELDS = /* @__PURE__ */ new Set(["preset", "options"]);
6
+ var STANDARD_FIELDS = /* @__PURE__ */ new Set(["resource", "errors", "tracer", "lifecycle"]);
7
+ var CUSTOM_FIELDS = /* @__PURE__ */ new Set([
8
+ ...STANDARD_FIELDS,
9
+ "budgets",
10
+ "n1Detection",
11
+ "runtimeMonitoring",
12
+ "destinations",
13
+ "delivery"
14
+ ]);
15
+ var REGISTRATION_CLEANUP_TIMEOUT_MS = 5e3;
16
+ var captureContainerMethod = (container, key) => {
17
+ if (isRuntimeProxy(container)) return void 0;
18
+ let current = container;
19
+ try {
20
+ for (let depth = 0; current && depth < 16; depth += 1) {
21
+ if (isRuntimeProxy(current)) return void 0;
22
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
23
+ if (descriptor) {
24
+ if (!("value" in descriptor) || typeof descriptor.value !== "function") return void 0;
25
+ const method = descriptor.value;
26
+ return (...args) => {
27
+ const result = Reflect.apply(method, container, args);
28
+ ignoreRuntimePromiseRejection(result);
29
+ if ((key === "has" || key === "unbind") && typeof result !== "boolean") throw new TypeError();
30
+ if (key === "bind" && result !== void 0) throw new TypeError();
31
+ return result;
32
+ };
33
+ }
34
+ current = Object.getPrototypeOf(current);
35
+ }
36
+ } catch {
37
+ return void 0;
38
+ }
39
+ return void 0;
40
+ };
41
+ var snapshotDataObject = (value, label, allowed) => {
42
+ try {
43
+ if (!value || typeof value !== "object" || isRuntimeProxy(value) || Array.isArray(value)) throw new TypeError();
44
+ const prototype = Object.getPrototypeOf(value);
45
+ if (prototype !== Object.prototype && prototype !== null) throw new TypeError();
46
+ if (Object.getOwnPropertySymbols(value).length > 0) throw new TypeError();
47
+ const snapshot = /* @__PURE__ */ Object.create(null);
48
+ let inspected = 0;
49
+ for (const key in value) {
50
+ if (inspected >= allowed.size || key.length > 64 || !allowed.has(key)) throw new TypeError();
51
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
52
+ if (!descriptor?.enumerable || !("value" in descriptor)) throw new TypeError();
53
+ inspected += 1;
54
+ snapshot[key] = descriptor.value;
55
+ }
56
+ return Object.freeze(snapshot);
57
+ } catch {
58
+ throw new TypeError(`${label} must contain only stable plain data fields`);
59
+ }
60
+ };
61
+ var snapshotRegistration = (value) => {
62
+ const registration = snapshotDataObject(value, "Performance registration options", ROOT_FIELDS);
63
+ const preset = registration.preset;
64
+ if (preset !== "development" && preset !== "production" && preset !== "custom") {
65
+ throw new Error("Unknown performance preset");
66
+ }
67
+ if (registration.options === void 0) {
68
+ if (preset === "custom") throw new TypeError("Performance custom registration options are required");
69
+ return Object.freeze({ preset });
70
+ }
71
+ const options = snapshotDataObject(
72
+ registration.options,
73
+ `Performance ${preset} options`,
74
+ preset === "custom" ? CUSTOM_FIELDS : STANDARD_FIELDS
75
+ );
76
+ return Object.freeze({ preset, options });
77
+ };
78
+ var cleanupPerformance = async (performance) => {
79
+ let timer;
80
+ try {
81
+ await Promise.race([
82
+ (async () => {
83
+ try {
84
+ await performance.shutdown?.();
85
+ } catch {
86
+ await performance.shutdown?.();
87
+ }
88
+ })(),
89
+ new Promise((_resolve, reject) => {
90
+ timer = setTimeout(
91
+ () => reject(new Error("performance_registration_cleanup_timeout")),
92
+ REGISTRATION_CLEANUP_TIMEOUT_MS
93
+ );
94
+ })
95
+ ]);
96
+ } finally {
97
+ if (timer) clearTimeout(timer);
98
+ }
99
+ };
100
+ async function registerPerformance(container, config) {
101
+ if (!container || typeof container !== "object") {
102
+ throw new TypeError("Performance registration requires a valid container");
103
+ }
104
+ if (registrationsInProgress.has(container)) {
105
+ throw new Error("performance_already_registered");
106
+ }
107
+ registrationsInProgress.add(container);
108
+ try {
109
+ const has = captureContainerMethod(container, "has");
110
+ const get = captureContainerMethod(container, "get");
111
+ const tryGet = captureContainerMethod(container, "tryGet");
112
+ const bind = captureContainerMethod(container, "bind");
113
+ const unbind = captureContainerMethod(container, "unbind");
114
+ if (!has || !get || !tryGet || !bind || !unbind) {
115
+ throw new TypeError("Performance registration requires a valid reversible container");
116
+ }
117
+ let alreadyRegistered;
118
+ try {
119
+ alreadyRegistered = has(TOK.Performance) || tryGet(TOK.Performance) !== void 0;
120
+ } catch {
121
+ throw new Error("performance_container_lookup_failed");
122
+ }
123
+ if (alreadyRegistered) throw new Error("performance_already_registered");
124
+ const registration = snapshotRegistration(config);
125
+ await registerPerformanceUnlocked({ has, get, tryGet, bind, unbind }, registration);
126
+ } finally {
127
+ registrationsInProgress.delete(container);
128
+ }
129
+ }
130
+ async function registerPerformanceUnlocked(container, config) {
131
+ let clock;
132
+ try {
133
+ clock = container.get(TOK.Clock);
134
+ if (clock === void 0 || clock === null) throw new TypeError();
135
+ } catch {
136
+ throw new Error("performance_invalid_clock");
137
+ }
138
+ let errors;
139
+ let tracer;
140
+ let lifecycle;
141
+ try {
142
+ errors = container.tryGet(TOK.Errors);
143
+ tracer = container.tryGet(TOK.Tracing);
144
+ lifecycle = container.tryGet(TOK.Lifecycle);
145
+ } catch {
146
+ throw new Error("performance_dependency_resolution_failed");
147
+ }
148
+ const presetDependencies = {
149
+ clock,
150
+ ...errors ? { errors } : {},
151
+ ...tracer ? { tracer } : {},
152
+ ...lifecycle ? { lifecycle } : {}
153
+ };
154
+ let performance;
155
+ if (config.preset === "development") {
156
+ const { createDevelopmentPerformance } = await import('./development.js');
157
+ performance = await createDevelopmentPerformance({ ...config.options, ...presetDependencies });
158
+ } else if (config.preset === "production") {
159
+ const { createProductionPerformance } = await import('./production.js');
160
+ performance = await createProductionPerformance({ ...config.options, ...presetDependencies });
161
+ } else {
162
+ const { createCustomPerformance } = await import('./custom.js');
163
+ performance = await createCustomPerformance({ ...config.options, ...presetDependencies });
164
+ }
165
+ let bindAttempted = false;
166
+ const hasPerformanceBinding = () => container.has(TOK.Performance) || container.tryGet(TOK.Performance) !== void 0;
167
+ try {
168
+ if (hasPerformanceBinding()) {
169
+ throw new Error("Performance service was registered during runtime creation");
170
+ }
171
+ bindAttempted = true;
172
+ container.bind(TOK.Performance, performance);
173
+ if (!container.has(TOK.Performance) || container.tryGet(TOK.Performance) !== performance) {
174
+ throw new Error("Performance container did not retain the expected binding");
175
+ }
176
+ } catch (error) {
177
+ const cleanupErrors = [];
178
+ try {
179
+ if (bindAttempted) {
180
+ const retained = container.tryGet(TOK.Performance);
181
+ if (retained === performance) {
182
+ container.unbind(TOK.Performance);
183
+ if (container.tryGet(TOK.Performance) === performance) {
184
+ throw new Error("Performance registration rollback failed");
185
+ }
186
+ }
187
+ }
188
+ } catch (cleanupError) {
189
+ cleanupErrors.push(cleanupError);
190
+ }
191
+ try {
192
+ await cleanupPerformance(performance);
193
+ } catch (cleanupError) {
194
+ cleanupErrors.push(cleanupError);
195
+ }
196
+ if (cleanupErrors.length > 0) {
197
+ throw new AggregateError([error, ...cleanupErrors], "Performance registration and rollback failed");
198
+ }
199
+ throw error;
200
+ }
201
+ }
202
+
203
+ export { registerPerformance };
204
+ //# sourceMappingURL=index.js.map
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/performance/index.ts"],"names":[],"mappings":";;;AAkBA,IAAM,uBAAA,uBAA8B,OAAA,EAAgB;AACpD,IAAM,8BAAc,IAAI,GA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AAM,KAAA;AAAA,EACP;AACD","file":"index.js","sourcesContent":["import type {Clock} from '@ooopsstudio/core/contracts/clock'\nimport type {Errors} from '@ooopsstudio/core/ports/errors'\nimport type {LifecyclePort} from '@ooopsstudio/core/ports/lifecycle'\nimport type {Tracing} from '@ooopsstudio/core/ports/tracing'\nimport type {Container} from '@ooopsstudio/core/runtime'\nimport {TOK} from '@ooopsstudio/core/tokens'\n\nimport type {CustomPerformanceOptions} from './public/custom'\nimport type {DevelopmentPerformanceOptions} from './public/development'\nimport type {ProductionPerformanceOptions} from './public/production'\nimport type {ManagedPerformance} from './types/ports'\nimport {ignoreRuntimePromiseRejection, isRuntimeProxy} from './utils/safe-object'\n\nexport type PerformanceOptions =\n\t| {preset: 'development'; options?: Omit<DevelopmentPerformanceOptions, 'clock'>}\n\t| {preset: 'production'; options?: Omit<ProductionPerformanceOptions, 'clock'>}\n\t| {preset: 'custom'; options: Omit<CustomPerformanceOptions, 'clock'>}\n\nconst registrationsInProgress = new WeakSet<object>()\nconst ROOT_FIELDS = new Set(['preset', 'options'])\nconst STANDARD_FIELDS = new Set(['resource', 'errors', 'tracer', 'lifecycle'])\nconst CUSTOM_FIELDS = new Set([\n\t...STANDARD_FIELDS, 'budgets', 'n1Detection', 'runtimeMonitoring', 'destinations', 'delivery'\n])\nconst REGISTRATION_CLEANUP_TIMEOUT_MS = 5_000\n\ntype ContainerMethod = (...args: never[]) => unknown\n\nconst captureContainerMethod = (container: object, key: PropertyKey): ContainerMethod | undefined => {\n\tif (isRuntimeProxy(container)) return undefined\n\tlet current: object | null = container\n\ttry {\n\t\tfor (let depth = 0; current && depth < 16; depth += 1) {\n\t\t\tif (isRuntimeProxy(current)) return undefined\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(current, key)\n\t\t\tif (descriptor) {\n\t\t\t\tif (!('value' in descriptor) || typeof descriptor.value !== 'function') return undefined\n\t\t\t\tconst method = descriptor.value as ContainerMethod\n\t\t\t\treturn (...args: never[]) => {\n\t\t\t\t\tconst result = Reflect.apply(method, container, args)\n\t\t\t\t\tignoreRuntimePromiseRejection(result)\n\t\t\t\t\tif ((key === 'has' || key === 'unbind') && typeof result !== 'boolean') throw new TypeError()\n\t\t\t\t\tif (key === 'bind' && result !== undefined) throw new TypeError()\n\t\t\t\t\treturn result\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent = Object.getPrototypeOf(current) as object | null\n\t\t}\n\t} catch {\n\t\treturn undefined\n\t}\n\treturn undefined\n}\n\nconst snapshotDataObject = (\n\tvalue: unknown,\n\tlabel: string,\n\tallowed: ReadonlySet<string>\n): Readonly<Record<string, unknown>> => {\n\ttry {\n\t\tif (!value || typeof value !== 'object' || isRuntimeProxy(value) || Array.isArray(value)) throw new TypeError()\n\t\tconst prototype = Object.getPrototypeOf(value)\n\t\tif (prototype !== Object.prototype && prototype !== null) throw new TypeError()\n\t\tif (Object.getOwnPropertySymbols(value).length > 0) throw new TypeError()\n\t\tconst snapshot: Record<string, unknown> = Object.create(null) as Record<string, unknown>\n\t\tlet inspected = 0\n\t\tfor (const key in value) {\n\t\t\tif (inspected >= allowed.size || key.length > 64 || !allowed.has(key)) throw new TypeError()\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)\n\t\t\tif (!descriptor?.enumerable || !('value' in descriptor)) throw new TypeError()\n\t\t\tinspected += 1\n\t\t\tsnapshot[key] = descriptor.value\n\t\t}\n\t\treturn Object.freeze(snapshot)\n\t} catch {\n\t\tthrow new TypeError(`${label} must contain only stable plain data fields`)\n\t}\n}\n\nconst snapshotRegistration = (value: unknown): PerformanceOptions => {\n\tconst registration = snapshotDataObject(value, 'Performance registration options', ROOT_FIELDS)\n\tconst preset = registration.preset\n\tif (preset !== 'development' && preset !== 'production' && preset !== 'custom') {\n\t\tthrow new Error('Unknown performance preset')\n\t}\n\tif (registration.options === undefined) {\n\t\tif (preset === 'custom') throw new TypeError('Performance custom registration options are required')\n\t\treturn Object.freeze({preset})\n\t}\n\tconst options = snapshotDataObject(\n\t\tregistration.options,\n\t\t`Performance ${preset} options`,\n\t\tpreset === 'custom' ? CUSTOM_FIELDS : STANDARD_FIELDS\n\t)\n\treturn Object.freeze({preset, options}) as PerformanceOptions\n}\n\nconst cleanupPerformance = async(performance: ManagedPerformance): Promise<void> => {\n\tlet timer: ReturnType<typeof setTimeout> | undefined\n\ttry {\n\t\tawait Promise.race([\n\t\t\t(async() => {\n\t\t\t\ttry { await performance.shutdown?.() } catch { await performance.shutdown?.() }\n\t\t\t})(),\n\t\t\tnew Promise<never>((_resolve, reject) => {\n\t\t\t\ttimer = setTimeout(\n\t\t\t\t\t() => reject(new Error('performance_registration_cleanup_timeout')),\n\t\t\t\t\tREGISTRATION_CLEANUP_TIMEOUT_MS\n\t\t\t\t)\n\t\t\t})\n\t\t])\n\t} finally {\n\t\tif (timer) clearTimeout(timer)\n\t}\n}\n\nexport async function registerPerformance(container: Container, config: PerformanceOptions): Promise<void> {\n\tif (!container || typeof container !== 'object') {\n\t\tthrow new TypeError('Performance registration requires a valid container')\n\t}\n\tif (registrationsInProgress.has(container)) {\n\t\tthrow new Error('performance_already_registered')\n\t}\n\tregistrationsInProgress.add(container)\n\ttry {\n\t\tconst has = captureContainerMethod(container, 'has') as ((token: symbol) => boolean) | undefined\n\t\tconst get = captureContainerMethod(container, 'get') as ((token: symbol) => unknown) | undefined\n\t\tconst tryGet = captureContainerMethod(container, 'tryGet') as ((token: symbol) => unknown) | undefined\n\t\tconst bind = captureContainerMethod(container, 'bind') as ((token: symbol, value: unknown) => void) | undefined\n\t\tconst unbind = captureContainerMethod(container, 'unbind') as ((token: symbol) => boolean) | undefined\n\t\tif (!has || !get || !tryGet || !bind || !unbind) {\n\t\t\tthrow new TypeError('Performance registration requires a valid reversible container')\n\t\t}\n\t\tlet alreadyRegistered: boolean\n\t\ttry {\n\t\t\talreadyRegistered = has(TOK.Performance) || tryGet(TOK.Performance) !== undefined\n\t\t} catch {\n\t\t\tthrow new Error('performance_container_lookup_failed')\n\t\t}\n\t\tif (alreadyRegistered) throw new Error('performance_already_registered')\n\t\tconst registration = snapshotRegistration(config)\n\t\tawait registerPerformanceUnlocked({has, get, tryGet, bind, unbind}, registration)\n\t} finally {\n\t\tregistrationsInProgress.delete(container)\n\t}\n}\n\nasync function registerPerformanceUnlocked(container: {\n\thas(token: symbol): boolean\n\tget(token: symbol): unknown\n\ttryGet(token: symbol): unknown\n\tbind(token: symbol, value: unknown): void\n\tunbind(token: symbol): boolean\n}, config: PerformanceOptions): Promise<void> {\n\tlet clock: Clock\n\ttry {\n\t\tclock = container.get(TOK.Clock) as Clock\n\t\tif (clock === undefined || clock === null) throw new TypeError()\n\t} catch {\n\t\tthrow new Error('performance_invalid_clock')\n\t}\n\tlet errors: Errors | undefined\n\tlet tracer: Tracing | undefined\n\tlet lifecycle: LifecyclePort | undefined\n\ttry {\n\t\terrors = container.tryGet(TOK.Errors) as Errors | undefined\n\t\ttracer = container.tryGet(TOK.Tracing) as Tracing | undefined\n\t\tlifecycle = container.tryGet(TOK.Lifecycle) as LifecyclePort | undefined\n\t} catch {\n\t\tthrow new Error('performance_dependency_resolution_failed')\n\t}\n\tconst presetDependencies = {\n\t\tclock,\n\t\t...(errors ? {errors} : {}),\n\t\t...(tracer ? {tracer} : {}),\n\t\t...(lifecycle ? {lifecycle} : {})\n\t}\n\tlet performance: ManagedPerformance\n\tif (config.preset === 'development') {\n\t\tconst {createDevelopmentPerformance} = await import('./public/development')\n\t\tperformance = await createDevelopmentPerformance({...config.options, ...presetDependencies})\n\t} else if (config.preset === 'production') {\n\t\tconst {createProductionPerformance} = await import('./public/production')\n\t\tperformance = await createProductionPerformance({...config.options, ...presetDependencies})\n\t} else {\n\t\tconst {createCustomPerformance} = await import('./public/custom')\n\t\tperformance = await createCustomPerformance({...config.options, ...presetDependencies})\n\t}\n\tlet bindAttempted = false\n\tconst hasPerformanceBinding = (): boolean =>\n\t\tcontainer.has(TOK.Performance) || container.tryGet(TOK.Performance) !== undefined\n\ttry {\n\t\tif (hasPerformanceBinding()) {\n\t\t\tthrow new Error('Performance service was registered during runtime creation')\n\t\t}\n\t\tbindAttempted = true\n\t\tcontainer.bind(TOK.Performance, performance)\n\t\tif (!container.has(TOK.Performance) || container.tryGet(TOK.Performance) !== performance) {\n\t\t\tthrow new Error('Performance container did not retain the expected binding')\n\t\t}\n\t} catch(error) {\n\t\tconst cleanupErrors: unknown[] = []\n\t\ttry {\n\t\t\tif (bindAttempted) {\n\t\t\t\tconst retained = container.tryGet(TOK.Performance)\n\t\t\t\tif (retained === performance) {\n\t\t\t\t\tcontainer.unbind(TOK.Performance)\n\t\t\t\t\tif (container.tryGet(TOK.Performance) === performance) {\n\t\t\t\t\t\tthrow new Error('Performance registration rollback failed')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch(cleanupError) {\n\t\t\tcleanupErrors.push(cleanupError)\n\t\t}\n\t\ttry { await cleanupPerformance(performance) } catch(cleanupError) { cleanupErrors.push(cleanupError) }\n\t\tif (cleanupErrors.length > 0) {\n\t\t\tthrow new AggregateError([error, ...cleanupErrors], 'Performance registration and rollback failed')\n\t\t}\n\t\tthrow error\n\t}\n}\n\nexport type {DevelopmentPerformanceOptions} from './public/development'\nexport type {ProductionPerformanceOptions} from './public/production'\nexport type {CustomPerformanceOptions} from './public/custom'\nexport type {PerformanceEventExporterPort, PerformancePort} from '@ooopsstudio/core/ports/performance'\nexport type {ManagedPerformance, PerformanceRuntimeState, PerformanceSinkState, PerformanceStatus} from './types/ports'\n"]}