@posthog/core 1.69.8 → 1.69.9
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/error-tracking/exception-steps.d.ts +2 -0
- package/dist/error-tracking/exception-steps.d.ts.map +1 -1
- package/dist/error-tracking/exception-steps.js +6 -0
- package/dist/error-tracking/exception-steps.mjs +6 -0
- package/package.json +1 -1
- package/src/error-tracking/exception-steps.spec.ts +25 -0
- package/src/error-tracking/exception-steps.ts +12 -0
- package/src/traces/index.spec.ts +5 -0
|
@@ -31,6 +31,8 @@ export declare class ExceptionStepsBuffer {
|
|
|
31
31
|
add(step: ExceptionStep): void;
|
|
32
32
|
getAttachable(): ExceptionStep[];
|
|
33
33
|
clear(): void;
|
|
34
|
+
/** Remove captured steps without consuming steps added after a deferred exception. */
|
|
35
|
+
clearThrough(step: ExceptionStep): void;
|
|
34
36
|
size(): number;
|
|
35
37
|
private _trimToMaxBytes;
|
|
36
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-steps.d.ts","sourceRoot":"","sources":["../../src/error-tracking/exception-steps.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B;aACzC,OAAO,EAAE,UAAU;aACnB,SAAS,EAAE,YAAY;CACf,CAAA;AAOV,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,8BAA8B,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChD,CAAC,8BAA8B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB,CAAA;AAED,kGAAkG;AAClG,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,E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ExceptionStepsBuffer {
|
|
|
105
105
|
this._entries = [];
|
|
106
106
|
this._totalBytes = 0;
|
|
107
107
|
}
|
|
108
|
+
clearThrough(step) {
|
|
109
|
+
const index = this._entries.findIndex((entry)=>entry.step === step);
|
|
110
|
+
if (-1 === index) return;
|
|
111
|
+
for(let i = 0; i <= index; i++)this._totalBytes -= this._entries[i].bytes;
|
|
112
|
+
this._entries.splice(0, index + 1);
|
|
113
|
+
}
|
|
108
114
|
size() {
|
|
109
115
|
return this._entries.length;
|
|
110
116
|
}
|
|
@@ -68,6 +68,12 @@ class ExceptionStepsBuffer {
|
|
|
68
68
|
this._entries = [];
|
|
69
69
|
this._totalBytes = 0;
|
|
70
70
|
}
|
|
71
|
+
clearThrough(step) {
|
|
72
|
+
const index = this._entries.findIndex((entry)=>entry.step === step);
|
|
73
|
+
if (-1 === index) return;
|
|
74
|
+
for(let i = 0; i <= index; i++)this._totalBytes -= this._entries[i].bytes;
|
|
75
|
+
this._entries.splice(0, index + 1);
|
|
76
|
+
}
|
|
71
77
|
size() {
|
|
72
78
|
return this._entries.length;
|
|
73
79
|
}
|
package/package.json
CHANGED
|
@@ -80,6 +80,31 @@ describe('exception steps', () => {
|
|
|
80
80
|
expect(buffer.getAttachable().map((s) => s.$message)).toEqual(expected)
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
+
it('clears captured steps while retaining newer steps and their byte accounting', () => {
|
|
84
|
+
const budget = bytesOf(makeStep('two')) + bytesOf(makeStep('three'))
|
|
85
|
+
const buffer = new ExceptionStepsBuffer({ max_bytes: budget })
|
|
86
|
+
buffer.add(makeStep('one'))
|
|
87
|
+
const captured = buffer.getAttachable()[0]
|
|
88
|
+
buffer.add(makeStep('two'))
|
|
89
|
+
buffer.clearThrough(captured)
|
|
90
|
+
expect(buffer.getAttachable().map((step) => step.$message)).toEqual(['two'])
|
|
91
|
+
buffer.add(makeStep('three'))
|
|
92
|
+
expect(buffer.getAttachable().map((step) => step.$message)).toEqual(['two', 'three'])
|
|
93
|
+
buffer.clearThrough(captured)
|
|
94
|
+
expect(buffer.size()).toBe(2)
|
|
95
|
+
buffer.clearThrough(buffer.getAttachable()[1])
|
|
96
|
+
expect(buffer.size()).toBe(0)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('leaves newer steps untouched when a captured step has already been evicted', () => {
|
|
100
|
+
const buffer = new ExceptionStepsBuffer({ max_bytes: bytesOf(makeStep('one')) })
|
|
101
|
+
buffer.add(makeStep('one'))
|
|
102
|
+
const captured = buffer.getAttachable()[0]
|
|
103
|
+
buffer.add(makeStep('two'))
|
|
104
|
+
buffer.clearThrough(captured)
|
|
105
|
+
expect(buffer.getAttachable().map((step) => step.$message)).toEqual(['two'])
|
|
106
|
+
})
|
|
107
|
+
|
|
83
108
|
it('clears all steps', () => {
|
|
84
109
|
const buffer = new ExceptionStepsBuffer({ max_bytes: 10000 })
|
|
85
110
|
buffer.add(makeStep('one'))
|
|
@@ -106,6 +106,18 @@ export class ExceptionStepsBuffer {
|
|
|
106
106
|
this._totalBytes = 0
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Remove captured steps without consuming steps added after a deferred exception. */
|
|
110
|
+
public clearThrough(step: ExceptionStep): void {
|
|
111
|
+
const index = this._entries.findIndex((entry) => entry.step === step)
|
|
112
|
+
if (index === -1) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i <= index; i++) {
|
|
116
|
+
this._totalBytes -= this._entries[i].bytes
|
|
117
|
+
}
|
|
118
|
+
this._entries.splice(0, index + 1)
|
|
119
|
+
}
|
|
120
|
+
|
|
109
121
|
public size(): number {
|
|
110
122
|
return this._entries.length
|
|
111
123
|
}
|
package/src/traces/index.spec.ts
CHANGED
|
@@ -75,6 +75,11 @@ describe('PostHogTraces', () => {
|
|
|
75
75
|
vi.spyOn(Math, 'random').mockReturnValue(0.5)
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
// Retry timers from earlier tracers must not run during later tests.
|
|
80
|
+
vi.clearAllTimers()
|
|
81
|
+
})
|
|
82
|
+
|
|
78
83
|
describe('startSpan', () => {
|
|
79
84
|
it('enqueues exactly one record per span', async () => {
|
|
80
85
|
const traces = createTraces()
|