Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
});
}

// 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);
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/types-hoist/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
* @deprecated Use the top level`beforeSendMetric` option instead.
*/
beforeSendMetric?: (metric: Metric) => Metric | null;

/**
* Determines if logs support should be enabled.
*
* @default false
* @deprecated Use the top level `enableLogs` option instead.
*/
enableLogs?: boolean;
};

/**
Expand Down
30 changes: 30 additions & 0 deletions packages/core/test/lib/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading