From 9e01f3efccf59b13c492870c8823a625175ce0a3 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 21 May 2025 12:36:37 +0100 Subject: [PATCH 1/2] feat(core): Allow re-use of `_INTERNAL_captureLog` --- packages/core/src/logs/exports.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/core/src/logs/exports.ts b/packages/core/src/logs/exports.ts index a2451c6cc6c0..70882ac22493 100644 --- a/packages/core/src/logs/exports.ts +++ b/packages/core/src/logs/exports.ts @@ -61,12 +61,28 @@ export function logAttributeToSerializedLogAttribute(value: unknown): Serialized } } +function defaultCaptureSerializedLog( + client: Client, + serializedLog: SerializedLog, +): void { + const logBuffer = _INTERNAL_getLogBuffer(client); + if (logBuffer === undefined) { + GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [serializedLog]); + } else { + GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [...logBuffer, serializedLog]); + if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) { + _INTERNAL_flushLogsBuffer(client, logBuffer); + } + } +} + /** * Captures a log event and sends it to Sentry. * * @param log - The log event to capture. * @param scope - A scope. Uses the current scope if not provided. * @param client - A client. Uses the current client if not provided. + * @param captureSerializedLog - A function to capture the serialized log. * * @experimental This method will experience breaking changes. This is not yet part of * the stable Sentry SDK API and can be changed or removed without warning. @@ -75,6 +91,7 @@ export function _INTERNAL_captureLog( beforeLog: Log, client: Client | undefined = getClient(), scope = getCurrentScope(), + captureSerializedLog: (client: Client, log: SerializedLog) => void = defaultCaptureSerializedLog, ): void { if (!client) { DEBUG_BUILD && logger.warn('No client available to capture log.'); @@ -151,15 +168,7 @@ export function _INTERNAL_captureLog( ), }; - const logBuffer = _INTERNAL_getLogBuffer(client); - if (logBuffer === undefined) { - GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [serializedLog]); - } else { - GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [...logBuffer, serializedLog]); - if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) { - _INTERNAL_flushLogsBuffer(client, logBuffer); - } - } + captureSerializedLog(client, serializedLog); client.emit('afterCaptureLog', log); } From 5c1a30404f2556a6e4159b522ef46b052807b9f9 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 21 May 2025 12:47:06 +0100 Subject: [PATCH 2/2] lint --- packages/core/src/logs/exports.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/src/logs/exports.ts b/packages/core/src/logs/exports.ts index 70882ac22493..41f1155ee3e1 100644 --- a/packages/core/src/logs/exports.ts +++ b/packages/core/src/logs/exports.ts @@ -61,10 +61,7 @@ export function logAttributeToSerializedLogAttribute(value: unknown): Serialized } } -function defaultCaptureSerializedLog( - client: Client, - serializedLog: SerializedLog, -): void { +function defaultCaptureSerializedLog(client: Client, serializedLog: SerializedLog): void { const logBuffer = _INTERNAL_getLogBuffer(client); if (logBuffer === undefined) { GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [serializedLog]);