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