10000 feat(core): Allow re-use of `captureLog` (#16352) · getsentry/sentry-javascript@3604a08 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3604a08

Browse files
timfishAbhiPrasad
andauthored
feat(core): Allow re-use of captureLog (#16352)
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
1 parent 952373e commit 3604a08

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/core/src/logs/exports.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,25 @@ export function logAttributeToSerializedLogAttribute(value: unknown): Serialized
6161
}
6262
}
6363

64+
function defaultCaptureSerializedLog(client: Client, serializedLog: SerializedLog): void {
65+
const logBuffer = _INTERNAL_getLogBuffer(client);
66+
if (logBuffer === undefined) {
67+
GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [serializedLog]);
68+
} else {
69+
GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [...logBuffer, serializedLog]);
70+
if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) {
71+
_INTERNAL_flushLogsBuffer(client, logBuffer);
72+
}
73+
}
74+
}
75+
6476
/**
6577
* Captures a log event and sends it to Sentry.
6678
*
6779
* @param log - The log event to capture.
6880
* @param scope - A scope. Uses the current scope if not provided.
6981
* @param client - A client. Uses the current client if not provided.
82+
* @param captureSerializedLog - A function to capture the serialized log.
7083
*
7184
* @experimental This method will experience breaking changes. This is not yet part of
7285
* the stable Sentry SDK API and can be changed or removed without warning.
@@ -75,6 +88,7 @@ export function _INTERNAL_captureLog(
7588
beforeLog: Log,
7689
client: Client | undefined = getClient(),
7790
scope = getCurrentScope(),
91+
captureSerializedLog: (client: Client, log: SerializedLog) => void = defaultCaptureSerializedLog,
7892
): void {
7993
if (!client) {
8094
DEBUG_BUILD && logger.warn('No client available to capture log.');
@@ -151,15 +165,7 @@ export function _INTERNAL_captureLog(
151165
),
152166
};
153167

154-
const logBuffer = _INTERNAL_getLogBuffer(client);
155-
if (logBuffer === undefined) {
156-
GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [serializedLog]);
157-
} else {
158-
GLOBAL_OBJ._sentryClientToLogBufferMap?.set(client, [...logBuffer, serializedLog]);
159-
if (logBuffer.length >= MAX_LOG_BUFFER_SIZE) {
160-
_INTERNAL_flushLogsBuffer(client, logBuffer);
161-
}
162-
}
168+
captureSerializedLog(client, serializedLog);
163169

164170
client.emit('afterCaptureLog', log);
165171
}

0 commit comments

Comments
 (0)
0