Skip to content

Commit 499b79a

Browse files
authored
fix(core): Only set template attributes on logs if parameters exist (#17480)
resolves #17479
1 parent ff09016 commit 499b79a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/core/src/logs/exports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export function _INTERNAL_captureLog(
153153
const beforeLogMessage = beforeLog.message;
154154
if (isParameterizedString(beforeLogMessage)) {
155155
const { __sentry_template_string__, __sentry_template_values__ = [] } = beforeLogMessage;
156-
processedLogAttributes['sentry.message.template'] = __sentry_template_string__;
156+
if (__sentry_template_values__?.length) {
157+
processedLogAttributes['sentry.message.template'] = __sentry_template_string__;
158+
}
157159
__sentry_template_values__.forEach((param, index) => {
158160
processedLogAttributes[`sentry.message.parameter.${index}`] = param;
159161
});

packages/core/test/lib/logs/exports.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ describe('_INTERNAL_captureLog', () => {
281281
});
282282
});
283283

284+
it('does not set the template attribute if there are no parameters', () => {
285+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: true });
286+
const client = new TestClient(options);
287+
288+
_INTERNAL_captureLog({ level: 'debug', message: fmt`User logged in` }, client, undefined);
289+
290+
const logAttributes = _INTERNAL_getLogBuffer(client)?.[0]?.attributes;
291+
expect(logAttributes).toEqual({});
292+
});
293+
284294
it('processes logs through beforeSendLog when provided', () => {
285295
const beforeSendLog = vi.fn().mockImplementation(log => ({
286296
...log,

0 commit comments

Comments
 (0)