Skip to content

Commit 235c865

Browse files
authored
feat(core): Re-add _experiments.enableLogs option (#18299)
We're re-introducing `_experiments.enableLogs`. The option stays deprecated and maybe we can actually remove it or type it as `undefined` in the next major to sunset it for good. Main motivation for re-adding: The flag was introduced in v9 while we already worked on v10 where we removed it again. Therefore, it had an unusually short lifespan. Some users didn't realize this when upgrading to v10 and were wondering where their logs went.
1 parent 4b92c64 commit 235c865

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

dev-packages/browser-integration-tests/suites/public-api/logger/init.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
7-
enableLogs: true,
7+
// purposefully testing against the experimental flag here
8+
_experiments: {
9+
enableLogs: true,
10+
},
811
});

dev-packages/browser-integration-tests/suites/public-api/logger/integration/init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
77
enableLogs: true,
8+
// Purposefully specifying the experimental flag here
9+
// to ensure the top level option is used instead.
10+
_experiments: {
11+
enableLogs: false,
12+
},
813
integrations: [Sentry.consoleLoggingIntegration()],
914
});

dev-packages/node-core-integration-tests/suites/winston/subject.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ const client = Sentry.init({
88
dsn: 'https://[email protected]/1337',
99
release: '1.0.0',
1010
environment: 'test',
11-
enableLogs: true,
11+
// Purposefully specifying the experimental flag here
12+
// to ensure the top level option is still respected.
13+
_experiments: {
14+
enableLogs: true,
15+
},
1216
transport: loggingTransport,
1317
});
1418

packages/core/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
239239
});
240240
}
241241

242+
// Backfill enableLogs option from _experiments.enableLogs
243+
// TODO(v11): Remove or change default value
244+
// eslint-disable-next-line deprecation/deprecation
245+
this._options.enableLogs = this._options.enableLogs ?? this._options._experiments?.enableLogs;
246+
242247
// Setup log flushing with weight and timeout tracking
243248
if (this._options.enableLogs) {
244249
setupWeightBasedFlushing(this, 'afterCaptureLog', 'flushLogs', estimateLogSizeInBytes, _INTERNAL_flushLogsBuffer);

packages/core/src/types-hoist/options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
306306
* @deprecated Use the top level`beforeSendMetric` option instead.
307307
*/
308308
beforeSendMetric?: (metric: Metric) => Metric | null;
309+
310+
/**
311+
* Determines if logs support should be enabled.
312+
*
313+
* @default false
314+
* @deprecated Use the top level `enableLogs` option instead.
315+
*/
316+
enableLogs?: boolean;
309317
};
310318

311319
/**

packages/core/test/lib/client.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,36 @@ describe('Client', () => {
27342734
});
27352735
});
27362736

2737+
describe('enableLogs', () => {
2738+
it('defaults to `undefined`', () => {
2739+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
2740+
const client = new TestClient(options);
2741+
expect(client.getOptions().enableLogs).toBeUndefined();
2742+
});
2743+
2744+
it('can be set as a top-level option', () => {
2745+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: true });
2746+
const client = new TestClient(options);
2747+
expect(client.getOptions().enableLogs).toBe(true);
2748+
});
2749+
2750+
it('can be set as an experimental option', () => {
2751+
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableLogs: true } });
2752+
const client = new TestClient(options);
2753+
expect(client.getOptions().enableLogs).toBe(true);
2754+
});
2755+
2756+
test('top-level option takes precedence over experimental option', () => {
2757+
const options = getDefaultTestClientOptions({
2758+
dsn: PUBLIC_DSN,
2759+
enableLogs: true,
2760+
_experiments: { enableLogs: false },
2761+
});
2762+
const client = new TestClient(options);
2763+
expect(client.getOptions().enableLogs).toBe(true);
2764+
});
2765+
});
2766+
27372767
describe('log weight-based flushing', () => {
27382768
beforeEach(() => {
27392769
vi.useFakeTimers();

0 commit comments

Comments
 (0)