@smoothbricks/lmao 0.2.2 → 0.2.3
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/dist/allocator.wasm +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/JsBufferStrategy.d.ts +4 -3
- package/dist/lib/JsBufferStrategy.d.ts.map +1 -1
- package/dist/lib/JsBufferStrategy.js +18 -11
- package/dist/lib/arrow/lease.d.ts +10 -0
- package/dist/lib/arrow/lease.d.ts.map +1 -0
- package/dist/lib/arrow/lease.js +33 -0
- package/dist/lib/arrow/utils.d.ts +3 -4
- package/dist/lib/arrow/utils.d.ts.map +1 -1
- package/dist/lib/arrow/utils.js +12 -13
- package/dist/lib/arrow/vocabularyDictionary.d.ts +21 -0
- package/dist/lib/arrow/vocabularyDictionary.d.ts.map +1 -0
- package/dist/lib/arrow/vocabularyDictionary.js +95 -0
- package/dist/lib/bufferStrategy.d.ts +3 -2
- package/dist/lib/bufferStrategy.d.ts.map +1 -1
- package/dist/lib/cloudflare/traceRows.d.ts.map +1 -1
- package/dist/lib/cloudflare/traceRows.js +3 -2
- package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/evaluatorGenerator.js +12 -11
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +44 -82
- package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/fixedPositionWriterGenerator.js +223 -162
- package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts +63 -0
- package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts.map +1 -0
- package/dist/lib/codegen/spanLoggerClosureMaterializer.js +447 -0
- package/dist/lib/codegen/spanLoggerGenerator.d.ts +36 -19
- package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -1
- package/dist/lib/codegen/spanLoggerGenerator.js +164 -158
- package/dist/lib/convertToArrow.d.ts +7 -2
- package/dist/lib/convertToArrow.d.ts.map +1 -1
- package/dist/lib/convertToArrow.js +499 -285
- package/dist/lib/defineOpContext.js +1 -1
- package/dist/lib/enumMetadata.d.ts +19 -0
- package/dist/lib/enumMetadata.d.ts.map +1 -0
- package/dist/lib/enumMetadata.js +86 -0
- package/dist/lib/flushScheduler.d.ts.map +1 -1
- package/dist/lib/flushScheduler.js +13 -4
- package/dist/lib/library.d.ts +16 -98
- package/dist/lib/library.d.ts.map +1 -1
- package/dist/lib/library.js +32 -525
- package/dist/lib/logBinding.d.ts +21 -27
- package/dist/lib/logBinding.d.ts.map +1 -1
- package/dist/lib/op.d.ts +30 -30
- package/dist/lib/op.d.ts.map +1 -1
- package/dist/lib/op.js +15 -22
- package/dist/lib/opContext/createOpGroup.d.ts +1 -1
- package/dist/lib/opContext/createOpGroup.d.ts.map +1 -1
- package/dist/lib/opContext/createOpGroup.js +22 -29
- package/dist/lib/opContext/defineOp.d.ts +4 -4
- package/dist/lib/opContext/defineOp.d.ts.map +1 -1
- package/dist/lib/opContext/defineOp.js +53 -10
- package/dist/lib/opContext/opGroupTypes.d.ts +2 -2
- package/dist/lib/opContext/opTypes.d.ts +1 -1
- package/dist/lib/opContext/opTypes.d.ts.map +1 -1
- package/dist/lib/opContext/spanContextTypes.d.ts +29 -14
- package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -1
- package/dist/lib/opContext/types.d.ts +4 -4
- package/dist/lib/opContext/types.d.ts.map +1 -1
- package/dist/lib/physicalLayoutPlan.d.ts +89 -0
- package/dist/lib/physicalLayoutPlan.d.ts.map +1 -0
- package/dist/lib/physicalLayoutPlan.js +442 -0
- package/dist/lib/resolveMessage.d.ts +9 -0
- package/dist/lib/resolveMessage.d.ts.map +1 -0
- package/dist/lib/resolveMessage.js +63 -0
- package/dist/lib/result.d.ts +5 -7
- package/dist/lib/result.d.ts.map +1 -1
- package/dist/lib/result.js +19 -26
- package/dist/lib/runtimeHint.d.ts +35 -0
- package/dist/lib/runtimeHint.d.ts.map +1 -0
- package/dist/lib/runtimeHint.js +79 -0
- package/dist/lib/schema/types.d.ts +1 -1
- package/dist/lib/schema/types.d.ts.map +1 -1
- package/dist/lib/span-buffer/aot/v1.d.ts +2 -0
- package/dist/lib/span-buffer/aot/v1.d.ts.map +1 -0
- package/dist/lib/span-buffer/aot/v1.js +24 -0
- package/dist/lib/spanBuffer.d.ts +33 -4
- package/dist/lib/spanBuffer.d.ts.map +1 -1
- package/dist/lib/spanBuffer.js +583 -91
- package/dist/lib/spanBufferStats.d.ts +1 -1
- package/dist/lib/spanBufferStats.d.ts.map +1 -1
- package/dist/lib/spanContext.d.ts +27 -51
- package/dist/lib/spanContext.d.ts.map +1 -1
- package/dist/lib/spanContext.js +822 -344
- package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -1
- package/dist/lib/sqlite/sqlite-common.js +20 -21
- package/dist/lib/testing/bun-harness.d.ts +8 -3
- package/dist/lib/testing/bun-harness.d.ts.map +1 -1
- package/dist/lib/testing/bun-harness.js +30 -18
- package/dist/lib/testing/extractFacts.d.ts +1 -1
- package/dist/lib/testing/extractFacts.d.ts.map +1 -1
- package/dist/lib/testing/extractFacts.js +55 -63
- package/dist/lib/testing/facts.d.ts +1 -1
- package/dist/lib/testing/facts.d.ts.map +1 -1
- package/dist/lib/testing/queryable-span.d.ts +1 -1
- package/dist/lib/testing/queryable-span.d.ts.map +1 -1
- package/dist/lib/testing/queryable-span.js +26 -28
- package/dist/lib/testing/span-query.d.ts.map +1 -1
- package/dist/lib/testing/span-query.js +19 -22
- package/dist/lib/testing/stdio-replay.d.ts.map +1 -1
- package/dist/lib/testing/stdio-replay.js +19 -8
- package/dist/lib/threadId.d.ts.map +1 -1
- package/dist/lib/threadId.js +6 -3
- package/dist/lib/traceRoot.d.ts +30 -8
- package/dist/lib/traceRoot.d.ts.map +1 -1
- package/dist/lib/traceRoot.es.d.ts +17 -15
- package/dist/lib/traceRoot.es.d.ts.map +1 -1
- package/dist/lib/traceRoot.es.js +68 -34
- package/dist/lib/traceRoot.js +11 -0
- package/dist/lib/traceRoot.node.d.ts +17 -19
- package/dist/lib/traceRoot.node.d.ts.map +1 -1
- package/dist/lib/traceRoot.node.js +66 -38
- package/dist/lib/traceTopology.d.ts +42 -0
- package/dist/lib/traceTopology.d.ts.map +1 -0
- package/dist/lib/traceTopology.js +260 -0
- package/dist/lib/tracer.d.ts +9 -5
- package/dist/lib/tracer.d.ts.map +1 -1
- package/dist/lib/tracer.js +65 -71
- package/dist/lib/tracers/ArrayQueueTracer.d.ts +1 -1
- package/dist/lib/tracers/ArrayQueueTracer.js +1 -1
- package/dist/lib/tracers/StdioTracer.d.ts.map +1 -1
- package/dist/lib/tracers/StdioTracer.js +15 -13
- package/dist/lib/tracers/TestTracer.d.ts +4 -6
- package/dist/lib/tracers/TestTracer.d.ts.map +1 -1
- package/dist/lib/tracers/TestTracer.js +6 -8
- package/dist/lib/types.d.ts +49 -32
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/vocabularyRegistry.d.ts +25 -0
- package/dist/lib/vocabularyRegistry.d.ts.map +1 -0
- package/dist/lib/vocabularyRegistry.js +372 -0
- package/dist/lib/wasm/WasmBufferStrategy.d.ts +6 -10
- package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -1
- package/dist/lib/wasm/WasmBufferStrategy.js +44 -37
- package/dist/lib/wasm/wasmAllocator.d.ts +27 -22
- package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -1
- package/dist/lib/wasm/wasmAllocator.js +66 -44
- package/dist/lib/wasm/wasmPhysicalLayout.d.ts +67 -0
- package/dist/lib/wasm/wasmPhysicalLayout.d.ts.map +1 -0
- package/dist/lib/wasm/wasmPhysicalLayout.js +179 -0
- package/dist/lib/wasm/wasmSpanBuffer.d.ts +79 -31
- package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -1
- package/dist/lib/wasm/wasmSpanBuffer.js +442 -272
- package/dist/lib/wasm/wasmTraceRoot.d.ts +24 -22
- package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -1
- package/dist/lib/wasm/wasmTraceRoot.js +110 -71
- package/dist/vocabulary/register/v1.d.ts +2 -0
- package/dist/vocabulary/register/v1.d.ts.map +1 -0
- package/dist/vocabulary/register/v1.js +1 -0
- package/dist/wasm.d.ts +5 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +4 -0
- package/package.json +54 -6
- package/src/index.ts +1 -0
- package/src/lib/JsBufferStrategy.ts +27 -9
- package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +335 -37
- package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +97 -26
- package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +75 -15
- package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +30 -6
- package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +18 -21
- package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +5 -2
- package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +25 -7
- package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +3 -2
- package/src/lib/__tests__/buffer-overflow.test.ts +24 -18
- package/src/lib/__tests__/capability-span-context.test.ts +505 -0
- package/src/lib/__tests__/capacity-tuning.test.ts +5 -3
- package/src/lib/__tests__/eager-columns.test.ts +345 -0
- package/src/lib/__tests__/enum-metadata-aot.test.ts +153 -0
- package/src/lib/__tests__/enum-metadata.test.ts +177 -0
- package/src/lib/__tests__/fixtures/empty-vocabulary-runtime.fixture.ts +15 -0
- package/src/lib/__tests__/flushScheduler.test.ts +5 -1
- package/src/lib/__tests__/identity-view.property.test.ts +179 -0
- package/src/lib/__tests__/library.test.ts +19 -235
- package/src/lib/__tests__/message-buffer-families.test.ts +878 -0
- package/src/lib/__tests__/nested-library-tasks.test.ts +14 -15
- package/src/lib/__tests__/op-metadata.test.ts +1 -1
- package/src/lib/__tests__/op-type-safety.test.ts +5 -16
- package/src/lib/__tests__/physical-layout-plan.test.ts +333 -0
- package/src/lib/__tests__/remap-descriptor-integration.test.ts +381 -0
- package/src/lib/__tests__/root-context-construction.test.ts +414 -0
- package/src/lib/__tests__/span-auto-runtime.test.ts +386 -0
- package/src/lib/__tests__/span-buffer-segment-stats.test.ts +221 -0
- package/src/lib/__tests__/span-lifecycle.test.ts +53 -25
- package/src/lib/__tests__/spanbuffer-materializer-parity.test.ts +266 -0
- package/src/lib/__tests__/sync-async-trace.test.ts +24 -23
- package/src/lib/__tests__/tag-writer-aot.test.ts +214 -0
- package/src/lib/__tests__/test-helpers.ts +67 -12
- package/src/lib/__tests__/threadId.test.ts +62 -0
- package/src/lib/__tests__/timestamp.test.ts +221 -93
- package/src/lib/__tests__/traceTopology.property.test.ts +383 -0
- package/src/lib/__tests__/type-narrowing.test.ts +63 -0
- package/src/lib/__tests__/vocabulary-dense-decoding.test.ts +405 -0
- package/src/lib/__tests__/vocabularyRegistry.test.ts +313 -0
- package/src/lib/arrow/lease.ts +43 -0
- package/src/lib/arrow/utils.ts +10 -14
- package/src/lib/arrow/vocabularyDictionary.ts +123 -0
- package/src/lib/bufferStrategy.ts +9 -1
- package/src/lib/cloudflare/traceRows.ts +3 -2
- package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +21 -141
- package/src/lib/codegen/__tests__/fixedPositionWriter-parity.test.ts +273 -0
- package/src/lib/codegen/__tests__/fixedPositionWriter-uint64.test.ts +61 -34
- package/src/lib/codegen/__tests__/nullBitmap.test.ts +33 -37
- package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +34 -18
- package/src/lib/codegen/__tests__/spanLoggerMaterializerParity.test.ts +503 -0
- package/src/lib/codegen/evaluatorGenerator.ts +18 -13
- package/src/lib/codegen/fixedPositionWriterGenerator.ts +329 -245
- package/src/lib/codegen/spanLoggerClosureMaterializer.ts +598 -0
- package/src/lib/codegen/spanLoggerGenerator.ts +241 -177
- package/src/lib/convertToArrow.ts +598 -311
- package/src/lib/defineOpContext.ts +1 -1
- package/src/lib/enumMetadata.ts +121 -0
- package/src/lib/flushScheduler.ts +11 -5
- package/src/lib/library.ts +37 -595
- package/src/lib/logBinding.ts +21 -27
- package/src/lib/op.ts +75 -18
- package/src/lib/opContext/__tests__/retry.test.ts +27 -21
- package/src/lib/opContext/createOpGroup.ts +33 -31
- package/src/lib/opContext/defineOp.ts +88 -11
- package/src/lib/opContext/opGroupTypes.ts +2 -2
- package/src/lib/opContext/opTypes.ts +1 -1
- package/src/lib/opContext/spanContextTypes.ts +98 -17
- package/src/lib/opContext/types.ts +7 -3
- package/src/lib/physicalLayoutPlan.ts +598 -0
- package/src/lib/resolveMessage.ts +67 -0
- package/src/lib/result.ts +20 -33
- package/src/lib/runtimeHint.ts +98 -0
- package/src/lib/schema/__tests__/featureFlags.test.ts +2 -1
- package/src/lib/schema/builder.ts +1 -1
- package/src/lib/schema/types.ts +1 -1
- package/src/lib/span-buffer/aot/v1.ts +26 -0
- package/src/lib/spanBuffer.ts +658 -92
- package/src/lib/spanBufferStats.ts +1 -1
- package/src/lib/spanContext.ts +1350 -861
- package/src/lib/sqlite/sqlite-common.ts +20 -31
- package/src/lib/testing/__tests__/topology-traversal.test.ts +174 -0
- package/src/lib/testing/__tests__/vitest-harness.test.ts +2 -1
- package/src/lib/testing/bun-harness.ts +94 -43
- package/src/lib/testing/extractFacts.ts +64 -78
- package/src/lib/testing/facts.ts +1 -1
- package/src/lib/testing/queryable-span.ts +23 -30
- package/src/lib/testing/span-query.ts +16 -20
- package/src/lib/testing/stdio-replay.ts +25 -8
- package/src/lib/testing/vitest-harness.ts +1 -1
- package/src/lib/threadId.ts +6 -3
- package/src/lib/traceRoot.es.ts +77 -42
- package/src/lib/traceRoot.node.ts +75 -46
- package/src/lib/traceRoot.ts +41 -14
- package/src/lib/traceTopology.ts +279 -0
- package/src/lib/tracer.ts +109 -98
- package/src/lib/tracers/ArrayQueueTracer.ts +1 -1
- package/src/lib/tracers/StdioTracer.ts +15 -13
- package/src/lib/tracers/TestTracer.ts +6 -8
- package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +15 -10
- package/src/lib/tracers/__tests__/TestTracer.test.ts +23 -13
- package/src/lib/types.ts +64 -33
- package/src/lib/vocabularyRegistry.ts +439 -0
- package/src/lib/wasm/WasmBufferStrategy.ts +56 -48
- package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +215 -11
- package/src/lib/wasm/__tests__/allocatorFreeBlockClamp.test.ts +86 -0
- package/src/lib/wasm/__tests__/wasm-identity-view.test.ts +311 -0
- package/src/lib/wasm/__tests__/wasm-integration.test.ts +417 -44
- package/src/lib/wasm/__tests__/wasm-message-buffer-families.test.ts +588 -0
- package/src/lib/wasm/__tests__/wasmAllocator.test.ts +100 -668
- package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +419 -63
- package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +24 -29
- package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +2 -2
- package/src/lib/wasm/wasmAllocator.ts +131 -96
- package/src/lib/wasm/wasmPhysicalLayout.ts +309 -0
- package/src/lib/wasm/wasmSpanBuffer.ts +597 -341
- package/src/lib/wasm/wasmTraceRoot.ts +140 -78
- package/src/vocabulary/register/v1.ts +1 -0
- package/src/wasm.ts +19 -0
- package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +0 -319
- package/src/lib/__tests__/remapped-buffer-view.test.ts +0 -635
- package/src/lib/wasm/allocator.zig +0 -948
package/src/lib/library.ts
CHANGED
|
@@ -4,82 +4,34 @@
|
|
|
4
4
|
* WHY: Libraries need to write clean, domain-focused code (ctx.tag.status(200))
|
|
5
5
|
* while avoiding naming conflicts when composed with other libraries.
|
|
6
6
|
*
|
|
7
|
-
* HOW: At composition time (cold path), we
|
|
8
|
-
*
|
|
7
|
+
* HOW: At composition time (cold path), we create immutable Arrow remap descriptors.
|
|
8
|
+
* Child buffers retain canonical schema/layout.
|
|
9
9
|
*
|
|
10
10
|
* Per specs/lmao/01e_library_integration_pattern.md:
|
|
11
11
|
* - Libraries define clean schemas without prefixes (status, method, url)
|
|
12
12
|
* - Prefixing happens at composition time (http_status, http_method, http_url)
|
|
13
|
-
* - Zero hot path overhead -
|
|
13
|
+
* - Zero hot path overhead - remapping is composed at module creation
|
|
14
14
|
*
|
|
15
|
-
* WHAT: This module provides
|
|
16
|
-
*
|
|
17
|
-
* - createPrefixMapping() - Build clean→prefixed name mapping
|
|
18
|
-
* - generateRemappedBufferViewClass() - Generate view for Arrow conversion
|
|
19
|
-
* - generateRemappedSpanLoggerClass() - Generate class with clean methods, prefixed writes
|
|
20
|
-
* - createRemappedSpanLoggerClass() - Compile and cache SpanLogger classes
|
|
15
|
+
* WHAT: This module provides schema/prefix mapping utilities and immutable remap
|
|
16
|
+
* descriptors for cold Arrow conversion.
|
|
21
17
|
*/
|
|
22
18
|
|
|
23
19
|
import { isRecord } from '@smoothbricks/validation';
|
|
24
|
-
import type {
|
|
25
|
-
import {
|
|
26
|
-
ENTRY_TYPE_DEBUG,
|
|
27
|
-
ENTRY_TYPE_ERROR,
|
|
28
|
-
ENTRY_TYPE_INFO,
|
|
29
|
-
ENTRY_TYPE_TRACE,
|
|
30
|
-
ENTRY_TYPE_WARN,
|
|
31
|
-
} from './schema/systemSchema.js';
|
|
32
|
-
import { getEnumValues, getSchemaType } from './schema/typeGuards.js';
|
|
20
|
+
import type { RemapDescriptor, RemappedColumn } from './logBinding.js';
|
|
33
21
|
import { LogSchema, type SchemaFields } from './schema/types.js';
|
|
34
|
-
import type { AnySpanBuffer } from './types.js';
|
|
35
|
-
|
|
36
|
-
type RemappedBufferViewConstructor = new (buffer: AnySpanBuffer) => AnySpanBuffer;
|
|
37
|
-
type RemappedSpanLoggerConstructor<T extends LogSchema = LogSchema> = new (
|
|
38
|
-
buffer: AnySpanBuffer,
|
|
39
|
-
createOverflowBuffer: (buffer: AnySpanBuffer) => AnySpanBuffer,
|
|
40
|
-
initialScopedAttributes?: Record<string, unknown>,
|
|
41
|
-
) => SpanLoggerImpl<T>;
|
|
42
22
|
|
|
43
23
|
function isSchemaField(value: unknown): value is SchemaFields[string] {
|
|
44
24
|
return isRecord(value);
|
|
45
25
|
}
|
|
46
26
|
|
|
47
|
-
function isRemappedBufferViewClass(value: unknown): value is RemappedBufferViewConstructor {
|
|
48
|
-
if (typeof value !== 'function') {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
const prototype = Reflect.get(value, 'prototype');
|
|
52
|
-
return (
|
|
53
|
-
typeof prototype === 'object' &&
|
|
54
|
-
prototype !== null &&
|
|
55
|
-
typeof Reflect.get(prototype, 'getColumnIfAllocated') === 'function' &&
|
|
56
|
-
typeof Reflect.get(prototype, 'getNullsIfAllocated') === 'function'
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function isRemappedSpanLoggerClass<T extends LogSchema>(value: unknown): value is RemappedSpanLoggerConstructor<T> {
|
|
61
|
-
if (typeof value !== 'function') {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const prototype = Reflect.get(value, 'prototype');
|
|
65
|
-
return (
|
|
66
|
-
typeof prototype === 'object' &&
|
|
67
|
-
prototype !== null &&
|
|
68
|
-
typeof Reflect.get(prototype, 'with') === 'function' &&
|
|
69
|
-
typeof Reflect.get(prototype, 'info') === 'function' &&
|
|
70
|
-
typeof Reflect.get(prototype, 'error') === 'function'
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//#region smoo/lmao!n/codegen-prefixed-remap
|
|
75
27
|
/**
|
|
76
28
|
* Prefix a tag attribute schema
|
|
77
29
|
* Renames all fields with a prefix to avoid conflicts
|
|
78
30
|
*
|
|
79
31
|
* 01j "Library Compilation (Prefixed)": a library defines clean field names
|
|
80
|
-
* (status, method); the consumer applies a prefix (http) at wire time.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
32
|
+
* (status, method); the consumer applies a prefix (http) at wire time. The utilities
|
|
33
|
+
* below create the prefixed schema, clean-to-prefixed mapping, and immutable Arrow
|
|
34
|
+
* remap descriptor.
|
|
83
35
|
*
|
|
84
36
|
* Example:
|
|
85
37
|
* - Input: { status: S.number(), method: S.enum(['GET', 'POST']) }
|
|
@@ -120,8 +72,8 @@ export interface PrefixMapping {
|
|
|
120
72
|
/**
|
|
121
73
|
* Create a mapping from clean field names to prefixed column names
|
|
122
74
|
*
|
|
123
|
-
* WHY: This mapping
|
|
124
|
-
*
|
|
75
|
+
* WHY: This mapping exposes the relationship between clean library field names and
|
|
76
|
+
* their prefixed column names.
|
|
125
77
|
*
|
|
126
78
|
* @param schema - Clean schema (LogSchema instance)
|
|
127
79
|
* @param prefix - Prefix to apply (e.g., 'http')
|
|
@@ -143,547 +95,37 @@ export function createPrefixMapping<T extends LogSchema>(schema: T, prefix: stri
|
|
|
143
95
|
return mapping;
|
|
144
96
|
}
|
|
145
97
|
|
|
146
|
-
// ============================================================================
|
|
147
|
-
// RemappedBufferView - Maps prefixed column names to unprefixed for tree traversal
|
|
148
|
-
// ============================================================================
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Cache for generated RemappedBufferView classes.
|
|
152
|
-
* Key is a stable string representation of the mapping.
|
|
153
|
-
* This avoids regenerating classes for the same mapping.
|
|
154
|
-
*/
|
|
155
|
-
const remappedBufferViewClassCache = new Map<string, RemappedBufferViewConstructor>();
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Cache for generated RemappedSpanLogger classes.
|
|
159
|
-
* Key is a stable string representation of schema fields + prefix mapping.
|
|
160
|
-
*/
|
|
161
|
-
const remappedSpanLoggerClassCache = new Map<string, RemappedSpanLoggerConstructor>();
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Create a stable cache key from a prefix mapping.
|
|
165
|
-
* Sorts keys to ensure consistent ordering.
|
|
166
|
-
*/
|
|
167
|
-
function createMappingCacheKey(mapping: Record<string, string>): string {
|
|
168
|
-
const sortedEntries = Object.entries(mapping).sort(([a], [b]) => a.localeCompare(b));
|
|
169
|
-
return JSON.stringify(sortedEntries);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Create a stable cache key from schema and prefix mapping.
|
|
174
|
-
* Combines schema fields with sorted prefix mapping for consistent keys.
|
|
175
|
-
*/
|
|
176
|
-
function createSchemaAndMappingCacheKey(schema: LogSchema, mapping: Record<string, string>): string {
|
|
177
|
-
const schemaKey = JSON.stringify(schema.fields);
|
|
178
|
-
const mappingKey = createMappingCacheKey(mapping);
|
|
179
|
-
return `${schemaKey}:${mappingKey}`;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Generate a RemappedBufferView class for library prefix support.
|
|
184
|
-
*
|
|
185
|
-
* WHY: Libraries write to unprefixed columns (status, method) but Arrow conversion
|
|
186
|
-
* iterates using prefixed names from the root schema (http_status, http_method).
|
|
187
|
-
* RemappedBufferView bridges this gap for tree traversal during cold-path Arrow conversion.
|
|
188
|
-
*
|
|
189
|
-
* HOW: Uses new Function() to generate a class at library composition time (cold path).
|
|
190
|
-
* The generated class wraps a SpanBuffer and remaps getColumnIfAllocated/getNullsIfAllocated
|
|
191
|
-
* calls from prefixed names to unprefixed names.
|
|
192
|
-
*
|
|
193
|
-
* WHAT: Returns a class constructor that:
|
|
194
|
-
* - Passes through tree traversal properties (children, next)
|
|
195
|
-
* - Passes through system columns (timestamps, operations, message, etc.)
|
|
196
|
-
* - Passes through identity properties (traceId, spanId, etc.)
|
|
197
|
-
* - Remaps getColumnIfAllocated() and getNullsIfAllocated() from prefixed→unprefixed
|
|
198
|
-
*
|
|
199
|
-
* Per specs/lmao/01e_library_integration_pattern.md:
|
|
200
|
-
* - Hot path: Library writes directly to unprefixed columns (zero overhead)
|
|
201
|
-
* - Cold path: Arrow conversion uses RemappedBufferView to access via prefixed names
|
|
202
|
-
*
|
|
203
|
-
* @param prefixToUnprefixedMapping - Maps prefixed names to unprefixed names
|
|
204
|
-
* e.g., { 'http_status': 'status', 'http_method': 'method' }
|
|
205
|
-
* NOTE: The mapping is prefixed→unprefixed (reverse of createPrefixMapping output)
|
|
206
|
-
*
|
|
207
|
-
* @returns Constructor for RemappedBufferView class
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```typescript
|
|
211
|
-
* // Create mapping (prefixed → unprefixed)
|
|
212
|
-
* const mapping = { 'http_status': 'status', 'http_method': 'method' };
|
|
213
|
-
* const ViewClass = generateRemappedBufferViewClass(mapping);
|
|
214
|
-
*
|
|
215
|
-
* // Wrap library buffer
|
|
216
|
-
* const view = new ViewClass(libraryBuffer);
|
|
217
|
-
*
|
|
218
|
-
* // Access via prefixed name returns unprefixed column
|
|
219
|
-
* view.getColumnIfAllocated('http_status'); // Returns buffer.getColumnIfAllocated('status')
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
export function generateRemappedBufferViewClass(
|
|
223
|
-
prefixToUnprefixedMapping: Record<string, string>,
|
|
224
|
-
): RemappedBufferViewConstructor {
|
|
225
|
-
// Check cache first
|
|
226
|
-
const cacheKey = createMappingCacheKey(prefixToUnprefixedMapping);
|
|
227
|
-
const cached = remappedBufferViewClassCache.get(cacheKey);
|
|
228
|
-
if (cached) {
|
|
229
|
-
return cached;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const mappingCode = JSON.stringify(prefixToUnprefixedMapping);
|
|
233
|
-
|
|
234
|
-
// Generate the class code
|
|
235
|
-
// Uses IIFE wrapper for clean scope, similar to generateRemappedSpanLoggerClass
|
|
236
|
-
const code = `(function() {
|
|
237
|
-
'use strict';
|
|
238
|
-
const mapping = ${mappingCode};
|
|
239
|
-
|
|
240
|
-
class RemappedBufferView {
|
|
241
|
-
constructor(buffer) {
|
|
242
|
-
this._buffer = buffer;
|
|
243
|
-
// Build _columns with prefixed names from mapping
|
|
244
|
-
// mapping is { prefixedName: unprefixedName }
|
|
245
|
-
// _logSchema may be undefined in tests using mock buffers
|
|
246
|
-
const baseFields = buffer._logSchema?.fields ?? {};
|
|
247
|
-
this._columns = [];
|
|
248
|
-
for (const prefixedName in mapping) {
|
|
249
|
-
const unprefixedName = mapping[prefixedName];
|
|
250
|
-
const schema = baseFields[unprefixedName];
|
|
251
|
-
if (schema) this._columns.push([prefixedName, schema]);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Tree traversal (pass-through)
|
|
256
|
-
get _children() { return this._buffer._children; }
|
|
257
|
-
get _parent() { return this._buffer._parent; }
|
|
258
|
-
get _overflow() { return this._buffer._overflow; }
|
|
259
|
-
|
|
260
|
-
// Row count
|
|
261
|
-
get _writeIndex() { return this._buffer._writeIndex; }
|
|
262
|
-
|
|
263
|
-
// System columns (NOT remapped - same in all buffers)
|
|
264
|
-
get timestamp() { return this._buffer.timestamp; }
|
|
265
|
-
get entry_type() { return this._buffer.entry_type; }
|
|
266
|
-
get message_values() { return this._buffer.message_values; }
|
|
267
|
-
get message_nulls() { return this._buffer.message_nulls; }
|
|
268
|
-
get line_values() { return this._buffer.line_values; }
|
|
269
|
-
get line_nulls() { return this._buffer.line_nulls; }
|
|
270
|
-
get error_code_values() { return this._buffer.error_code_values; }
|
|
271
|
-
get error_code_nulls() { return this._buffer.error_code_nulls; }
|
|
272
|
-
get exception_stack_values() { return this._buffer.exception_stack_values; }
|
|
273
|
-
get exception_stack_nulls() { return this._buffer.exception_stack_nulls; }
|
|
274
|
-
get ff_value_values() { return this._buffer.ff_value_values; }
|
|
275
|
-
get ff_value_nulls() { return this._buffer.ff_value_nulls; }
|
|
276
|
-
|
|
277
|
-
// Identity (pass-through)
|
|
278
|
-
get trace_id() { return this._buffer.trace_id; }
|
|
279
|
-
get thread_id() { return this._buffer.thread_id; }
|
|
280
|
-
get span_id() { return this._buffer.span_id; }
|
|
281
|
-
get parent_span_id() { return this._buffer.parent_span_id; }
|
|
282
|
-
get parent_thread_id() { return this._buffer.parent_thread_id; }
|
|
283
|
-
get _identity() { return this._buffer._identity; }
|
|
284
|
-
|
|
285
|
-
// Metadata (pass-through)
|
|
286
|
-
get module() { return this._buffer._module; }
|
|
287
|
-
get _opMetadata() { return this._buffer._opMetadata; }
|
|
288
|
-
get _callsiteMetadata() { return this._buffer._callsiteMetadata; }
|
|
289
|
-
// Remapped column access (for Arrow conversion iteration)
|
|
290
|
-
// Maps prefixed name → unprefixed name before calling underlying buffer
|
|
291
|
-
getColumnIfAllocated(name) {
|
|
292
|
-
const unprefixedName = mapping[name] ?? name;
|
|
293
|
-
return this._buffer.getColumnIfAllocated(unprefixedName);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
getNullsIfAllocated(name) {
|
|
297
|
-
const unprefixedName = mapping[name] ?? name;
|
|
298
|
-
return this._buffer.getNullsIfAllocated(unprefixedName);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return RemappedBufferView;
|
|
303
|
-
})()`;
|
|
304
|
-
|
|
305
|
-
const GeneratedClass = new Function(`return ${code}`)();
|
|
306
|
-
if (!isRemappedBufferViewClass(GeneratedClass)) {
|
|
307
|
-
throw new TypeError('Generated remapped buffer view is missing column remapping methods');
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Cache for future use
|
|
311
|
-
remappedBufferViewClassCache.set(cacheKey, GeneratedClass);
|
|
312
|
-
|
|
313
|
-
return GeneratedClass;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Generate enum value mapping code for remapped class
|
|
318
|
-
* Creates a switch-case statement for compile-time enum mapping
|
|
319
|
-
*
|
|
320
|
-
* WHY: Enums need compile-time mapping to Uint8 values for 1-byte storage
|
|
321
|
-
*/
|
|
322
|
-
function generateEnumMapping(fieldName: string, enumValues: readonly string[]): string {
|
|
323
|
-
const cases = enumValues.map((value, index) => ` case ${JSON.stringify(value)}: return ${index};`).join('\n');
|
|
324
|
-
|
|
325
|
-
return `
|
|
326
|
-
function getEnumIndex_${fieldName}(value) {
|
|
327
|
-
switch(value) {
|
|
328
|
-
${cases}
|
|
329
|
-
default: return 0;
|
|
330
|
-
}
|
|
331
|
-
}`;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Generate attribute writer method for remapped SpanLogger
|
|
336
|
-
*
|
|
337
|
-
* WHY: Each method must write to the PREFIXED column while being called by CLEAN name
|
|
338
|
-
* HOW: Method name is cleanName, but buffer access uses prefixedColumnName
|
|
339
|
-
*
|
|
340
|
-
* @param cleanName - Clean method name (e.g., 'status')
|
|
341
|
-
* @param prefixedColumnName - Prefixed column name (e.g., 'http_status')
|
|
342
|
-
* @param schema - Field schema for type-specific handling
|
|
343
|
-
* @param hasEnumMapping - Whether enum mapping function exists
|
|
344
|
-
*/
|
|
345
|
-
function generateRemappedAttributeWriter(
|
|
346
|
-
cleanName: string,
|
|
347
|
-
prefixedColumnName: string,
|
|
348
|
-
schema: unknown,
|
|
349
|
-
hasEnumMapping: boolean,
|
|
350
|
-
): string {
|
|
351
|
-
const columnName = prefixedColumnName;
|
|
352
|
-
const lmaoType = getSchemaType(schema);
|
|
353
|
-
|
|
354
|
-
// For enums, use pre-generated mapping function (uses cleanName for function)
|
|
355
|
-
// Generated code: ALWAYS writes to row 0 (span-start) with overwrite semantics
|
|
356
|
-
// Maps clean method name to prefixed column, marks value as non-null (bit 0)
|
|
357
|
-
if (lmaoType === 'enum' && hasEnumMapping) {
|
|
358
|
-
return `
|
|
359
|
-
${cleanName}(value) {
|
|
360
|
-
const idx = 0;
|
|
361
|
-
const enumIndex = getEnumIndex_${cleanName}(value);
|
|
362
|
-
this._buffer.${columnName}_values[idx] = enumIndex;
|
|
363
|
-
this._buffer.${columnName}_nulls[0] |= 1;
|
|
364
|
-
return this;
|
|
365
|
-
}`;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// For categories, store strings directly
|
|
369
|
-
// Generated code: writes to row 0, stores string directly, marks non-null
|
|
370
|
-
if (lmaoType === 'category') {
|
|
371
|
-
return `
|
|
372
|
-
${cleanName}(value) {
|
|
373
|
-
const idx = 0;
|
|
374
|
-
if (value === null || value === undefined) {
|
|
375
|
-
this._buffer.${columnName}_nulls[0] &= ~1;
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
this._buffer.${columnName}_values[idx] = value;
|
|
379
|
-
this._buffer.${columnName}_nulls[0] |= 1;
|
|
380
|
-
return this;
|
|
381
|
-
}`;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// For text, store strings directly
|
|
385
|
-
// Generated code: writes to row 0, handles null/undefined by clearing bit and returning early,
|
|
386
|
-
// stores string directly, marks non-null
|
|
387
|
-
if (lmaoType === 'text') {
|
|
388
|
-
return `
|
|
389
|
-
${cleanName}(value) {
|
|
390
|
-
const idx = 0;
|
|
391
|
-
if (value === null || value === undefined) {
|
|
392
|
-
this._buffer.${columnName}_nulls[0] &= ~1;
|
|
393
|
-
return this;
|
|
394
|
-
}
|
|
395
|
-
this._buffer.${columnName}_values[idx] = value;
|
|
396
|
-
this._buffer.${columnName}_nulls[0] |= 1;
|
|
397
|
-
return this;
|
|
398
|
-
}`;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// Boolean: bit-packed storage (8 values per byte)
|
|
402
|
-
// Generated code: writes to row 0, bit 0 of byte 0 is index 0,
|
|
403
|
-
// sets or clears value bit, marks non-null
|
|
404
|
-
if (lmaoType === 'boolean') {
|
|
405
|
-
return `
|
|
406
|
-
${cleanName}(value) {
|
|
407
|
-
if (value) {
|
|
408
|
-
this._buffer.${columnName}_values[0] |= 1;
|
|
409
|
-
} else {
|
|
410
|
-
this._buffer.${columnName}_values[0] &= ~1;
|
|
411
|
-
}
|
|
412
|
-
this._buffer.${columnName}_nulls[0] |= 1;
|
|
413
|
-
return this;
|
|
414
|
-
}`;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Generic writer for other types (number)
|
|
418
|
-
// Generated code: writes to row 0, direct value assignment, marks non-null
|
|
419
|
-
return `
|
|
420
|
-
${cleanName}(value) {
|
|
421
|
-
const idx = 0;
|
|
422
|
-
this._buffer.${columnName}_values[idx] = value;
|
|
423
|
-
this._buffer.${columnName}_nulls[0] |= 1;
|
|
424
|
-
return this;
|
|
425
|
-
}`;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
98
|
/**
|
|
429
|
-
*
|
|
99
|
+
* Create immutable output-to-source metadata for cold Arrow traversal.
|
|
430
100
|
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* HOW: Uses new Function() to generate optimized JavaScript code. The generated class
|
|
436
|
-
* has methods named after clean schema fields but writes to prefixed buffer columns.
|
|
437
|
-
*
|
|
438
|
-
* WHAT: Returns executable JavaScript code string for a SpanLogger class with:
|
|
439
|
-
* - Clean method names (status, method, url)
|
|
440
|
-
* - Writes to prefixed columns (http_status, http_method, http_url)
|
|
441
|
-
* - Full support for enum/category/text type handling
|
|
442
|
-
* - Method chaining support
|
|
443
|
-
*
|
|
444
|
-
* @param cleanSchema - Original clean schema (without prefix)
|
|
445
|
-
* @param prefixMapping - Mapping from clean names to prefixed names
|
|
446
|
-
* @param className - Name for the generated class
|
|
447
|
-
* @returns Executable JavaScript code string
|
|
448
|
-
*
|
|
449
|
-
* @example
|
|
450
|
-
* const code = generateRemappedSpanLoggerClass(
|
|
451
|
-
* { status: S.number(), method: S.enum(['GET', 'POST']) },
|
|
452
|
-
* { status: 'http_status', method: 'http_method' },
|
|
453
|
-
* 'HttpSpanLogger'
|
|
454
|
-
* );
|
|
455
|
-
* // Generated class has .status() method that writes to http_status
|
|
101
|
+
* The mapping is already fully composed by OpGroup prefix/map operations. Keeping
|
|
102
|
+
* both the frozen lookup and output schema entries avoids wrapping child buffers
|
|
103
|
+
* or reconstructing schema metadata during each traversal.
|
|
456
104
|
*/
|
|
457
|
-
export function
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
105
|
+
export function createRemapDescriptor(
|
|
106
|
+
sourceSchema: LogSchema,
|
|
107
|
+
outputToSourceMapping: Record<string, string>,
|
|
108
|
+
): RemapDescriptor {
|
|
109
|
+
const sourceNames: Record<string, string> = {};
|
|
110
|
+
const columns: RemappedColumn[] = [];
|
|
111
|
+
|
|
112
|
+
for (const [outputName, sourceName] of Object.entries(outputToSourceMapping)) {
|
|
113
|
+
sourceNames[outputName] = sourceName;
|
|
114
|
+
const fieldSchema = sourceSchema.fields[sourceName];
|
|
115
|
+
if (fieldSchema !== undefined) {
|
|
116
|
+
const column: RemappedColumn = Object.freeze([
|
|
117
|
+
outputName,
|
|
118
|
+
sourceName,
|
|
119
|
+
fieldSchema,
|
|
120
|
+
`${sourceName}_values`,
|
|
121
|
+
`${sourceName}_nulls`,
|
|
122
|
+
]);
|
|
123
|
+
columns.push(column);
|
|
476
124
|
}
|
|
477
125
|
}
|
|
478
126
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
return generateRemappedAttributeWriter(cleanName, prefixedName, fieldSchema, enumFieldNames.has(cleanName));
|
|
127
|
+
return Object.freeze({
|
|
128
|
+
sourceNames: Object.freeze(sourceNames),
|
|
129
|
+
columns: Object.freeze(columns),
|
|
483
130
|
});
|
|
484
|
-
|
|
485
|
-
// Create schema type map for runtime type detection in scope()
|
|
486
|
-
const schemaTypeMap = Object.fromEntries(
|
|
487
|
-
schemaFields.map(([fieldName, fieldSchema]) => {
|
|
488
|
-
return [fieldName, getSchemaType(fieldSchema) || 'unknown'];
|
|
489
|
-
}),
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
// Create clean-to-prefixed mapping for with() and scope() methods
|
|
493
|
-
const prefixMappingJson = JSON.stringify(prefixMapping);
|
|
494
|
-
|
|
495
|
-
// Entry type constants (imported from lmao.ts at module level, used here for code gen)
|
|
496
|
-
// These values are inlined into the generated code string below
|
|
497
|
-
|
|
498
|
-
// Generate the complete class
|
|
499
|
-
// Generated code: IIFE wrapper for clean scope
|
|
500
|
-
const classCode =
|
|
501
|
-
`(function() {
|
|
502
|
-
'use strict';
|
|
503
|
-
` +
|
|
504
|
-
// Generated code: getTimestampNanos - platform-aware timestamp function
|
|
505
|
-
// Node.js: uses process.hrtime.bigint() for true nanosecond precision
|
|
506
|
-
// Browser: uses performance.timeOrigin + performance.now() for microsecond precision
|
|
507
|
-
`const getTimestampNanos = (typeof process !== 'undefined' && process.hrtime)
|
|
508
|
-
? (() => {
|
|
509
|
-
const anchorEpochNanos = BigInt(Date.now()) * 1000000n;
|
|
510
|
-
const anchorHrtime = process.hrtime.bigint();
|
|
511
|
-
return () => anchorEpochNanos + (process.hrtime.bigint() - anchorHrtime);
|
|
512
|
-
})()
|
|
513
|
-
: () => {
|
|
514
|
-
const epochMicros = Math.round((performance.timeOrigin + performance.now()) * 1000);
|
|
515
|
-
return BigInt(epochMicros) * 1000n;
|
|
516
|
-
};
|
|
517
|
-
` +
|
|
518
|
-
// Generated code: enum mapping functions (getEnumIndex_${fieldName})
|
|
519
|
-
enumMappings.join('\n') +
|
|
520
|
-
`
|
|
521
|
-
` +
|
|
522
|
-
// Generated code: SCHEMA_TYPES - maps clean field names to lmao types for runtime type detection
|
|
523
|
-
`const SCHEMA_TYPES = ${JSON.stringify(schemaTypeMap)};
|
|
524
|
-
` +
|
|
525
|
-
// Generated code: PREFIX_MAPPING - maps clean names to prefixed column names
|
|
526
|
-
`const PREFIX_MAPPING = ${prefixMappingJson};
|
|
527
|
-
|
|
528
|
-
class ${className} {
|
|
529
|
-
` +
|
|
530
|
-
// Generated code: constructor stores buffer, createOverflowBuffer function, and scoped attributes
|
|
531
|
-
`constructor(buffer, createOverflowBuffer, initialScopedAttributes = {}) {
|
|
532
|
-
this._buffer = buffer;
|
|
533
|
-
this._createOverflowBuffer = createOverflowBuffer;
|
|
534
|
-
this._scopedAttributes = initialScopedAttributes;
|
|
535
|
-
}
|
|
536
|
-
` +
|
|
537
|
-
// Generated code: tag getter returns this for chainable API (writes to row 0 = span-start)
|
|
538
|
-
`get tag() {
|
|
539
|
-
return this;
|
|
540
|
-
}
|
|
541
|
-
` +
|
|
542
|
-
// Generated code: with() bulk attribute setting - maps clean names to prefixed columns,
|
|
543
|
-
// stores values directly (strings stored as-is), marks non-null (bit 0)
|
|
544
|
-
`with(attributes) {
|
|
545
|
-
const idx = 0;
|
|
546
|
-
for (const [cleanKey, value] of Object.entries(attributes)) {
|
|
547
|
-
const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
|
|
548
|
-
const columnName = prefixedKey;
|
|
549
|
-
const column = this._buffer[columnName + '_values'];
|
|
550
|
-
if (column && value !== null && value !== undefined) {
|
|
551
|
-
column[idx] = value;
|
|
552
|
-
const nullBitmap = this._buffer[columnName + '_nulls'];
|
|
553
|
-
if (nullBitmap) {
|
|
554
|
-
nullBitmap[0] |= 1;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
return this;
|
|
559
|
-
}
|
|
560
|
-
` +
|
|
561
|
-
// Generated code: individual attribute setters (one per schema field)
|
|
562
|
-
attributeWriters.join('\n') +
|
|
563
|
-
`
|
|
564
|
-
` +
|
|
565
|
-
// Generated code: scope() stores values in _scopedAttributes,
|
|
566
|
-
// then pre-fills remaining buffer capacity so future log entries inherit these values
|
|
567
|
-
`scope(attributes) {
|
|
568
|
-
for (const [cleanKey, value] of Object.entries(attributes)) {
|
|
569
|
-
if (value !== null && value !== undefined) {
|
|
570
|
-
this._scopedAttributes[cleanKey] = value;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
const startIdx = this._buffer._writeIndex;
|
|
574
|
-
const endIdx = this._buffer._capacity;
|
|
575
|
-
for (let idx = startIdx; idx < endIdx; idx++) {
|
|
576
|
-
for (const [cleanKey, value] of Object.entries(this._scopedAttributes)) {
|
|
577
|
-
const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
|
|
578
|
-
const columnName = prefixedKey;
|
|
579
|
-
const column = this._buffer[columnName + '_values'];
|
|
580
|
-
if (column) {
|
|
581
|
-
column[idx] = value;
|
|
582
|
-
const nullBitmap = this._buffer[columnName + '_nulls'];
|
|
583
|
-
if (nullBitmap) {
|
|
584
|
-
const byteIndex = Math.floor(idx / 8);
|
|
585
|
-
const bitOffset = idx % 8;
|
|
586
|
-
nullBitmap[byteIndex] |= (1 << bitOffset);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
` +
|
|
593
|
-
// Generated code: _writeMessage() writes a log entry - ensures buffer has space,
|
|
594
|
-
// writes entry type + timestamp + message, applies scoped attributes
|
|
595
|
-
`_writeMessage(entryType, message) {
|
|
596
|
-
// Check if buffer is full and create overflow buffer if needed
|
|
597
|
-
if (this._buffer._writeIndex >= this._buffer._capacity) {
|
|
598
|
-
const oldBuffer = this._buffer;
|
|
599
|
-
this._buffer = this._createOverflowBuffer(oldBuffer);
|
|
600
|
-
oldBuffer._overflow = this._buffer;
|
|
601
|
-
}
|
|
602
|
-
const idx = this._buffer._writeIndex;
|
|
603
|
-
this._buffer.entry_type[idx] = entryType;
|
|
604
|
-
this._buffer.timestamp[idx] = getTimestampNanos(this._buffer._traceRoot.anchorEpochNanos, this._buffer._traceRoot.anchorPerfNow);
|
|
605
|
-
const messageColumn = this._buffer.message_values;
|
|
606
|
-
if (messageColumn) {
|
|
607
|
-
messageColumn[idx] = message;
|
|
608
|
-
const nullBitmap = this._buffer.message_nulls;
|
|
609
|
-
if (nullBitmap) {
|
|
610
|
-
const byteIndex = Math.floor(idx / 8);
|
|
611
|
-
const bitOffset = idx % 8;
|
|
612
|
-
nullBitmap[byteIndex] |= (1 << bitOffset);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
for (const [cleanKey, value] of Object.entries(this._scopedAttributes)) {
|
|
616
|
-
const prefixedKey = PREFIX_MAPPING[cleanKey] || cleanKey;
|
|
617
|
-
const columnName = prefixedKey;
|
|
618
|
-
const column = this._buffer[columnName + '_values'];
|
|
619
|
-
if (column) {
|
|
620
|
-
column[idx] = value;
|
|
621
|
-
const nullBitmap = this._buffer[columnName + '_nulls'];
|
|
622
|
-
if (nullBitmap) {
|
|
623
|
-
const byteIndex = Math.floor(idx / 8);
|
|
624
|
-
const bitOffset = idx % 8;
|
|
625
|
-
nullBitmap[byteIndex] |= (1 << bitOffset);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
this._buffer._writeIndex++;
|
|
630
|
-
}
|
|
631
|
-
` +
|
|
632
|
-
// Generated code: message() generic logging with level string mapping to entry type constants
|
|
633
|
-
`message(level, message) {
|
|
634
|
-
const entryTypeMap = {
|
|
635
|
-
'info': ${ENTRY_TYPE_INFO},
|
|
636
|
-
'debug': ${ENTRY_TYPE_DEBUG},
|
|
637
|
-
'warn': ${ENTRY_TYPE_WARN},
|
|
638
|
-
'error': ${ENTRY_TYPE_ERROR},
|
|
639
|
-
'trace': ${ENTRY_TYPE_TRACE}
|
|
640
|
-
};
|
|
641
|
-
this._writeMessage(entryTypeMap[level] || ${ENTRY_TYPE_INFO}, message);
|
|
642
|
-
}
|
|
643
|
-
` +
|
|
644
|
-
// Generated code: convenience logging methods - each calls _writeMessage with entry type constant
|
|
645
|
-
`info(message) { this._writeMessage(${ENTRY_TYPE_INFO}, message); }
|
|
646
|
-
debug(message) { this._writeMessage(${ENTRY_TYPE_DEBUG}, message); }
|
|
647
|
-
warn(message) { this._writeMessage(${ENTRY_TYPE_WARN}, message); }
|
|
648
|
-
error(message) { this._writeMessage(${ENTRY_TYPE_ERROR}, message); }
|
|
649
|
-
trace(message) { this._writeMessage(${ENTRY_TYPE_TRACE}, message); }
|
|
650
|
-
}
|
|
651
|
-
return ${className};
|
|
652
|
-
})()`;
|
|
653
|
-
|
|
654
|
-
return classCode;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Create a remapped SpanLogger class constructor from clean schema and prefix mapping
|
|
659
|
-
*
|
|
660
|
-
* WHY: This is the cold-path function called at module creation time. It compiles
|
|
661
|
-
* the generated class code once and caches the constructor.
|
|
662
|
-
*
|
|
663
|
-
* @param cleanSchema - Clean schema (without prefix)
|
|
664
|
-
* @param prefixMapping - Mapping from clean names to prefixed names
|
|
665
|
-
* @returns Constructor for the remapped SpanLogger class
|
|
666
|
-
*/
|
|
667
|
-
export function createRemappedSpanLoggerClass<T extends LogSchema>(
|
|
668
|
-
cleanSchema: T,
|
|
669
|
-
prefixMapping: PrefixMapping,
|
|
670
|
-
): RemappedSpanLoggerConstructor<T> {
|
|
671
|
-
// Check cache first
|
|
672
|
-
const cacheKey = createSchemaAndMappingCacheKey(cleanSchema, prefixMapping);
|
|
673
|
-
const cached = remappedSpanLoggerClassCache.get(cacheKey);
|
|
674
|
-
if (cached && isRemappedSpanLoggerClass<T>(cached)) {
|
|
675
|
-
return cached;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
const classCode = generateRemappedSpanLoggerClass(cleanSchema, prefixMapping).trim();
|
|
679
|
-
|
|
680
|
-
const GeneratedClass = new Function(`return ${classCode}`)();
|
|
681
|
-
if (!isRemappedSpanLoggerClass<T>(GeneratedClass)) {
|
|
682
|
-
throw new TypeError('Generated remapped span logger is missing required logging methods');
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
remappedSpanLoggerClassCache.set(cacheKey, GeneratedClass);
|
|
686
|
-
|
|
687
|
-
return GeneratedClass;
|
|
688
131
|
}
|
|
689
|
-
//#endregion smoo/lmao!n/codegen-prefixed-remap
|