@stackone/olap 1.66.0 → 1.67.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 +87 -0
- package/dist/index.cjs +121 -23
- package/dist/index.d.cts +25 -20
- package/dist/index.d.mts +25 -20
- package/dist/index.mjs +124 -26
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -48,3 +48,90 @@ $ pnpm lint
|
|
|
48
48
|
# run linter and try to fix any error
|
|
49
49
|
$ pnpm lint:fix
|
|
50
50
|
```
|
|
51
|
+
|
|
52
|
+
## Advanced log truncation
|
|
53
|
+
|
|
54
|
+
Advanced logs hold the full request and response of a call. When one is too large to store, what the
|
|
55
|
+
sink does is chosen **per call** by `advanced.truncation`, so the behaviour can be driven by a feature
|
|
56
|
+
flag outside this package.
|
|
57
|
+
|
|
58
|
+
### Modes
|
|
59
|
+
|
|
60
|
+
| Mode | An oversized log becomes | Budget |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `drop` (default) | its whole `data` object replaced by `{ "outputs": { "error": "Error.TOO_LARGE" } }` | `maxItemSizeBytes` |
|
|
63
|
+
| `truncate` | its payload fields cut to fit, envelope intact | `maxItemSizeBytes`, ×`errorSizeMultiplier` for failures |
|
|
64
|
+
| `complete` | stored whole, at any size | none |
|
|
65
|
+
|
|
66
|
+
`drop` is the default and is what the sink has always done, so an unset flag changes nothing. Note
|
|
67
|
+
that it discards the envelope along with the payload — method, URL, status code and the run
|
|
68
|
+
identifiers all go — which is exactly what `truncate` exists to fix. Prefer `truncate`; `drop` is
|
|
69
|
+
there to roll back to.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
await olapClient.recordAction(input, result, {
|
|
73
|
+
advanced: { enabled: true, truncation: 'truncate' },
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Platform logs are never truncated, in any mode.** They are audit records of events we generate
|
|
78
|
+
ourselves, so losing part of one is worse than storing a large object, and their `data` has no fixed
|
|
79
|
+
payload paths to cut. Their size is still recorded.
|
|
80
|
+
|
|
81
|
+
### Budgets, in `truncate` mode
|
|
82
|
+
|
|
83
|
+
- `maxItemSizeBytes` (default `MAX_LOG_SIZE_BYTES`, 10MB) is the target size for a log. It is a
|
|
84
|
+
**soft** target: the per-field floor below means a stored log can slightly exceed it.
|
|
85
|
+
- A failed result — non-2xx/3xx status, `success: false`, `hasStepErrors: true`, or recorded errors —
|
|
86
|
+
gets `maxItemSizeBytes * errorSizeMultiplier` (default `5`), because a failure is the payload most
|
|
87
|
+
worth keeping in full. At the defaults that is `MAX_EXTENDED_LOG_SIZE_BYTES`, 50MB. The multiplier
|
|
88
|
+
is a `truncate`-mode allowance only: `drop` measures against the flat limit, so it discards a large
|
|
89
|
+
failure exactly as it always has.
|
|
90
|
+
- Only payload fields are ever truncated: `data.request.body`, `data.response.body`, `data.input`,
|
|
91
|
+
`data.outputs` and `data.errors`. Method, URL, headers, status code and the run identifiers survive
|
|
92
|
+
verbatim at any size.
|
|
93
|
+
- Bodies we sent (`data.request.body`, `data.input`) bid to be kept whole first, so a call stays as
|
|
94
|
+
replayable as possible. A body too large to keep whole loses that priority and competes for an
|
|
95
|
+
equal share like any other field.
|
|
96
|
+
- No field is ever allocated less than 64KB, so a 30MB array is stored truncated rather than as `[]`.
|
|
97
|
+
|
|
98
|
+
### Metadata
|
|
99
|
+
|
|
100
|
+
Size information sits flat on `metadata`:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"metadata": {
|
|
105
|
+
"expirationTime": 1750000000,
|
|
106
|
+
"sizeBytes": 24117248,
|
|
107
|
+
"maxSizeBytes": 10485760,
|
|
108
|
+
"truncated": true
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
- `sizeBytes` — the estimated size of the log before truncation. Present on **every** advanced log,
|
|
114
|
+
in **every** mode, so the effect of a mode change can be measured before making it.
|
|
115
|
+
- `maxSizeBytes` and `truncated` — present **only** when a budget was applied and exceeded. They are
|
|
116
|
+
absent, not `false`, on a log that fitted or that was stored whole, so `metadata.truncated` is the
|
|
117
|
+
single signal a reader needs.
|
|
118
|
+
|
|
119
|
+
### What a truncated field looks like, in `truncate` mode
|
|
120
|
+
|
|
121
|
+
Truncation is structural — serialized JSON is never sliced, so a partial record is never emitted.
|
|
122
|
+
|
|
123
|
+
- **Arrays** keep their leading elements whole and drop the rest. No marker element is appended: the
|
|
124
|
+
retained elements stay valid for element-wise consumers and typed deserializers.
|
|
125
|
+
- **Objects** keep the entries that fit, smallest-first, and truncate the rest recursively. No key is
|
|
126
|
+
ever dropped, so a reader still finds the field it was looking for.
|
|
127
|
+
- **Strings** are sliced and suffixed with ` [truncated]`, so a raw render can never look complete.
|
|
128
|
+
- **Numbers, booleans and dates** are kept whole. They have nothing to cut, they cost at most 8 bytes
|
|
129
|
+
— fewer than the marker that would replace them — and replacing them would change the field's type.
|
|
130
|
+
- **A container with no budget at all** for its contents becomes
|
|
131
|
+
`{ "truncated": true, "sizeBytes": <n> }`, because an empty array or object would read as real data.
|
|
132
|
+
|
|
133
|
+
So truncation never changes the type of a stored field: arrays stay arrays of whole elements, objects
|
|
134
|
+
keep their keys, strings stay strings, scalars are untouched.
|
|
135
|
+
|
|
136
|
+
A log that cannot be serialized at all — one carrying a value `JSON.stringify` refuses, such as a
|
|
137
|
+
BigInt — is stored with its payload fields dropped and its envelope intact, rather than being lost.
|