diff --git a/dev-packages/browser-integration-tests/suites/public-api/logger/init.js b/dev-packages/browser-integration-tests/suites/public-api/logger/init.js index 8026df91ea46..1fa010f49659 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/logger/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/logger/init.js @@ -4,5 +4,8 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - enableLogs: true, + // purposefully testing against the experimental flag here + _experiments: { + enableLogs: true, + }, }); diff --git a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/init.js b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/init.js index 809b78739e77..e26b03d7fc61 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/logger/integration/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/logger/integration/init.js @@ -5,5 +5,10 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', enableLogs: true, + // Purposefully specifying the experimental flag here + // to ensure the top level option is used instead. + _experiments: { + enableLogs: false, + }, integrations: [Sentry.consoleLoggingIntegration()], }); diff --git a/dev-packages/node-core-integration-tests/suites/winston/subject.ts b/dev-packages/node-core-integration-tests/suites/winston/subject.ts index 3c31ddb63fa5..02ffcdb0f5cb 100644 --- a/dev-packages/node-core-integration-tests/suites/winston/subject.ts +++ b/dev-packages/node-core-integration-tests/suites/winston/subject.ts @@ -8,7 +8,11 @@ const client = Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', release: '1.0.0', environment: 'test', - enableLogs: true, + // Purposefully specifying the experimental flag here + // to ensure the top level option is still respected. + _experiments: { + enableLogs: true, + }, transport: loggingTransport, }); diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index b7e0cab509c1..cdeff3df4615 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -239,6 +239,11 @@ export abstract class Client { }); } + // Backfill enableLogs option from _experiments.enableLogs + // TODO(v11): Remove or change default value + // eslint-disable-next-line deprecation/deprecation + this._options.enableLogs = this._options.enableLogs ?? this._options._experiments?.enableLogs; + // Setup log flushing with weight and timeout tracking if (this._options.enableLogs) { setupWeightBasedFlushing(this, 'afterCaptureLog', 'flushLogs', estimateLogSizeInBytes, _INTERNAL_flushLogsBuffer); diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index 59c4609f01c4..c33d0107df5f 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -306,6 +306,14 @@ export interface ClientOptions Metric | null; + + /** + * Determines if logs support should be enabled. + * + * @default false + * @deprecated Use the top level `enableLogs` option instead. + */ + enableLogs?: boolean; }; /** diff --git a/packages/core/test/lib/client.test.ts b/packages/core/test/lib/client.test.ts index 19ef8a95dff5..0a915a0aacde 100644 --- a/packages/core/test/lib/client.test.ts +++ b/packages/core/test/lib/client.test.ts @@ -2706,6 +2706,36 @@ describe('Client', () => { }); }); + describe('enableLogs', () => { + it('defaults to `undefined`', () => { + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); + const client = new TestClient(options); + expect(client.getOptions().enableLogs).toBeUndefined(); + }); + + it('can be set as a top-level option', () => { + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: true }); + const client = new TestClient(options); + expect(client.getOptions().enableLogs).toBe(true); + }); + + it('can be set as an experimental option', () => { + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableLogs: true } }); + const client = new TestClient(options); + expect(client.getOptions().enableLogs).toBe(true); + }); + + test('top-level option takes precedence over experimental option', () => { + const options = getDefaultTestClientOptions({ + dsn: PUBLIC_DSN, + enableLogs: true, + _experiments: { enableLogs: false }, + }); + const client = new TestClient(options); + expect(client.getOptions().enableLogs).toBe(true); + }); + }); + describe('log weight-based flushing', () => { beforeEach(() => { vi.useFakeTimers();