Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(posthog): upgrade SDKs and fix serverless event flushing
  • Loading branch information
waleedlatif1 committed Apr 4, 2026
commit c170e1935bef784045305f4ae873422fbd9574ca
27 changes: 16 additions & 11 deletions apps/sim/instrumentation-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,17 @@ async function initializeOpenTelemetry() {

sdk.start()

const shutdownHandler = async () => {
const shutdownOtel = async () => {
try {
await sdk.shutdown()
logger.info('OpenTelemetry SDK shut down successfully')
} catch (err) {
logger.error('Error shutting down OpenTelemetry SDK', err)
}

try {
const { getPostHogClient } = await import('@/lib/posthog/server')
await getPostHogClient()?.shutdown()
logger.info('PostHog client shut down successfully')
} catch (err) {
logger.error('Error shutting down PostHog client', err)
}
}

process.on('SIGTERM', shutdownHandler)
process.on('SIGINT', shutdownHandler)
process.on('SIGTERM', shutdownOtel)
process.on('SIGINT', shutdownOtel)

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

const shutdownPostHog = async () => {
try {
const { getPostHogClient } = await import('@/lib/posthog/server')
await getPostHogClient()?.shutdown()
logger.info('PostHog client shut down successfully')
} catch (err) {
logger.error('Error shutting down PostHog client', err)
}
}

process.on('SIGTERM', shutdownPostHog)
process.on('SIGINT', shutdownPostHog)

const { startMemoryTelemetry } = await import('./lib/monitoring/memory-telemetry')
startMemoryTelemetry()
}
2 changes: 1 addition & 1 deletion apps/sim/lib/posthog/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getClient(): import('posthog-node').PostHog | null {
const { PostHog } = require('posthog-node') as typeof import('posthog-node')
_client = new PostHog(key, {
host: 'https://us.i.posthog.com',
flushAt: 20,
flushAt: 1,
flushInterval: 10_000,
})
return _client
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
"papaparse": "5.5.3",
"pdf-lib": "1.17.1",
"postgres": "^3.4.5",
"posthog-js": "1.334.1",
"posthog-node": "5.9.2",
"posthog-js": "1.364.4",
"posthog-node": "5.28.9",
"pptxgenjs": "4.0.1",
"pptxviewjs": "1.1.8",
"prismjs": "^1.30.0",
Expand Down
14 changes: 6 additions & 8 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading