Skip to content

Commit f026e77

Browse files
committed
fix(node): standardize flush interval default
1 parent fad6d9a commit f026e77

5 files changed

Lines changed: 33 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'posthog-node': patch
3+
---
4+
5+
Fix the default Node.js event flush interval at 5 seconds.

packages/node/references/posthog-node-references-latest.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,6 +2966,11 @@
29662966
{
29672967
"type": "number[]",
29682968
"name": "experiment_set"
2969+
},
2970+
{
2971+
"description": "Whether the flag is linked to an experiment. Absent when the server does not report it.",
2972+
"type": "boolean",
2973+
"name": "has_experiment"
29692974
}
29702975
],
29712976
"path": "src/types.ts"
@@ -3244,11 +3249,6 @@
32443249
"type": "number",
32453250
"name": "flushAt"
32463251
},
3247-
{
3248-
"description": "The interval in milliseconds between periodic flushes",
3249-
"type": "number",
3250-
"name": "flushInterval"
3251-
},
32523252
{
32533253
"description": "The maximum number of queued messages to be flushed as part of a single batch (must be higher than `flushAt`)",
32543254
"type": "number",
@@ -3368,6 +3368,11 @@
33683368
"type": "\"memory\"",
33693369
"name": "persistence"
33703370
},
3371+
{
3372+
"description": "The interval in milliseconds between periodic flushes",
3373+
"type": "number",
3374+
"name": "flushInterval"
3375+
},
33713376
{
33723377
"description": "The maximum number of cached messages either in memory or on the local storage (must be higher than `flushAt`)",
33733378
"type": "number",

packages/node/src/__tests__/posthog-node.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ describe('PostHog Node.js', () => {
616616
})
617617
})
618618

619+
describe('flushInterval', () => {
620+
it('defaults to 5000 for Node', () => {
621+
const ph = new PostHog('TEST_API_KEY', {
622+
host: 'http://example.com',
623+
})
624+
625+
expect((ph as any).flushInterval).toBe(5000)
626+
})
627+
})
628+
619629
describe('maxQueueSize', () => {
620630
it('defaults to 10000, higher than the shared core default of 1000', () => {
621631
const ph = new PostHog('TEST_API_KEY', {

packages/node/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
192192
// Applied after the spread with a nullish fallback so a wrapper forwarding
193193
// `maxQueueSize: undefined` still gets the Node default, not the core one.
194194
maxQueueSize: options.maxQueueSize ?? 10000,
195+
flushInterval: options.flushInterval ?? 5000,
195196
host: normalizeHost(options.host),
196197
personalApiKey: normalizePersonalApiKey(options.secretKey ?? options.personalApiKey),
197198
}

packages/node/src/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,14 @@ export type FeatureFlagBucketingIdentifier = 'distinct_id' | 'device_id' | '' |
146146

147147
export type BeforeSendFn = (event: EventMessage | null) => EventMessage | null
148148

149-
export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'maxQueueSize'> & {
149+
export type PostHogOptions = Omit<PostHogCoreOptions, 'before_send' | 'flushInterval' | 'maxQueueSize'> & {
150150
persistence?: 'memory'
151+
/**
152+
* The interval in milliseconds between periodic flushes
153+
*
154+
* @default 5000
155+
*/
156+
flushInterval?: number
151157
/**
152158
* The maximum number of cached messages either in memory or on the local storage (must be higher than `flushAt`)
153159
*

0 commit comments

Comments
 (0)