Show OpenTelemetry SDK initialization & shutdown in debug mode only (#6096)
This commit is contained in:
parent
806af05b97
commit
431a312d4d
|
@ -143,7 +143,7 @@ export async function runNonInteractive(
|
|||
} finally {
|
||||
consolePatcher.cleanup();
|
||||
if (isTelemetrySdkInitialized()) {
|
||||
await shutdownTelemetry();
|
||||
await shutdownTelemetry(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,25 +125,33 @@ export function initializeTelemetry(config: Config): void {
|
|||
|
||||
try {
|
||||
sdk.start();
|
||||
console.log('OpenTelemetry SDK started successfully.');
|
||||
if (config.getDebugMode()) {
|
||||
console.log('OpenTelemetry SDK started successfully.');
|
||||
}
|
||||
telemetryInitialized = true;
|
||||
initializeMetrics(config);
|
||||
} catch (error) {
|
||||
console.error('Error starting OpenTelemetry SDK:', error);
|
||||
}
|
||||
|
||||
process.on('SIGTERM', shutdownTelemetry);
|
||||
process.on('SIGINT', shutdownTelemetry);
|
||||
process.on('SIGTERM', () => {
|
||||
shutdownTelemetry(config);
|
||||
});
|
||||
process.on('SIGINT', () => {
|
||||
shutdownTelemetry(config);
|
||||
});
|
||||
}
|
||||
|
||||
export async function shutdownTelemetry(): Promise<void> {
|
||||
export async function shutdownTelemetry(config: Config): Promise<void> {
|
||||
if (!telemetryInitialized || !sdk) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ClearcutLogger.getInstance()?.shutdown();
|
||||
await sdk.shutdown();
|
||||
console.log('OpenTelemetry SDK shut down successfully.');
|
||||
if (config.getDebugMode()) {
|
||||
console.log('OpenTelemetry SDK shut down successfully.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error shutting down SDK:', error);
|
||||
} finally {
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('telemetry', () => {
|
|||
afterEach(async () => {
|
||||
// Ensure we shut down telemetry even if a test fails.
|
||||
if (isTelemetrySdkInitialized()) {
|
||||
await shutdownTelemetry();
|
||||
await shutdownTelemetry(mockConfig);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe('telemetry', () => {
|
|||
|
||||
it('should shutdown the telemetry service', async () => {
|
||||
initializeTelemetry(mockConfig);
|
||||
await shutdownTelemetry();
|
||||
await shutdownTelemetry(mockConfig);
|
||||
|
||||
expect(mockNodeSdk.shutdown).toHaveBeenCalled();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue