@smoothbricks/lmao 0.1.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.
- package/README.md +269 -0
- package/dist/allocator.wasm +0 -0
- package/dist/bun/preload.d.ts +11 -0
- package/dist/bun/preload.d.ts.map +1 -0
- package/dist/bun/preload.js +10 -0
- package/dist/bun/trace-preload.d.ts +8 -0
- package/dist/bun/trace-preload.d.ts.map +1 -0
- package/dist/bun/trace-preload.js +12 -0
- package/dist/es.d.ts +8 -0
- package/dist/es.d.ts.map +1 -0
- package/dist/es.js +9 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/lib/JsBufferStrategy.d.ts +49 -0
- package/dist/lib/JsBufferStrategy.d.ts.map +1 -0
- package/dist/lib/JsBufferStrategy.js +60 -0
- package/dist/lib/archive/chunkCompaction.d.ts +15 -0
- package/dist/lib/archive/chunkCompaction.d.ts.map +1 -0
- package/dist/lib/archive/chunkCompaction.js +24 -0
- package/dist/lib/archive/chunkEnvelope.d.ts +21 -0
- package/dist/lib/archive/chunkEnvelope.d.ts.map +1 -0
- package/dist/lib/archive/chunkEnvelope.js +55 -0
- package/dist/lib/archive/chunkRouting.d.ts +10 -0
- package/dist/lib/archive/chunkRouting.d.ts.map +1 -0
- package/dist/lib/archive/chunkRouting.js +47 -0
- package/dist/lib/archive/chunkStats.d.ts +12 -0
- package/dist/lib/archive/chunkStats.d.ts.map +1 -0
- package/dist/lib/archive/chunkStats.js +10 -0
- package/dist/lib/archive/index.d.ts +5 -0
- package/dist/lib/archive/index.d.ts.map +1 -0
- package/dist/lib/archive/index.js +4 -0
- package/dist/lib/arrow/capacityStats.d.ts +9 -0
- package/dist/lib/arrow/capacityStats.d.ts.map +1 -0
- package/dist/lib/arrow/capacityStats.js +231 -0
- package/dist/lib/arrow/dictionaries.d.ts +27 -0
- package/dist/lib/arrow/dictionaries.d.ts.map +1 -0
- package/dist/lib/arrow/dictionaries.js +135 -0
- package/dist/lib/arrow/flechette.d.ts +40 -0
- package/dist/lib/arrow/flechette.d.ts.map +1 -0
- package/dist/lib/arrow/flechette.js +67 -0
- package/dist/lib/arrow/utils.d.ts +38 -0
- package/dist/lib/arrow/utils.d.ts.map +1 -0
- package/dist/lib/arrow/utils.js +112 -0
- package/dist/lib/buffer/Nanoseconds.d.ts +109 -0
- package/dist/lib/buffer/Nanoseconds.d.ts.map +1 -0
- package/dist/lib/buffer/Nanoseconds.js +86 -0
- package/dist/lib/bufferStrategy.d.ts +95 -0
- package/dist/lib/bufferStrategy.d.ts.map +1 -0
- package/dist/lib/bufferStrategy.js +1 -0
- package/dist/lib/capacityTuning.d.ts +50 -0
- package/dist/lib/capacityTuning.d.ts.map +1 -0
- package/dist/lib/capacityTuning.js +65 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts +35 -0
- package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/evaluatorGenerator.js +199 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +139 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/fixedPositionWriterGenerator.js +289 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts +115 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -0
- package/dist/lib/codegen/spanLoggerGenerator.js +575 -0
- package/dist/lib/convertToArrow.d.ts +40 -0
- package/dist/lib/convertToArrow.d.ts.map +1 -0
- package/dist/lib/convertToArrow.js +1467 -0
- package/dist/lib/defineOpContext.d.ts +96 -0
- package/dist/lib/defineOpContext.d.ts.map +1 -0
- package/dist/lib/defineOpContext.js +227 -0
- package/dist/lib/errors/Blocked.d.ts +113 -0
- package/dist/lib/errors/Blocked.d.ts.map +1 -0
- package/dist/lib/errors/Blocked.js +68 -0
- package/dist/lib/errors/CodeError.d.ts +101 -0
- package/dist/lib/errors/CodeError.d.ts.map +1 -0
- package/dist/lib/errors/CodeError.js +42 -0
- package/dist/lib/errors/RetriesExhausted.d.ts +67 -0
- package/dist/lib/errors/RetriesExhausted.d.ts.map +1 -0
- package/dist/lib/errors/RetriesExhausted.js +31 -0
- package/dist/lib/errors/Transient.d.ts +115 -0
- package/dist/lib/errors/Transient.d.ts.map +1 -0
- package/dist/lib/errors/Transient.js +54 -0
- package/dist/lib/errors/index.d.ts +14 -0
- package/dist/lib/errors/index.d.ts.map +1 -0
- package/dist/lib/errors/index.js +16 -0
- package/dist/lib/errors/retry-policy.d.ts +60 -0
- package/dist/lib/errors/retry-policy.d.ts.map +1 -0
- package/dist/lib/errors/retry-policy.js +54 -0
- package/dist/lib/flushScheduler.d.ts +162 -0
- package/dist/lib/flushScheduler.d.ts.map +1 -0
- package/dist/lib/flushScheduler.js +388 -0
- package/dist/lib/library.d.ts +149 -0
- package/dist/lib/library.d.ts.map +1 -0
- package/dist/lib/library.js +588 -0
- package/dist/lib/logApi.d.ts +61 -0
- package/dist/lib/logApi.d.ts.map +1 -0
- package/dist/lib/logApi.js +12 -0
- package/dist/lib/logBinding.d.ts +63 -0
- package/dist/lib/logBinding.d.ts.map +1 -0
- package/dist/lib/logBinding.js +1 -0
- package/dist/lib/op.d.ts +105 -0
- package/dist/lib/op.d.ts.map +1 -0
- package/dist/lib/op.js +59 -0
- package/dist/lib/opContext/contextTypes.d.ts +88 -0
- package/dist/lib/opContext/contextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/contextTypes.js +34 -0
- package/dist/lib/opContext/createOpGroup.d.ts +57 -0
- package/dist/lib/opContext/createOpGroup.d.ts.map +1 -0
- package/dist/lib/opContext/createOpGroup.js +341 -0
- package/dist/lib/opContext/defineOp.d.ts +83 -0
- package/dist/lib/opContext/defineOp.d.ts.map +1 -0
- package/dist/lib/opContext/defineOp.js +197 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts +58 -0
- package/dist/lib/opContext/featureFlagTypes.d.ts.map +1 -0
- package/dist/lib/opContext/featureFlagTypes.js +1 -0
- package/dist/lib/opContext/index.d.ts +13 -0
- package/dist/lib/opContext/index.d.ts.map +1 -0
- package/dist/lib/opContext/index.js +15 -0
- package/dist/lib/opContext/opGroupTypes.d.ts +250 -0
- package/dist/lib/opContext/opGroupTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opGroupTypes.js +31 -0
- package/dist/lib/opContext/opTypes.d.ts +48 -0
- package/dist/lib/opContext/opTypes.d.ts.map +1 -0
- package/dist/lib/opContext/opTypes.js +7 -0
- package/dist/lib/opContext/spanContextTypes.d.ts +347 -0
- package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -0
- package/dist/lib/opContext/spanContextTypes.js +1 -0
- package/dist/lib/opContext/types.d.ts +297 -0
- package/dist/lib/opContext/types.d.ts.map +1 -0
- package/dist/lib/opContext/types.js +16 -0
- package/dist/lib/result.d.ts +308 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +359 -0
- package/dist/lib/schema/LogSchema.d.ts +62 -0
- package/dist/lib/schema/LogSchema.d.ts.map +1 -0
- package/dist/lib/schema/LogSchema.js +134 -0
- package/dist/lib/schema/builder.d.ts +12 -0
- package/dist/lib/schema/builder.d.ts.map +1 -0
- package/dist/lib/schema/builder.js +169 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts +60 -0
- package/dist/lib/schema/defineFeatureFlags.d.ts.map +1 -0
- package/dist/lib/schema/defineFeatureFlags.js +29 -0
- package/dist/lib/schema/defineLogSchema.d.ts +87 -0
- package/dist/lib/schema/defineLogSchema.d.ts.map +1 -0
- package/dist/lib/schema/defineLogSchema.js +171 -0
- package/dist/lib/schema/evaluator.d.ts +267 -0
- package/dist/lib/schema/evaluator.d.ts.map +1 -0
- package/dist/lib/schema/evaluator.js +169 -0
- package/dist/lib/schema/extend.d.ts +14 -0
- package/dist/lib/schema/extend.d.ts.map +1 -0
- package/dist/lib/schema/extend.js +51 -0
- package/dist/lib/schema/systemSchema.d.ts +112 -0
- package/dist/lib/schema/systemSchema.d.ts.map +1 -0
- package/dist/lib/schema/systemSchema.js +260 -0
- package/dist/lib/schema/typeGuards.d.ts +52 -0
- package/dist/lib/schema/typeGuards.d.ts.map +1 -0
- package/dist/lib/schema/typeGuards.js +127 -0
- package/dist/lib/schema/types.d.ts +156 -0
- package/dist/lib/schema/types.d.ts.map +1 -0
- package/dist/lib/schema/types.js +4 -0
- package/dist/lib/spanBuffer.d.ts +133 -0
- package/dist/lib/spanBuffer.d.ts.map +1 -0
- package/dist/lib/spanBuffer.js +442 -0
- package/dist/lib/spanBufferHelpers.d.ts +53 -0
- package/dist/lib/spanBufferHelpers.d.ts.map +1 -0
- package/dist/lib/spanBufferHelpers.js +65 -0
- package/dist/lib/spanBufferStats.d.ts +38 -0
- package/dist/lib/spanBufferStats.d.ts.map +1 -0
- package/dist/lib/spanBufferStats.js +1 -0
- package/dist/lib/spanContext.d.ts +141 -0
- package/dist/lib/spanContext.d.ts.map +1 -0
- package/dist/lib/spanContext.js +763 -0
- package/dist/lib/sqlite/index.d.ts +14 -0
- package/dist/lib/sqlite/index.d.ts.map +1 -0
- package/dist/lib/sqlite/index.js +12 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts +24 -0
- package/dist/lib/sqlite/sqlite-async-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-async-writer.js +65 -0
- package/dist/lib/sqlite/sqlite-common.d.ts +37 -0
- package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-common.js +207 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts +25 -0
- package/dist/lib/sqlite/sqlite-d1.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-d1.js +67 -0
- package/dist/lib/sqlite/sqlite-db.d.ts +29 -0
- package/dist/lib/sqlite/sqlite-db.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-db.js +1 -0
- package/dist/lib/sqlite/sqlite-node.d.ts +16 -0
- package/dist/lib/sqlite/sqlite-node.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-node.js +68 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts +39 -0
- package/dist/lib/sqlite/sqlite-writer.d.ts.map +1 -0
- package/dist/lib/sqlite/sqlite-writer.js +78 -0
- package/dist/lib/testing/bun-harness.d.ts +150 -0
- package/dist/lib/testing/bun-harness.d.ts.map +1 -0
- package/dist/lib/testing/bun-harness.js +729 -0
- package/dist/lib/testing/extractFacts.d.ts +73 -0
- package/dist/lib/testing/extractFacts.d.ts.map +1 -0
- package/dist/lib/testing/extractFacts.js +237 -0
- package/dist/lib/testing/facts.d.ts +235 -0
- package/dist/lib/testing/facts.d.ts.map +1 -0
- package/dist/lib/testing/facts.js +209 -0
- package/dist/lib/testing/index.d.ts +58 -0
- package/dist/lib/testing/index.d.ts.map +1 -0
- package/dist/lib/testing/index.js +74 -0
- package/dist/lib/testing/queryable-span.d.ts +39 -0
- package/dist/lib/testing/queryable-span.d.ts.map +1 -0
- package/dist/lib/testing/queryable-span.js +58 -0
- package/dist/lib/testing/span-query.d.ts +21 -0
- package/dist/lib/testing/span-query.d.ts.map +1 -0
- package/dist/lib/testing/span-query.js +47 -0
- package/dist/lib/testing/stdio-replay.d.ts +4 -0
- package/dist/lib/testing/stdio-replay.d.ts.map +1 -0
- package/dist/lib/testing/stdio-replay.js +42 -0
- package/dist/lib/testing/trace-query.d.ts +59 -0
- package/dist/lib/testing/trace-query.d.ts.map +1 -0
- package/dist/lib/testing/trace-query.js +462 -0
- package/dist/lib/testing/vitest-harness.d.ts +135 -0
- package/dist/lib/testing/vitest-harness.d.ts.map +1 -0
- package/dist/lib/testing/vitest-harness.js +486 -0
- package/dist/lib/threadId.d.ts +58 -0
- package/dist/lib/threadId.d.ts.map +1 -0
- package/dist/lib/threadId.js +123 -0
- package/dist/lib/traceContext.d.ts +116 -0
- package/dist/lib/traceContext.d.ts.map +1 -0
- package/dist/lib/traceContext.js +37 -0
- package/dist/lib/traceId.d.ts +78 -0
- package/dist/lib/traceId.d.ts.map +1 -0
- package/dist/lib/traceId.js +87 -0
- package/dist/lib/traceRoot.d.ts +133 -0
- package/dist/lib/traceRoot.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.d.ts +75 -0
- package/dist/lib/traceRoot.es.d.ts.map +1 -0
- package/dist/lib/traceRoot.es.js +129 -0
- package/dist/lib/traceRoot.js +19 -0
- package/dist/lib/traceRoot.node.d.ts +77 -0
- package/dist/lib/traceRoot.node.d.ts.map +1 -0
- package/dist/lib/traceRoot.node.js +133 -0
- package/dist/lib/traceRoot.universal.d.ts +3 -0
- package/dist/lib/traceRoot.universal.d.ts.map +1 -0
- package/dist/lib/traceRoot.universal.js +17 -0
- package/dist/lib/tracer.d.ts +296 -0
- package/dist/lib/tracer.d.ts.map +1 -0
- package/dist/lib/tracer.js +346 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts +56 -0
- package/dist/lib/tracers/ArrayQueueTracer.d.ts.map +1 -0
- package/dist/lib/tracers/ArrayQueueTracer.js +67 -0
- package/dist/lib/tracers/CompositeTracer.d.ts +24 -0
- package/dist/lib/tracers/CompositeTracer.d.ts.map +1 -0
- package/dist/lib/tracers/CompositeTracer.js +57 -0
- package/dist/lib/tracers/NoOpTracer.d.ts +58 -0
- package/dist/lib/tracers/NoOpTracer.d.ts.map +1 -0
- package/dist/lib/tracers/NoOpTracer.js +41 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts +42 -0
- package/dist/lib/tracers/SQLiteTracer.d.ts.map +1 -0
- package/dist/lib/tracers/SQLiteTracer.js +84 -0
- package/dist/lib/tracers/StdioTracer.d.ts +83 -0
- package/dist/lib/tracers/StdioTracer.d.ts.map +1 -0
- package/dist/lib/tracers/StdioTracer.js +270 -0
- package/dist/lib/tracers/TestTracer.d.ts +95 -0
- package/dist/lib/tracers/TestTracer.d.ts.map +1 -0
- package/dist/lib/tracers/TestTracer.js +87 -0
- package/dist/lib/tracers/index.d.ts +12 -0
- package/dist/lib/tracers/index.d.ts.map +1 -0
- package/dist/lib/tracers/index.js +11 -0
- package/dist/lib/types.d.ts +366 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/utf8Cache.d.ts +111 -0
- package/dist/lib/utf8Cache.d.ts.map +1 -0
- package/dist/lib/utf8Cache.js +177 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts +88 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -0
- package/dist/lib/wasm/WasmBufferStrategy.js +138 -0
- package/dist/lib/wasm/wasmAllocator.d.ts +109 -0
- package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -0
- package/dist/lib/wasm/wasmAllocator.js +227 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts +123 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -0
- package/dist/lib/wasm/wasmSpanBuffer.js +772 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts +167 -0
- package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -0
- package/dist/lib/wasm/wasmTraceRoot.js +264 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +8 -0
- package/dist/testing.d.ts +18 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/package.json +193 -0
- package/src/bun/preload.ts +11 -0
- package/src/bun/trace-preload.ts +14 -0
- package/src/es.ts +11 -0
- package/src/index.ts +194 -0
- package/src/lib/JsBufferStrategy.ts +102 -0
- package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +485 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +390 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +647 -0
- package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +292 -0
- package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +354 -0
- package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +127 -0
- package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +392 -0
- package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +389 -0
- package/src/lib/__tests__/arrow-conversion-algorithms.test.ts +54 -0
- package/src/lib/__tests__/arrow-test-helpers.ts +71 -0
- package/src/lib/__tests__/binary-e2e.test.ts +203 -0
- package/src/lib/__tests__/buffer-overflow-op-api.test.ts +608 -0
- package/src/lib/__tests__/buffer-overflow.test.ts +612 -0
- package/src/lib/__tests__/capacity-tuning.test.ts +544 -0
- package/src/lib/__tests__/effective-schema.test.ts +439 -0
- package/src/lib/__tests__/flechette.test.ts +42 -0
- package/src/lib/__tests__/flushScheduler.test.ts +537 -0
- package/src/lib/__tests__/integration.test.ts +600 -0
- package/src/lib/__tests__/library.test.ts +934 -0
- package/src/lib/__tests__/nested-library-tasks.test.ts +849 -0
- package/src/lib/__tests__/op-context-binding.test.ts +135 -0
- package/src/lib/__tests__/op-metadata.test.ts +198 -0
- package/src/lib/__tests__/op-type-safety.test.ts +71 -0
- package/src/lib/__tests__/package-exports.test.ts +57 -0
- package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +319 -0
- package/src/lib/__tests__/remapped-buffer-view.test.ts +635 -0
- package/src/lib/__tests__/scope-attributes.test.ts +348 -0
- package/src/lib/__tests__/span-lifecycle.test.ts +680 -0
- package/src/lib/__tests__/sync-async-trace.test.ts +435 -0
- package/src/lib/__tests__/test-helpers.ts +318 -0
- package/src/lib/__tests__/timestamp.test.ts +259 -0
- package/src/lib/__tests__/trace-archive-primitives.test.ts +98 -0
- package/src/lib/__tests__/traceContext-type-enforcement.test.ts +271 -0
- package/src/lib/__tests__/tracer.test.ts +211 -0
- package/src/lib/__tests__/type-narrowing.test.ts +137 -0
- package/src/lib/archive/chunkCompaction.ts +44 -0
- package/src/lib/archive/chunkEnvelope.ts +79 -0
- package/src/lib/archive/chunkRouting.ts +70 -0
- package/src/lib/archive/chunkStats.ts +25 -0
- package/src/lib/archive/index.ts +4 -0
- package/src/lib/arrow/capacityStats.ts +340 -0
- package/src/lib/arrow/dictionaries.ts +159 -0
- package/src/lib/arrow/flechette.ts +114 -0
- package/src/lib/arrow/utils.ts +126 -0
- package/src/lib/buffer/Nanoseconds.ts +131 -0
- package/src/lib/bufferStrategy.ts +106 -0
- package/src/lib/capacityTuning.ts +102 -0
- package/src/lib/codegen/__tests__/__snapshots__/evaluatorGenerator.test.ts.snap +160 -0
- package/src/lib/codegen/__tests__/__snapshots__/scopeGenerator.test.ts.snap +196 -0
- package/src/lib/codegen/__tests__/__snapshots__/spanLoggerGenerator.test.ts.snap +1965 -0
- package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +516 -0
- package/src/lib/codegen/__tests__/nullBitmap.test.ts +207 -0
- package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +237 -0
- package/src/lib/codegen/evaluatorGenerator.ts +309 -0
- package/src/lib/codegen/fixedPositionWriterGenerator.ts +444 -0
- package/src/lib/codegen/spanLoggerGenerator.ts +715 -0
- package/src/lib/convertToArrow.ts +1805 -0
- package/src/lib/defineOpContext.ts +398 -0
- package/src/lib/errors/Blocked.ts +165 -0
- package/src/lib/errors/CodeError.ts +132 -0
- package/src/lib/errors/RetriesExhausted.ts +78 -0
- package/src/lib/errors/Transient.ts +168 -0
- package/src/lib/errors/__tests__/Blocked-config.test.ts +152 -0
- package/src/lib/errors/__tests__/Transient.test.ts +129 -0
- package/src/lib/errors/__tests__/retry-policy.test.ts +85 -0
- package/src/lib/errors/index.ts +24 -0
- package/src/lib/errors/retry-policy.ts +87 -0
- package/src/lib/flushScheduler.ts +509 -0
- package/src/lib/library.ts +682 -0
- package/src/lib/logApi.ts +70 -0
- package/src/lib/logBinding.ts +67 -0
- package/src/lib/op.ts +103 -0
- package/src/lib/opContext/__tests__/retry.test.ts +764 -0
- package/src/lib/opContext/contextTypes.ts +130 -0
- package/src/lib/opContext/createOpGroup.ts +456 -0
- package/src/lib/opContext/defineOp.ts +281 -0
- package/src/lib/opContext/featureFlagTypes.ts +54 -0
- package/src/lib/opContext/index.ts +16 -0
- package/src/lib/opContext/opGroupTypes.ts +342 -0
- package/src/lib/opContext/opTypes.ts +80 -0
- package/src/lib/opContext/spanContextTypes.ts +398 -0
- package/src/lib/opContext/types.ts +403 -0
- package/src/lib/result.ts +550 -0
- package/src/lib/schema/LogSchema.ts +153 -0
- package/src/lib/schema/__tests__/defineLogSchema.test.ts +342 -0
- package/src/lib/schema/__tests__/featureFlags.test.ts +443 -0
- package/src/lib/schema/builder.ts +201 -0
- package/src/lib/schema/defineFeatureFlags.ts +91 -0
- package/src/lib/schema/defineLogSchema.ts +291 -0
- package/src/lib/schema/evaluator.ts +404 -0
- package/src/lib/schema/extend.ts +69 -0
- package/src/lib/schema/systemSchema.ts +339 -0
- package/src/lib/schema/typeGuards.ts +163 -0
- package/src/lib/schema/types.ts +265 -0
- package/src/lib/spanBuffer.ts +571 -0
- package/src/lib/spanBufferHelpers.ts +73 -0
- package/src/lib/spanBufferStats.ts +40 -0
- package/src/lib/spanContext.ts +1566 -0
- package/src/lib/sqlite/__tests__/sqlite-common.test.ts +89 -0
- package/src/lib/sqlite/index.ts +26 -0
- package/src/lib/sqlite/sqlite-async-writer.ts +101 -0
- package/src/lib/sqlite/sqlite-common.ts +309 -0
- package/src/lib/sqlite/sqlite-d1.ts +104 -0
- package/src/lib/sqlite/sqlite-db.ts +32 -0
- package/src/lib/sqlite/sqlite-node.ts +83 -0
- package/src/lib/sqlite/sqlite-writer.ts +128 -0
- package/src/lib/testing/TRACE-TESTING.md +100 -0
- package/src/lib/testing/__tests__/bun-harness.test.ts +108 -0
- package/src/lib/testing/__tests__/extractFacts.test.ts +279 -0
- package/src/lib/testing/__tests__/facts.test.ts +324 -0
- package/src/lib/testing/__tests__/vitest-harness.test.ts +32 -0
- package/src/lib/testing/bun-harness.ts +990 -0
- package/src/lib/testing/extractFacts.ts +362 -0
- package/src/lib/testing/facts.ts +470 -0
- package/src/lib/testing/index.ts +141 -0
- package/src/lib/testing/queryable-span.ts +108 -0
- package/src/lib/testing/span-query.ts +65 -0
- package/src/lib/testing/stdio-replay.ts +50 -0
- package/src/lib/testing/trace-query.ts +329 -0
- package/src/lib/testing/vitest-harness.ts +691 -0
- package/src/lib/threadId.ts +135 -0
- package/src/lib/traceContext.ts +182 -0
- package/src/lib/traceId.ts +142 -0
- package/src/lib/traceRoot.es.ts +157 -0
- package/src/lib/traceRoot.node.ts +170 -0
- package/src/lib/traceRoot.ts +154 -0
- package/src/lib/traceRoot.universal.ts +22 -0
- package/src/lib/tracer.ts +896 -0
- package/src/lib/tracers/ArrayQueueTracer.ts +76 -0
- package/src/lib/tracers/CompositeTracer.ts +76 -0
- package/src/lib/tracers/NoOpTracer.ts +73 -0
- package/src/lib/tracers/SQLiteTracer.ts +115 -0
- package/src/lib/tracers/StdioTracer.ts +380 -0
- package/src/lib/tracers/TestTracer.ts +146 -0
- package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +184 -0
- package/src/lib/tracers/__tests__/NoOpTracer.test.ts +204 -0
- package/src/lib/tracers/__tests__/StdioTracer.test.ts +313 -0
- package/src/lib/tracers/__tests__/TestTracer.test.ts +200 -0
- package/src/lib/tracers/index.ts +12 -0
- package/src/lib/types.ts +498 -0
- package/src/lib/utf8Cache.ts +201 -0
- package/src/lib/wasm/WasmBufferStrategy.ts +219 -0
- package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +256 -0
- package/src/lib/wasm/__tests__/wasm-integration.test.ts +476 -0
- package/src/lib/wasm/__tests__/wasmAllocator.test.ts +699 -0
- package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +449 -0
- package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +390 -0
- package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +444 -0
- package/src/lib/wasm/allocator.zig +945 -0
- package/src/lib/wasm/wasmAllocator.ts +469 -0
- package/src/lib/wasm/wasmSpanBuffer.ts +1014 -0
- package/src/lib/wasm/wasmTraceRoot.ts +315 -0
- package/src/node.ts +10 -0
- package/src/testing.ts +18 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpanBuffer - Unified memory layout for trace logging
|
|
3
|
+
*
|
|
4
|
+
* This module implements the unified SpanBuffer design from
|
|
5
|
+
* specs/lmao/01b_columnar_buffer_architecture.md "Unified SpanBuffer Memory Layout"
|
|
6
|
+
*
|
|
7
|
+
* **Memory Layout**
|
|
8
|
+
*
|
|
9
|
+
* Single `_system` ArrayBuffer contains:
|
|
10
|
+
* - timestamps (BigInt64Array) at offset 0
|
|
11
|
+
* - operations (Uint8Array) at offset capacity * 8
|
|
12
|
+
* - identity (Uint8Array) at offset capacity * 9 (for root/child, not chained)
|
|
13
|
+
*
|
|
14
|
+
* **Buffer Types**
|
|
15
|
+
* - ROOT: 13 + traceId.length bytes identity (threadId + spanId + len + traceId)
|
|
16
|
+
* - CHILD: 12 bytes identity (threadId + spanId only, parent via pointer)
|
|
17
|
+
* - CHAINED: 0 bytes identity (shares _identity reference from first buffer)
|
|
18
|
+
*
|
|
19
|
+
* **Key Design Decisions**
|
|
20
|
+
* - Parent ancestry via pointer (not copied bytes) - isParentOf is O(1)
|
|
21
|
+
* - traceId walks up parent chain to root
|
|
22
|
+
* - System columns at fixed offsets for all buffer types
|
|
23
|
+
* - arrow-builder used ONLY for lazy attribute columns (not system columns)
|
|
24
|
+
*
|
|
25
|
+
* @module spanBuffer
|
|
26
|
+
*/
|
|
27
|
+
import { DEFAULT_BUFFER_CAPACITY, getColumnBufferClass } from '@smoothbricks/arrow-builder';
|
|
28
|
+
import { checkCapacityTuning } from './capacityTuning.js';
|
|
29
|
+
import { textEncoder } from './spanBufferHelpers.js';
|
|
30
|
+
import { writeThreadIdToUint64Array } from './threadId.js';
|
|
31
|
+
/**
|
|
32
|
+
* Empty frozen scope object - shared singleton to avoid allocations.
|
|
33
|
+
* Used as default _scopeValues for all buffers until setScope() is called.
|
|
34
|
+
*/
|
|
35
|
+
export const EMPTY_SCOPE = Object.freeze({});
|
|
36
|
+
const traceIdDecoder = new TextDecoder();
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Thread-local state (generated once per process/worker)
|
|
39
|
+
// These are used by the generated class code via the constructorPreamble
|
|
40
|
+
// ============================================================================
|
|
41
|
+
/**
|
|
42
|
+
* Reset thread-local state (for testing only).
|
|
43
|
+
* Note: The actual state is in the generated class constructorPreamble.
|
|
44
|
+
* This function resets it by clearing the class cache.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export function _resetSpanBufferState() {
|
|
48
|
+
// Clear the class cache to force regeneration with fresh state
|
|
49
|
+
// The generated constructorPreamble creates its own PROCESS_THREAD_ID and nextSpanId
|
|
50
|
+
// which are reset when the class is regenerated
|
|
51
|
+
// Note: WeakMap doesn't have a clear() method, but schemas are typically
|
|
52
|
+
// long-lived so this is mainly for testing where we create new schemas
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Test utilities for accessing generated buffer properties
|
|
56
|
+
* Works directly with SpanBuffer type from this module
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export const SpanBufferTestUtils = {
|
|
60
|
+
/**
|
|
61
|
+
* Get a column's null bitmap (generated property)
|
|
62
|
+
*/
|
|
63
|
+
getNullBitmap(buffer, columnName) {
|
|
64
|
+
return buffer.getNullsIfAllocated(columnName);
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Set buffer capacity (for testing)
|
|
68
|
+
*/
|
|
69
|
+
setCapacity(buffer, capacity) {
|
|
70
|
+
// Cast to mutable for test manipulation
|
|
71
|
+
buffer._capacity = capacity;
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Set buffer writeIndex (for testing)
|
|
75
|
+
*/
|
|
76
|
+
setWriteIndex(buffer, writeIndex) {
|
|
77
|
+
buffer._writeIndex = writeIndex;
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Get buffer writeIndex (for testing)
|
|
81
|
+
* Accepts ColumnBuffer (from ColumnWriter._buffer) but casts to AnySpanBuffer
|
|
82
|
+
* since at runtime all buffers are AnySpanBuffer instances
|
|
83
|
+
*/
|
|
84
|
+
getWriteIndex(buffer) {
|
|
85
|
+
return buffer._writeIndex;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
function isGeneratedSpanBufferClass(ctor) {
|
|
89
|
+
const prototype = Reflect.get(ctor, 'prototype');
|
|
90
|
+
if (typeof prototype !== 'object' || prototype === null) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return (typeof Reflect.get(prototype, 'getOrCreateOverflow') === 'function' &&
|
|
94
|
+
typeof Reflect.get(prototype, 'isParentOf') === 'function' &&
|
|
95
|
+
typeof Reflect.get(prototype, 'isChildOf') === 'function');
|
|
96
|
+
}
|
|
97
|
+
function isSpanBufferConstructorForSchema(ctor, schema) {
|
|
98
|
+
return (typeof ctor === 'function' &&
|
|
99
|
+
Reflect.get(ctor, 'schema') === schema &&
|
|
100
|
+
typeof Reflect.get(ctor, 'stats') === 'object');
|
|
101
|
+
}
|
|
102
|
+
function getSpanBufferConstructorForBuffer(buffer) {
|
|
103
|
+
const ctor = buffer.constructor;
|
|
104
|
+
if (!isSpanBufferConstructorForSchema(ctor, buffer._logSchema)) {
|
|
105
|
+
throw new TypeError('Buffer constructor does not match buffer schema');
|
|
106
|
+
}
|
|
107
|
+
return ctor;
|
|
108
|
+
}
|
|
109
|
+
function createSpanBufferConstructor(schema, generatedClass) {
|
|
110
|
+
return Object.assign(generatedClass, {
|
|
111
|
+
schema,
|
|
112
|
+
stats: {
|
|
113
|
+
capacity: DEFAULT_BUFFER_CAPACITY,
|
|
114
|
+
totalWrites: 0,
|
|
115
|
+
spansCreated: 0,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Cache for generated SpanBuffer classes per schema.
|
|
121
|
+
* Key is the schema object reference (WeakMap for GC).
|
|
122
|
+
*/
|
|
123
|
+
const spanBufferClassCache = new WeakMap();
|
|
124
|
+
/**
|
|
125
|
+
* Get or create a SpanBuffer class for the given schema.
|
|
126
|
+
*
|
|
127
|
+
* The generated class has static `schema` and `stats` properties:
|
|
128
|
+
* - `schema`: The LogSchema used to generate this class
|
|
129
|
+
* - `stats`: Shared SpanBufferStats for all instances from same defineOpContext
|
|
130
|
+
*
|
|
131
|
+
* Classes are cached per schema (WeakMap keyed by schema object).
|
|
132
|
+
*
|
|
133
|
+
* @param schema - LogSchema defining the buffer structure
|
|
134
|
+
* @returns SpanBufferConstructor with static schema and stats properties
|
|
135
|
+
*/
|
|
136
|
+
export function getSpanBufferClass(schema) {
|
|
137
|
+
const cached = spanBufferClassCache.get(schema);
|
|
138
|
+
if (isSpanBufferConstructorForSchema(cached, schema)) {
|
|
139
|
+
return cached;
|
|
140
|
+
}
|
|
141
|
+
// ==========================================================================
|
|
142
|
+
// GENERATED CODE EXTENSION
|
|
143
|
+
// ==========================================================================
|
|
144
|
+
// The constructorPreamble and methods strings below are passed to new Function() by
|
|
145
|
+
// arrow-builder's columnBufferGenerator. They MUST be pure JavaScript:
|
|
146
|
+
// - NO TypeScript type annotations (: Type)
|
|
147
|
+
// - NO non-null assertions (!)
|
|
148
|
+
// - NO comments (waste of runtime parsing)
|
|
149
|
+
//
|
|
150
|
+
// V8 IN-OBJECT PROPERTY OPTIMIZATION:
|
|
151
|
+
// Property assignment order determines which properties get fast in-object slots.
|
|
152
|
+
// First ~10-12 properties are stored directly on the object (fastest access).
|
|
153
|
+
// Remaining properties go to backing store (extra indirection).
|
|
154
|
+
// Therefore: ASSIGN HOTTEST PROPERTIES FIRST!
|
|
155
|
+
//
|
|
156
|
+
// Hot path analysis (from buffer performance profiling):
|
|
157
|
+
// 1. _writeIndex - incremented on EVERY write
|
|
158
|
+
// 2. _capacity - compared on EVERY write (overflow check)
|
|
159
|
+
// 3. _overflow - checked when overflow occurs
|
|
160
|
+
// 4. timestamp/entry_type - TypedArray refs accessed on EVERY write
|
|
161
|
+
// 5. _children/_parent - modified/accessed during span creation
|
|
162
|
+
// 6. _traceRoot - accessed for timestamp anchors on EVERY write
|
|
163
|
+
// 7. _identity/_logBinding - accessed during span operations
|
|
164
|
+
// 8-N. Cold properties - only accessed during Arrow conversion
|
|
165
|
+
// ==========================================================================
|
|
166
|
+
// Define extension for arrow-builder's class generator
|
|
167
|
+
const extension = {
|
|
168
|
+
constructorParams: 'stats, parent, isChained, callsiteMetadata, opMetadata, traceRoot',
|
|
169
|
+
dependencies: {
|
|
170
|
+
writeThreadIdToUint64Array,
|
|
171
|
+
textDecoder: traceIdDecoder,
|
|
172
|
+
textEncoder,
|
|
173
|
+
EMPTY_SCOPE,
|
|
174
|
+
checkCapacityTuning,
|
|
175
|
+
},
|
|
176
|
+
// ==========================================================================
|
|
177
|
+
// GENERATED CONSTRUCTOR PREAMBLE
|
|
178
|
+
// ==========================================================================
|
|
179
|
+
// The constructorPreamble below is passed to new Function() by arrow-builder's
|
|
180
|
+
// columnBufferGenerator. It MUST be pure JavaScript:
|
|
181
|
+
// - NO TypeScript type annotations (: Type)
|
|
182
|
+
// - NO non-null assertions (!)
|
|
183
|
+
// - NO comments (waste of runtime parsing)
|
|
184
|
+
//
|
|
185
|
+
// BUFFER TYPES (determined by constructor arguments):
|
|
186
|
+
// - ROOT: traceRoot provided, parent undefined
|
|
187
|
+
// → Creates identity with traceId: [threadId(8)][spanId(4)][traceIdLen(1)][traceId(N)]
|
|
188
|
+
// - CHILD: traceRoot undefined (uses parent._traceRoot), parent provided, isChained=false
|
|
189
|
+
// → Creates identity without traceId: [threadId(8)][spanId(4)]
|
|
190
|
+
// - CHAINED: traceRoot undefined (uses parent._traceRoot), parent provided, isChained=true
|
|
191
|
+
// → Shares parent._identity (no new identity allocation)
|
|
192
|
+
//
|
|
193
|
+
// MEMORY LAYOUT:
|
|
194
|
+
// - systemBuffer: timestamps (8 bytes * cap) + entry_type (1 byte * cap) + identity
|
|
195
|
+
// - System size aligned to 8 bytes so identity's BigUint64Array offset is aligned
|
|
196
|
+
// - Identity layout: [threadId(8)][spanId(4)][traceIdLen(1)?][traceId(N)?]
|
|
197
|
+
//
|
|
198
|
+
// V8 IN-OBJECT PROPERTY OPTIMIZATION:
|
|
199
|
+
// Property assignment order determines which properties get fast in-object slots.
|
|
200
|
+
// First ~10-12 properties are stored directly on the object (fastest access).
|
|
201
|
+
// Slots 1-3: HOTTEST (every log entry) - _writeIndex, _capacity, _overflow
|
|
202
|
+
// Slots 4-5: HOT (TypedArray refs) - timestamp, entry_type
|
|
203
|
+
// Slots 6-7: WARM (tree structure) - _children, _parent
|
|
204
|
+
// Slots 8-10: WARM (context) - _traceRoot, _scopeValues, _identity
|
|
205
|
+
// Slots 11: WARM (system) - _system
|
|
206
|
+
// Slots 12+: COLD (Arrow conversion only) - _callsiteMetadata, _opMetadata
|
|
207
|
+
// ==========================================================================
|
|
208
|
+
constructorPreamble:
|
|
209
|
+
// Thread-local span counter (per-process/worker, see threadId.ts docs)
|
|
210
|
+
`if (typeof globalThis.globalSpanCounter === 'undefined') {
|
|
211
|
+
globalThis.globalSpanCounter = 0;
|
|
212
|
+
}
|
|
213
|
+
const spanId = ++globalThis.globalSpanCounter;
|
|
214
|
+
` +
|
|
215
|
+
// Calculate system buffer size: timestamps (8 bytes * cap) + entry_type (1 byte * cap)
|
|
216
|
+
// Align to 8 bytes so identity's BigUint64Array offset is aligned
|
|
217
|
+
`const rawSystemSize = requestedCapacity * 9;
|
|
218
|
+
const systemSize = (rawSystemSize + 7) & ~7;
|
|
219
|
+
let systemBuffer;
|
|
220
|
+
let identityView;
|
|
221
|
+
` +
|
|
222
|
+
// CHAINED BUFFER: overflow storage for same logical span - shares parent identity
|
|
223
|
+
`if (isChained) {
|
|
224
|
+
systemBuffer = new ArrayBuffer(systemSize);
|
|
225
|
+
identityView = parent._identity;
|
|
226
|
+
}` +
|
|
227
|
+
// CHILD BUFFER: new span in existing trace - gets identity without traceId
|
|
228
|
+
// (traceId accessed via parent chain walk in trace_id getter)
|
|
229
|
+
` else if (parent) {
|
|
230
|
+
const identitySize = 12;
|
|
231
|
+
systemBuffer = new ArrayBuffer(systemSize + identitySize);
|
|
232
|
+
identityView = new Uint8Array(systemBuffer, systemSize, identitySize);
|
|
233
|
+
const threadIdArray = new BigUint64Array(systemBuffer, systemSize, 1);
|
|
234
|
+
writeThreadIdToUint64Array(threadIdArray, 0);
|
|
235
|
+
new DataView(systemBuffer, systemSize).setUint32(8, spanId, true);
|
|
236
|
+
}` +
|
|
237
|
+
// ROOT BUFFER: new trace - gets identity with traceId from TraceRoot
|
|
238
|
+
` else {
|
|
239
|
+
const traceIdUtf8 = textEncoder.encode(traceRoot.trace_id);
|
|
240
|
+
const identitySize = 13 + traceIdUtf8.length;
|
|
241
|
+
systemBuffer = new ArrayBuffer(systemSize + identitySize);
|
|
242
|
+
identityView = new Uint8Array(systemBuffer, systemSize, identitySize);
|
|
243
|
+
const view = new DataView(systemBuffer, systemSize);
|
|
244
|
+
const threadIdArray = new BigUint64Array(systemBuffer, systemSize, 1);
|
|
245
|
+
writeThreadIdToUint64Array(threadIdArray, 0);
|
|
246
|
+
view.setUint32(8, spanId, true);
|
|
247
|
+
identityView[12] = traceIdUtf8.length;
|
|
248
|
+
identityView.set(traceIdUtf8, 13);
|
|
249
|
+
}
|
|
250
|
+
` +
|
|
251
|
+
// Create TypedArray views for timestamps and entry_type
|
|
252
|
+
`const timestampView = new BigInt64Array(systemBuffer, 0, requestedCapacity);
|
|
253
|
+
const entryTypeView = new Uint8Array(systemBuffer, requestedCapacity * 8, requestedCapacity);
|
|
254
|
+
timestampView.fill(0n);
|
|
255
|
+
entryTypeView.fill(0);
|
|
256
|
+
` +
|
|
257
|
+
// Assign properties in optimal order for V8 in-object slots (see comment above)
|
|
258
|
+
`this._writeIndex = 0;
|
|
259
|
+
this._capacity = requestedCapacity;
|
|
260
|
+
this._overflow = undefined;
|
|
261
|
+
this.timestamp = timestampView;
|
|
262
|
+
this.entry_type = entryTypeView;
|
|
263
|
+
this._children = [];
|
|
264
|
+
this._parent = isChained ? parent._parent : parent;
|
|
265
|
+
this._traceRoot = traceRoot;
|
|
266
|
+
this._scopeValues = parent ? parent._scopeValues : EMPTY_SCOPE;
|
|
267
|
+
this._identity = identityView;
|
|
268
|
+
this._system = systemBuffer;
|
|
269
|
+
this._callsiteMetadata = callsiteMetadata;
|
|
270
|
+
this._opMetadata = opMetadata;
|
|
271
|
+
`,
|
|
272
|
+
// Generated methods for SpanBuffer - no comments in output
|
|
273
|
+
// span_id: extract from identity bytes [8:12]
|
|
274
|
+
// thread_id: extract from identity bytes [0:8]
|
|
275
|
+
// trace_id: walk up parent chain to root, decode trace_id from identity
|
|
276
|
+
// parent_span_id/parent_thread_id: delegate to parent
|
|
277
|
+
// isParentOf/isChildOf: pointer comparison
|
|
278
|
+
// copyThreadIdTo/copyParentThreadIdTo: copy thread_id bytes to destination
|
|
279
|
+
methods: `get span_id() {
|
|
280
|
+
return this._identity ? new DataView(this._identity.buffer, this._identity.byteOffset + 8).getUint32(0, true) : 0;
|
|
281
|
+
}
|
|
282
|
+
get thread_id() {
|
|
283
|
+
return this._identity ? new DataView(this._identity.buffer, this._identity.byteOffset).getBigUint64(0, true) : 0n;
|
|
284
|
+
}
|
|
285
|
+
get trace_id() {
|
|
286
|
+
let current = this;
|
|
287
|
+
while (current._parent) { current = current._parent; }
|
|
288
|
+
if (!current._identity) { return undefined; }
|
|
289
|
+
const len = current._identity[12];
|
|
290
|
+
const traceIdBytes = current._identity.subarray(13, 13 + len);
|
|
291
|
+
return textDecoder.decode(traceIdBytes);
|
|
292
|
+
}
|
|
293
|
+
get _spanStartTime() {
|
|
294
|
+
return this.timestamp[0];
|
|
295
|
+
}
|
|
296
|
+
get _lastLoggedTime() {
|
|
297
|
+
const chain = [];
|
|
298
|
+
let current = this;
|
|
299
|
+
while (current) {
|
|
300
|
+
chain.push(current);
|
|
301
|
+
current = current._overflow;
|
|
302
|
+
}
|
|
303
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
304
|
+
const buffer = chain[i];
|
|
305
|
+
for (let row = buffer._writeIndex - 1; row >= 0; row--) {
|
|
306
|
+
const ts = buffer.timestamp[row];
|
|
307
|
+
if (ts !== 0n) {
|
|
308
|
+
return ts;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
get _hasParent() { return this._parent !== undefined; }
|
|
315
|
+
get parent_span_id() { return this._parent?.span_id ?? 0; }
|
|
316
|
+
get parent_thread_id() { return this._parent?.thread_id ?? 0n; }
|
|
317
|
+
isParentOf(other) { return this === other._parent; }
|
|
318
|
+
isChildOf(other) { return this._parent === other; }
|
|
319
|
+
copyThreadIdTo(dest, offset) {
|
|
320
|
+
if (this._identity) {
|
|
321
|
+
const view = new DataView(this._identity.buffer, this._identity.byteOffset);
|
|
322
|
+
const threadId = view.getBigUint64(0, true);
|
|
323
|
+
new DataView(dest.buffer, dest.byteOffset + offset).setBigUint64(0, threadId, true);
|
|
324
|
+
} else {
|
|
325
|
+
new DataView(dest.buffer, dest.byteOffset + offset).setBigUint64(0, 0n, true);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
copyParentThreadIdTo(dest, offset) {
|
|
329
|
+
this._parent?.copyThreadIdTo(dest, offset) ?? new DataView(dest.buffer, dest.byteOffset + offset).setBigUint64(0, 0n, true);
|
|
330
|
+
}
|
|
331
|
+
get _logSchema() { return this.constructor.schema; }
|
|
332
|
+
get _columns() { return this.constructor.schema._columns; }
|
|
333
|
+
get _stats() { return this.constructor.stats; }
|
|
334
|
+
getOrCreateOverflow() {
|
|
335
|
+
if (this._overflow) return this._overflow;
|
|
336
|
+
const tracer = this._traceRoot.tracer;
|
|
337
|
+
tracer.onStatsWillResetFor(this);
|
|
338
|
+
checkCapacityTuning(this.constructor.stats);
|
|
339
|
+
return tracer.bufferStrategy.createOverflowBuffer(this);
|
|
340
|
+
}
|
|
341
|
+
`,
|
|
342
|
+
};
|
|
343
|
+
// Generate class with arrow-builder
|
|
344
|
+
const generatedClass = getColumnBufferClass(schema, extension);
|
|
345
|
+
if (!isGeneratedSpanBufferClass(generatedClass)) {
|
|
346
|
+
throw new TypeError('Generated column buffer is missing SpanBuffer methods');
|
|
347
|
+
}
|
|
348
|
+
// Add static properties to the generated class
|
|
349
|
+
// These are shared across all instances from the same defineOpContext
|
|
350
|
+
const SpanBufferClass = createSpanBufferConstructor(schema, generatedClass);
|
|
351
|
+
// Cache for future use
|
|
352
|
+
spanBufferClassCache.set(schema, SpanBufferClass);
|
|
353
|
+
return SpanBufferClass;
|
|
354
|
+
}
|
|
355
|
+
// ============================================================================
|
|
356
|
+
// SpanBuffer factory functions
|
|
357
|
+
// ============================================================================
|
|
358
|
+
/**
|
|
359
|
+
* Creates a root SpanBuffer for a new trace.
|
|
360
|
+
*
|
|
361
|
+
* Root buffers have identity: [threadId(8)][spanId(4)][traceIdLen(1)][traceId(N)]
|
|
362
|
+
*
|
|
363
|
+
* @param schema - Tag attribute schema defining column types (must be LogSchema)
|
|
364
|
+
* @param traceRoot - Pre-built ITraceRoot with trace_id, anchors, and tracer
|
|
365
|
+
* @param opMetadata - Op metadata for attribution (package_name, package_file, git_sha, line)
|
|
366
|
+
* @param capacity - Buffer capacity (optional, uses class.stats.capacity if omitted)
|
|
367
|
+
*
|
|
368
|
+
* @returns SpanBuffer with typed setters for schema fields
|
|
369
|
+
*/
|
|
370
|
+
const MIN_CAPACITY = 8;
|
|
371
|
+
export function createSpanBuffer(schema, traceRoot, opMetadata, capacity) {
|
|
372
|
+
const SpanBufferClass = getSpanBufferClass(schema);
|
|
373
|
+
const stats = SpanBufferClass.stats;
|
|
374
|
+
// Use provided capacity or default from class stats, enforce minimum
|
|
375
|
+
const actualCapacity = Math.max(MIN_CAPACITY, capacity ?? stats.capacity);
|
|
376
|
+
// Track non-chained buffer creation for capacity tuning
|
|
377
|
+
stats.spansCreated++;
|
|
378
|
+
// Create root buffer (no parent)
|
|
379
|
+
// Root spans use same metadata for both callsite and op (no distinction at root)
|
|
380
|
+
return new SpanBufferClass(actualCapacity, stats, undefined, // no parent
|
|
381
|
+
false, // not chained
|
|
382
|
+
opMetadata, // callsiteMetadata for row 0
|
|
383
|
+
opMetadata, // opMetadata for rows 1+ (same as callsite for root)
|
|
384
|
+
traceRoot);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Creates a continuation buffer when the current buffer overflows.
|
|
388
|
+
*
|
|
389
|
+
* Chained buffers SHARE the identity reference from the first buffer
|
|
390
|
+
* (they represent the SAME logical span, just additional storage).
|
|
391
|
+
*
|
|
392
|
+
* @param buffer - The full buffer that needs overflow handling
|
|
393
|
+
*
|
|
394
|
+
* @returns New SpanBuffer linked via `buffer._overflow`, with same schema type
|
|
395
|
+
*/
|
|
396
|
+
export function createOverflowBuffer(buffer) {
|
|
397
|
+
const SpanBufferClass = getSpanBufferConstructorForBuffer(buffer);
|
|
398
|
+
const stats = SpanBufferClass.stats;
|
|
399
|
+
// Ensure capacity is multiple of 8 for byte-aligned null bitmaps
|
|
400
|
+
const capacity = (stats.capacity + 7) & ~7;
|
|
401
|
+
// Chained buffers inherit callsiteMetadata and opMetadata from the original buffer
|
|
402
|
+
// Pass buffer as parent - used for identity sharing; _parent set to buffer._parent in constructor
|
|
403
|
+
const nextBuffer = new SpanBufferClass(capacity, stats, buffer, // Used for identity sharing, _parent set to buffer._parent in constructor
|
|
404
|
+
true, // isChained
|
|
405
|
+
buffer._callsiteMetadata, buffer._opMetadata, buffer._traceRoot);
|
|
406
|
+
// Link current buffer to next
|
|
407
|
+
buffer._overflow = nextBuffer;
|
|
408
|
+
return nextBuffer;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Creates a child span buffer with parent linkage.
|
|
412
|
+
*
|
|
413
|
+
* Child buffers have their own identity but reference their parent
|
|
414
|
+
* for trace hierarchy and scope inheritance.
|
|
415
|
+
*
|
|
416
|
+
* Note: Caller must call writeSpanStart() after this to set span name in message_values[0].
|
|
417
|
+
*
|
|
418
|
+
* @param parentBuffer - The parent span buffer
|
|
419
|
+
* @param SpanBufferClass - The SpanBuffer class to instantiate (has static schema + stats)
|
|
420
|
+
* @param callsiteMetadata - Caller's op metadata (for row 0 attribution)
|
|
421
|
+
* @param opMetadata - Op metadata for this span (for rows 1+ attribution)
|
|
422
|
+
* @param capacity - Optional capacity override (uses class.stats.capacity if omitted)
|
|
423
|
+
*
|
|
424
|
+
* @returns New SpanBuffer linked to parent
|
|
425
|
+
*/
|
|
426
|
+
export function createChildSpanBuffer(parentBuffer, SpanBufferClass, callsiteMetadata, opMetadata, capacity) {
|
|
427
|
+
const stats = SpanBufferClass.stats;
|
|
428
|
+
const actualCapacity = capacity ?? stats.capacity;
|
|
429
|
+
// Track non-chained buffer creation for capacity tuning
|
|
430
|
+
stats.spansCreated++;
|
|
431
|
+
// Create child buffer with parent reference
|
|
432
|
+
const childBuffer = new SpanBufferClass(actualCapacity, stats, parentBuffer, // parent
|
|
433
|
+
false, // not chained
|
|
434
|
+
callsiteMetadata, // callsiteMetadata - CALLER's op metadata (for row 0)
|
|
435
|
+
opMetadata, // opMetadata - EXECUTING op metadata (for rows 1+)
|
|
436
|
+
parentBuffer._traceRoot);
|
|
437
|
+
return childBuffer;
|
|
438
|
+
}
|
|
439
|
+
// ============================================================================
|
|
440
|
+
// Constants for Arrow conversion
|
|
441
|
+
// ============================================================================
|
|
442
|
+
export const THREAD_ID_BYTES = 8;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for generated SpanBuffer classes.
|
|
3
|
+
*
|
|
4
|
+
* These are injected into generated code via the `dependencies` mechanism
|
|
5
|
+
* to avoid regenerating identical code for every schema.
|
|
6
|
+
*
|
|
7
|
+
* Note: Generic null bitmap helpers (setNullBit, fillNullBitmapRange) are in
|
|
8
|
+
* @smoothbricks/arrow-builder's bufferHelpers - they're Arrow concepts, not span-specific.
|
|
9
|
+
*/
|
|
10
|
+
import { copyThreadIdTo } from './threadId.js';
|
|
11
|
+
/**
|
|
12
|
+
* Shared TextEncoder instance for traceId encoding.
|
|
13
|
+
* TextEncoder is stateless and thread-safe, so one instance suffices.
|
|
14
|
+
*/
|
|
15
|
+
export declare const textEncoder: TextEncoder;
|
|
16
|
+
/**
|
|
17
|
+
* Write spanId bytes (4 bytes, little-endian) to identity buffer.
|
|
18
|
+
*
|
|
19
|
+
* @param identity - Target Uint8Array (identity bytes)
|
|
20
|
+
* @param offset - Byte offset to write at
|
|
21
|
+
* @param spanId - 32-bit span ID
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeSpanId(identity: Uint8Array, offset: number, span_id: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Read spanId bytes (4 bytes, little-endian) from identity buffer.
|
|
26
|
+
*
|
|
27
|
+
* @param identity - Source Uint8Array (identity bytes)
|
|
28
|
+
* @param offset - Byte offset to read from
|
|
29
|
+
* @returns 32-bit span ID
|
|
30
|
+
*/
|
|
31
|
+
export declare function readSpanId(identity: Uint8Array, offset: number): number;
|
|
32
|
+
/**
|
|
33
|
+
* Decode traceId string from identity buffer (root spans only).
|
|
34
|
+
*
|
|
35
|
+
* Format: [length byte][traceId bytes...]
|
|
36
|
+
*
|
|
37
|
+
* @param identity - Source Uint8Array (identity bytes)
|
|
38
|
+
* @param offset - Byte offset where length byte starts
|
|
39
|
+
* @returns Decoded traceId string
|
|
40
|
+
*/
|
|
41
|
+
export declare function decodeTraceId(identity: Uint8Array, offset: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Helpers object to inject into generated SpanBuffer code.
|
|
44
|
+
*/
|
|
45
|
+
export declare const spanBufferHelpers: {
|
|
46
|
+
readonly textEncoder: TextEncoder;
|
|
47
|
+
readonly writeSpanId: typeof writeSpanId;
|
|
48
|
+
readonly readSpanId: typeof readSpanId;
|
|
49
|
+
readonly decodeTraceId: typeof decodeTraceId;
|
|
50
|
+
readonly copyThreadIdTo: typeof copyThreadIdTo;
|
|
51
|
+
};
|
|
52
|
+
export type SpanBufferHelpers = typeof spanBufferHelpers;
|
|
53
|
+
//# sourceMappingURL=spanBufferHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spanBufferHelpers.d.ts","sourceRoot":"","sources":["../../src/lib/spanBufferHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAKvF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAO1E;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;CAMpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for generated SpanBuffer classes.
|
|
3
|
+
*
|
|
4
|
+
* These are injected into generated code via the `dependencies` mechanism
|
|
5
|
+
* to avoid regenerating identical code for every schema.
|
|
6
|
+
*
|
|
7
|
+
* Note: Generic null bitmap helpers (setNullBit, fillNullBitmapRange) are in
|
|
8
|
+
* @smoothbricks/arrow-builder's bufferHelpers - they're Arrow concepts, not span-specific.
|
|
9
|
+
*/
|
|
10
|
+
import { copyThreadIdTo } from './threadId.js';
|
|
11
|
+
/**
|
|
12
|
+
* Shared TextEncoder instance for traceId encoding.
|
|
13
|
+
* TextEncoder is stateless and thread-safe, so one instance suffices.
|
|
14
|
+
*/
|
|
15
|
+
export const textEncoder = new TextEncoder();
|
|
16
|
+
/**
|
|
17
|
+
* Write spanId bytes (4 bytes, little-endian) to identity buffer.
|
|
18
|
+
*
|
|
19
|
+
* @param identity - Target Uint8Array (identity bytes)
|
|
20
|
+
* @param offset - Byte offset to write at
|
|
21
|
+
* @param spanId - 32-bit span ID
|
|
22
|
+
*/
|
|
23
|
+
export function writeSpanId(identity, offset, span_id) {
|
|
24
|
+
identity[offset] = span_id & 0xff;
|
|
25
|
+
identity[offset + 1] = (span_id >> 8) & 0xff;
|
|
26
|
+
identity[offset + 2] = (span_id >> 16) & 0xff;
|
|
27
|
+
identity[offset + 3] = (span_id >> 24) & 0xff;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read spanId bytes (4 bytes, little-endian) from identity buffer.
|
|
31
|
+
*
|
|
32
|
+
* @param identity - Source Uint8Array (identity bytes)
|
|
33
|
+
* @param offset - Byte offset to read from
|
|
34
|
+
* @returns 32-bit span ID
|
|
35
|
+
*/
|
|
36
|
+
export function readSpanId(identity, offset) {
|
|
37
|
+
return identity[offset] | (identity[offset + 1] << 8) | (identity[offset + 2] << 16) | (identity[offset + 3] << 24);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decode traceId string from identity buffer (root spans only).
|
|
41
|
+
*
|
|
42
|
+
* Format: [length byte][traceId bytes...]
|
|
43
|
+
*
|
|
44
|
+
* @param identity - Source Uint8Array (identity bytes)
|
|
45
|
+
* @param offset - Byte offset where length byte starts
|
|
46
|
+
* @returns Decoded traceId string
|
|
47
|
+
*/
|
|
48
|
+
export function decodeTraceId(identity, offset) {
|
|
49
|
+
const len = identity[offset];
|
|
50
|
+
let str = '';
|
|
51
|
+
for (let i = 0; i < len; i++) {
|
|
52
|
+
str += String.fromCharCode(identity[offset + 1 + i]);
|
|
53
|
+
}
|
|
54
|
+
return str;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Helpers object to inject into generated SpanBuffer code.
|
|
58
|
+
*/
|
|
59
|
+
export const spanBufferHelpers = {
|
|
60
|
+
textEncoder,
|
|
61
|
+
writeSpanId,
|
|
62
|
+
readSpanId,
|
|
63
|
+
decodeTraceId,
|
|
64
|
+
copyThreadIdTo,
|
|
65
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpanBufferStats - Self-tuning buffer statistics
|
|
3
|
+
*
|
|
4
|
+
* Mutable stats shared across all SpanBuffer instances from the same defineOpContext.
|
|
5
|
+
* Stored as a static property on the generated SpanBuffer class for optimal memory usage.
|
|
6
|
+
*
|
|
7
|
+
* Per specs/lmao/01b2_buffer_self_tuning.md:
|
|
8
|
+
* - Track row utilization = totalWrites / (spansCreated * usableRowsPerSpan)
|
|
9
|
+
* - Capacity grows when utilization > 150% (regularly overflowing)
|
|
10
|
+
* - Capacity shrinks when utilization < 50% with enough spans (wasting space)
|
|
11
|
+
* - Stats reset after each adjustment to measure new capacity effectiveness
|
|
12
|
+
*
|
|
13
|
+
* ## Key Architectural Decision
|
|
14
|
+
*
|
|
15
|
+
* Stats are NO LONGER on LogBinding. They are static properties on the generated
|
|
16
|
+
* SpanBuffer class. This reduces per-instance memory (schema stored once per class,
|
|
17
|
+
* stats shared across all instances from same defineOpContext).
|
|
18
|
+
*
|
|
19
|
+
* **Property names have NO `sb_` prefix** (clean names for new architecture).
|
|
20
|
+
* The `sb_` prefix was only needed when these were on LogBinding to avoid conflicts.
|
|
21
|
+
*
|
|
22
|
+
* @module spanBufferStats
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* SpanBufferStats interface - mutable self-tuning statistics
|
|
26
|
+
*
|
|
27
|
+
* Created once per `defineOpContext`, stored as static property on generated
|
|
28
|
+
* SpanBuffer class. All buffers from same context share these stats.
|
|
29
|
+
*/
|
|
30
|
+
export interface SpanBufferStats {
|
|
31
|
+
/** Current buffer capacity for new buffers (grows/shrinks based on utilization) */
|
|
32
|
+
capacity: number;
|
|
33
|
+
/** Total entries written across all buffers */
|
|
34
|
+
totalWrites: number;
|
|
35
|
+
/** Number of non-chained spans created (root + child spans, NOT overflow buffers) */
|
|
36
|
+
spansCreated: number;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=spanBufferStats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spanBufferStats.d.ts","sourceRoot":"","sources":["../../src/lib/spanBufferStats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IAEjB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IAEpB,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|