Skip to content

Commit c170e19

Browse files
committed
fix(posthog): upgrade SDKs and fix serverless event flushing
1 parent 75f8c6a commit c170e19

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

apps/sim/instrumentation-node.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,17 @@ async function initializeOpenTelemetry() {
140140

141141
sdk.start()
142142

143-
const shutdownHandler = async () => {
143+
const shutdownOtel = async () => {
144144
try {
145145
await sdk.shutdown()
146146
logger.info('OpenTelemetry SDK shut down successfully')
147147
} catch (err) {
148148
logger.error('Error shutting down OpenTelemetry SDK', err)
149149
}
150-
151-
try {
152-
const { getPostHogClient } = await import('@/lib/posthog/server')
153-
await getPostHogClient()?.shutdown()
154-
logger.info('PostHog client shut down successfully')
155-
} catch (err) {
156-
logger.error('Error shutting down PostHog client', err)
157-
}
158150
}
159151

160-
process.on('SIGTERM', shutdownHandler)
161-
process.on('SIGINT', shutdownHandler)
152+
process.on('SIGTERM', shutdownOtel)
153+
process.on('SIGINT', shutdownOtel)
162154

163155
logger.info('OpenTelemetry instrumentation initialized with business span filtering')
164156
} catch (error) {
@@ -169,6 +161,19 @@ async function initializeOpenTelemetry() {
169161
export async function register() {
170162
await initializeOpenTelemetry()
171163

164+
const shutdownPostHog = async () => {
165+
try {
166+
const { getPostHogClient } = await import('@/lib/posthog/server')
167+
await getPostHogClient()?.shutdown()
168+
logger.info('PostHog client shut down successfully')
169+
} catch (err) {
170+
logger.error('Error shutting down PostHog client', err)
171+
}
172+
}
173+
174+
process.on('SIGTERM', shutdownPostHog)
175+
process.on('SIGINT', shutdownPostHog)
176+
172177
const { startMemoryTelemetry } = await import('./lib/monitoring/memory-telemetry')
173178
startMemoryTelemetry()
174179
}

apps/sim/lib/posthog/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getClient(): import('posthog-node').PostHog | null {
2626
const { PostHog } = require('posthog-node') as typeof import('posthog-node')
2727
_client = new PostHog(key, {
2828
host: 'https://us.i.posthog.com',
29-
flushAt: 20,
29+
flushAt: 1,
3030
flushInterval: 10_000,
3131
})
3232
return _client

apps/sim/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
"papaparse": "5.5.3",
155155
"pdf-lib": "1.17.1",
156156
"postgres": "^3.4.5",
157-
"posthog-js": "1.334.1",
158-
"posthog-node": "5.9.2",
157+
"posthog-js": "1.364.4",
158+
"posthog-node": "5.28.9",
159159
"pptxgenjs": "4.0.1",
160160
"pptxviewjs": "1.1.8",
161161
"prismjs": "^1.30.0",

bun.lock

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)