@reproapp/node-sdk 0.0.12 → 0.0.13

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.
@@ -4,7 +4,13 @@ exports.flushIngestQueue = exports.enqueueIngestEntries = exports.postIngestEntr
4
4
  const mapper_1 = require("./mapper");
5
5
  const DEFAULT_INGEST_BASE = 'http://localhost:8080';
6
6
  const DEFAULT_INGEST_PATH = '/v1/ingest/events';
7
- const DEFAULT_QUEUE_MAX_ITEMS = 1000;
7
+ const DEFAULT_QUEUE_MAX_ITEMS = (() => {
8
+ const env = Number(typeof process !== 'undefined' ? process?.env?.REPRO_INGEST_QUEUE_MAX_ITEMS : undefined);
9
+ if (Number.isFinite(env) && env > 0) {
10
+ return Math.trunc(env);
11
+ }
12
+ return 0;
13
+ })();
8
14
  const DEFAULT_QUEUE_MAX_ATTEMPTS = 5;
9
15
  const DEFAULT_QUEUE_BACKOFF_MAX_MS = 4000;
10
16
  const DEFAULT_DEFER_DRAIN_MS = 25;
@@ -142,7 +148,7 @@ const enqueueIngestEntries = (config, sessionId, entries) => {
142
148
  entries: entries.slice(),
143
149
  attempts: 0,
144
150
  });
145
- if (ingestQueue.length > DEFAULT_QUEUE_MAX_ITEMS) {
151
+ if (DEFAULT_QUEUE_MAX_ITEMS > 0 && ingestQueue.length > DEFAULT_QUEUE_MAX_ITEMS) {
146
152
  ingestQueue.splice(0, ingestQueue.length - DEFAULT_QUEUE_MAX_ITEMS);
147
153
  }
148
154
  scheduleDrain(shouldDeferDrain?.() ? deferDrainMs : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reproapp/node-sdk",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  "build": "tsc -p tsconfig.json",
13
13
  "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
14
14
  "prepublishOnly": "npm run build",
15
- "test": "npm run build && node test/unawaited.test.js && node test/integration-unawaited.js && node test/request-flush-timing.test.js && node test/express-trace-http-args.test.js && node test/trace-batch-size.test.js && node test/sdk-background-priority.test.js && node -r ./tracer/register test/promise-map.test.js && node test/disable-subtree.test.js && node test/circular-capture.test.js && node test/wrap-plugin-arrow-args.test.js && node test/privacy-runtime-policy.test.js && node test/runtime-privacy-materialization.test.js && node test/kafka-runtime-privacy-policy.test.js"
15
+ "test": "npm run build && node test/unawaited.test.js && node test/integration-unawaited.js && node test/request-flush-timing.test.js && node test/express-trace-http-args.test.js && node test/trace-batch-size.test.js && node test/sdk-background-priority.test.js && node test/ingest-queue-retention.test.js && node -r ./tracer/register test/promise-map.test.js && node test/disable-subtree.test.js && node test/circular-capture.test.js && node test/wrap-plugin-arrow-args.test.js && node test/privacy-runtime-policy.test.js && node test/runtime-privacy-materialization.test.js && node test/kafka-runtime-privacy-policy.test.js"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "express": "^5.1.0",
@@ -3,7 +3,13 @@ import type { IngestClientConfig, LegacyEntry } from './types';
3
3
 
4
4
  const DEFAULT_INGEST_BASE = 'http://localhost:8080';
5
5
  const DEFAULT_INGEST_PATH = '/v1/ingest/events';
6
- const DEFAULT_QUEUE_MAX_ITEMS = 1000;
6
+ const DEFAULT_QUEUE_MAX_ITEMS = (() => {
7
+ const env = Number(typeof process !== 'undefined' ? (process as any)?.env?.REPRO_INGEST_QUEUE_MAX_ITEMS : undefined);
8
+ if (Number.isFinite(env) && env > 0) {
9
+ return Math.trunc(env);
10
+ }
11
+ return 0;
12
+ })();
7
13
  const DEFAULT_QUEUE_MAX_ATTEMPTS = 5;
8
14
  const DEFAULT_QUEUE_BACKOFF_MAX_MS = 4000;
9
15
  const DEFAULT_DEFER_DRAIN_MS = 25;
@@ -177,7 +183,7 @@ export const enqueueIngestEntries = (
177
183
  entries: entries.slice(),
178
184
  attempts: 0,
179
185
  });
180
- if (ingestQueue.length > DEFAULT_QUEUE_MAX_ITEMS) {
186
+ if (DEFAULT_QUEUE_MAX_ITEMS > 0 && ingestQueue.length > DEFAULT_QUEUE_MAX_ITEMS) {
181
187
  ingestQueue.splice(0, ingestQueue.length - DEFAULT_QUEUE_MAX_ITEMS);
182
188
  }
183
189
  scheduleDrain(shouldDeferDrain?.() ? deferDrainMs : 0);
@@ -0,0 +1,82 @@
1
+ const assert = require('assert');
2
+
3
+ const originalFetch = global.fetch;
4
+ const capturedBodies = [];
5
+
6
+ global.fetch = async (_url, init = {}) => {
7
+ capturedBodies.push(JSON.parse(String(init.body || '{}')));
8
+ return {
9
+ ok: true,
10
+ status: 200,
11
+ json: async () => ({ ok: true }),
12
+ text: async () => '{"ok":true}',
13
+ };
14
+ };
15
+
16
+ const { enqueueIngestEntries, flushIngestQueue } = require('../dist/ingest/client');
17
+
18
+ async function main() {
19
+ const cfg = {
20
+ tenantId: 'TENANT_test',
21
+ appId: 'APP_test',
22
+ appSecret: 'secret',
23
+ serviceName: 'queue-retention-test',
24
+ ingestBase: 'http://127.0.0.1:65535',
25
+ };
26
+
27
+ const sessionId = 'S_queue_retention';
28
+ const requestRid = 'R_queue_retention';
29
+ const totalBatches = 1414;
30
+
31
+ for (let index = 0; index < totalBatches; index += 1) {
32
+ enqueueIngestEntries(cfg, sessionId, [{
33
+ actionId: 'A_queue_retention',
34
+ trace: [{
35
+ t: Date.now(),
36
+ type: 'enter',
37
+ fn: `trace-${index}`,
38
+ }],
39
+ traceBatch: {
40
+ rid: requestRid,
41
+ index,
42
+ total: totalBatches,
43
+ },
44
+ t: Date.now(),
45
+ }]);
46
+ }
47
+
48
+ await flushIngestQueue();
49
+
50
+ const traceEvents = capturedBodies.flatMap((body) => Array.isArray(body?.events) ? body.events : [])
51
+ .filter((event) => event?.event_type === 'trace_batch');
52
+
53
+ assert.strictEqual(traceEvents.length, totalBatches, JSON.stringify({
54
+ got: traceEvents.length,
55
+ expected: totalBatches,
56
+ }));
57
+
58
+ const indexes = traceEvents
59
+ .map((event) => Number(event?.payload?.traceBatch?.index))
60
+ .filter((value) => Number.isFinite(value))
61
+ .sort((left, right) => left - right);
62
+
63
+ assert.strictEqual(indexes.length, totalBatches, JSON.stringify({
64
+ got: indexes.length,
65
+ expected: totalBatches,
66
+ }));
67
+ assert.strictEqual(indexes[0], 0);
68
+ assert.strictEqual(indexes[indexes.length - 1], totalBatches - 1);
69
+
70
+ // eslint-disable-next-line no-console
71
+ console.log('ingest queue retention OK');
72
+ }
73
+
74
+ main()
75
+ .catch((error) => {
76
+ // eslint-disable-next-line no-console
77
+ console.error(error);
78
+ process.exitCode = 1;
79
+ })
80
+ .finally(() => {
81
+ global.fetch = originalFetch;
82
+ });