Skip to content

Commit 7d89809

Browse files
committed
fix: add error handling to telemetry event logging by catching and logging promise rejections.
1 parent 1367e2c commit 7d89809

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

packages/core/src/telemetry/loggers.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import { bufferTelemetryEvent } from './sdk.js';
8181
import type { UiEvent } from './uiTelemetry.js';
8282
import { uiTelemetryService } from './uiTelemetry.js';
8383
import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js';
84+
import { debugLogger } from '../utils/debugLogger.js';
8485

8586
export function logCliConfiguration(
8687
config: Config,
@@ -89,15 +90,19 @@ export function logCliConfiguration(
8990
void ClearcutLogger.getInstance(config)?.logStartSessionEvent(event);
9091
bufferTelemetryEvent(() => {
9192
// Wait for experiments to load before emitting so we capture experimentIds
92-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
93-
config.getExperimentsAsync().then(() => {
94-
const logger = logs.getLogger(SERVICE_NAME);
95-
const logRecord: LogRecord = {
96-
body: event.toLogBody(),
97-
attributes: event.toOpenTelemetryAttributes(config),
98-
};
99-
logger.emit(logRecord);
100-
});
93+
void config
94+
.getExperimentsAsync()
95+
.then(() => {
96+
const logger = logs.getLogger(SERVICE_NAME);
97+
const logRecord: LogRecord = {
98+
body: event.toLogBody(),
99+
attributes: event.toOpenTelemetryAttributes(config),
100+
};
101+
logger.emit(logRecord);
102+
})
103+
.catch((e: unknown) => {
104+
debugLogger.error('Failed to log telemetry event', e);
105+
});
101106
});
102107
}
103108

@@ -785,14 +790,18 @@ export function logStartupStats(
785790
): void {
786791
bufferTelemetryEvent(() => {
787792
// Wait for experiments to load before emitting so we capture experimentIds
788-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
789-
config.getExperimentsAsync().then(() => {
790-
const logger = logs.getLogger(SERVICE_NAME);
791-
const logRecord: LogRecord = {
792-
body: event.toLogBody(),
793-
attributes: event.toOpenTelemetryAttributes(config),
794-
};
795-
logger.emit(logRecord);
796-
});
793+
void config
794+
.getExperimentsAsync()
795+
.then(() => {
796+
const logger = logs.getLogger(SERVICE_NAME);
797+
const logRecord: LogRecord = {
798+
body: event.toLogBody(),
799+
attributes: event.toOpenTelemetryAttributes(config),
800+
};
801+
logger.emit(logRecord);
802+
})
803+
.catch((e: unknown) => {
804+
debugLogger.error('Failed to log telemetry event', e);
805+
});
797806
});
798807
}

0 commit comments

Comments
 (0)