@@ -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() {
169161export 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}
0 commit comments