From a577c4f7b05c788d82be13f64a769b396661a3e5 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 7 Apr 2025 15:58:31 +0200 Subject: [PATCH 1/3] feat(core): Add sentry origin attribute to console logs integration --- packages/core/src/logs/console-integration.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/src/logs/console-integration.ts b/packages/core/src/logs/console-integration.ts index 6dbb829db5a6..d0fe2a639738 100644 --- a/packages/core/src/logs/console-integration.ts +++ b/packages/core/src/logs/console-integration.ts @@ -1,6 +1,7 @@ import { getClient } from '../currentScopes'; import { DEBUG_BUILD } from '../debug-build'; import { defineIntegration } from '../integration'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes'; import type { ConsoleLevel, IntegrationFn } from '../types-hoist'; import { CONSOLE_LEVELS, GLOBAL_OBJ, addConsoleInstrumentationHandler, logger, safeJoin } from '../utils-hoist'; import { _INTERNAL_captureLog } from './exports'; @@ -17,6 +18,10 @@ type GlobalObjectWithUtil = typeof GLOBAL_OBJ & { const INTEGRATION_NAME = 'ConsoleLogs'; +const DEFAULT_ATTRIBUTES = { + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.console.logging', +}; + const _consoleLoggingIntegration = ((options: Partial = {}) => { const levels = options.levels || CONSOLE_LEVELS; @@ -38,7 +43,7 @@ const _consoleLoggingIntegration = ((options: Partial = { const followingArgs = args.slice(1); const message = followingArgs.length > 0 ? `Assertion failed: ${formatConsoleArgs(followingArgs)}` : 'Assertion failed'; - _INTERNAL_captureLog({ level: 'error', message }); + _INTERNAL_captureLog({ level: 'error', message, attributes: DEFAULT_ATTRIBUTES }); } return; } @@ -48,6 +53,7 @@ const _consoleLoggingIntegration = ((options: Partial = { level: isLevelLog ? 'info' : level, message: formatConsoleArgs(args), severityNumber: isLevelLog ? 10 : undefined, + attributes: DEFAULT_ATTRIBUTES, }); }); }, From 9b15302b4e6d04ad9a8b7ce0d6ac22821d667d45 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 7 Apr 2025 16:49:18 +0200 Subject: [PATCH 2/3] fix tests --- .../public-api/logger/integration/test.ts | 72 +++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts index 00e918ce9719..f6146eba48cf 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts +++ b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts @@ -16,6 +16,15 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page const event = await getFirstSentryEnvelopeRequest(page, url, properFullEnvelopeRequestParser); const envelopeItems = event[1]; + // - "attributes": Array [], + // + "attributes": Array [ + // + Object { + // + "key": "sentry.origin", + // + "value": Object { + // + "stringValue": "auto.console.logging", + // + }, + // + }, + // + ], expect(envelopeItems[0]).toEqual([ { type: 'otel_log', @@ -23,7 +32,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'trace', body: { stringValue: 'console.trace 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 1, @@ -37,7 +53,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'debug', body: { stringValue: 'console.debug 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 5, @@ -51,7 +74,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'info', body: { stringValue: 'console.log 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 10, @@ -65,7 +95,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'info', body: { stringValue: 'console.info 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 9, @@ -79,7 +116,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'warn', body: { stringValue: 'console.warn 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 13, @@ -93,7 +137,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'error', body: { stringValue: 'console.error 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 17, @@ -107,7 +158,14 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page { severityText: 'error', body: { stringValue: 'Assertion failed: console.assert 123 false' }, - attributes: [], + attributes: [ + { + key: 'sentry.origin', + value: { + stringValue: 'auto.console.logging', + }, + }, + ], timeUnixNano: expect.any(String), traceId: expect.any(String), severityNumber: 17, From d13262617d5a4f3cd7f27e7a173464a6d11b3c5b Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 7 Apr 2025 16:54:27 +0200 Subject: [PATCH 3/3] remove comment --- .../suites/public-api/logger/integration/test.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts index f6146eba48cf..183c80eb35be 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts +++ b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts @@ -16,15 +16,6 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page const event = await getFirstSentryEnvelopeRequest(page, url, properFullEnvelopeRequestParser); const envelopeItems = event[1]; - // - "attributes": Array [], - // + "attributes": Array [ - // + Object { - // + "key": "sentry.origin", - // + "value": Object { - // + "stringValue": "auto.console.logging", - // + }, - // + }, - // + ], expect(envelopeItems[0]).toEqual([ { type: 'otel_log',