Skip to content
Open
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 @@ -22,7 +22,6 @@ Sentry.init({
traceLifecycle: 'stream',
tracesSampleRate: 1,
dataCollection: { userInfo: true },
enableLogs: true,
});

const port = 3030;
Expand Down
1 change: 0 additions & 1 deletion dev-packages/e2e-tests/test-applications/deno/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Sentry.init({
tunnel: 'http://localhost:3031/',
tracesSampleRate: 1,
dataCollection: { userInfo: true },
enableLogs: true,
});

const port = 3030;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const AppLayer = Layer.mergeAll(
release: 'e2e-test',
environment: 'qa',
tunnel: 'http://localhost:3031',
enableLogs: true,
}),
Layer.setTracer(Sentry.SentryEffectTracer),
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const SentryLive = Layer.mergeAll(
debug: !!process.env.DEBUG,
tunnel: 'http://localhost:3031/',
tracesSampleRate: 1,
enableLogs: true,
}),
Layer.setTracer(Sentry.SentryEffectTracer),
Logger.replace(Logger.defaultLogger, Sentry.SentryEffectLogger),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const AppLayer = Layer.mergeAll(
release: 'e2e-test',
environment: 'qa',
tunnel: 'http://localhost:3031',
enableLogs: true,
}),
Logger.layer([Sentry.SentryEffectLogger]),
Layer.succeed(Tracer.Tracer, Sentry.SentryEffectTracer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const SentryLive = Layer.mergeAll(
debug: !!process.env.DEBUG,
tunnel: 'http://localhost:3031/',
tracesSampleRate: 1,
enableLogs: true,
}),
Logger.layer([Sentry.SentryEffectLogger]),
Layer.succeed(Tracer.Tracer, Sentry.SentryEffectTracer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Sentry.init({
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
enableLogs: true,
traceLifecycle: 'stream',
integrations: [
Sentry.spanStreamingIntegration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Sentry.init({
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
enableLogs: true,
integrations: [Sentry.nodeRuntimeMetricsIntegration({ collectionIntervalMs: 1_000 })],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Sentry.init({
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
enableLogs: true,
integrations: [
Sentry.nativeNodeFetchIntegration({
headersToSpanAttributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Sentry.init({
// Tracing is completely disabled
// Custom OTEL setup
skipOpenTelemetrySetup: true,
enableLogs: true,
});

// Create and configure NodeTracerProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ Sentry.init({
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
enableLogs: true,
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0.0',
environment: 'test',
enableLogs: true,
transport: loggingTransport,
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
tracesSampleRate: 1.0,
enableLogs: true,
integrations: [Sentry.pinoIntegration({ autoInstrument: false })],
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
tracesSampleRate: 1.0,
enableLogs: true,
integrations: [Sentry.pinoIntegration({ error: { levels: ['error', 'fatal'] } })],
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0.0',
environment: 'test',
enableLogs: true,
transport: loggingTransport,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

const client = new Sentry.NodeClient({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
enableLogs: false,
transport: loggingTransport,
stackParser: Sentry.defaultStackParser,
integrations: [],
});

const scope = new Sentry.Scope();
scope.setClient(client);
client.init();

async function run(): Promise<void> {
Sentry.logger.info('this log should not be captured', {}, { scope });

// Flush the log buffer before the sentinel is captured. If the disable path is
// broken, the leaked log envelope is sent here and arrives before the error,
// failing the ordered `event` expectation. If logs are correctly disabled,
// the buffer is empty and only the sentinel error is delivered.
await client.flush();

scope.captureException(new Error('sentinel_error'));

await client.flush();
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
void run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { afterAll, describe, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

describe('logs disabled', () => {
afterAll(() => {
cleanupChildProcesses();
});

// With `enableLogs: false` the log is dropped at capture time, so it never reaches
// the transport. The sentinel error is the only envelope we expect — if a log
// envelope were emitted, it would arrive before the error and fail the assertion.
test('does not capture logs when enableLogs is disabled', async () => {
const runner = createRunner(__dirname, 'subject.ts')
.expect({
event: {
exception: {
values: [
{
type: 'Error',
value: 'sentinel_error',
},
],
},
},
})
.start();

await runner.completed();
});
Comment thread
cursor[bot] marked this conversation as resolved.
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const client = new Sentry.NodeClient({
transport: loggingTransport,
stackParser: Sentry.defaultStackParser,
integrations: [],
enableLogs: true,
dataCollection: { userInfo: true },
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0.0',
environment: 'test',
enableLogs: true,
transport: loggingTransport,
debug: true,
});
4 changes: 2 additions & 2 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
}

// Backfill enableLogs option from _experiments.enableLogs
// TODO(v11): Remove or change default value
// todo(v11): Remove the experimental flag
// eslint-disable-next-line typescript/no-deprecated
this._options.enableLogs = this._options.enableLogs ?? this._options._experiments?.enableLogs;
this._options.enableLogs = this._options.enableLogs ?? this._options._experiments?.enableLogs ?? true;

// Setup log flushing with weight and timeout tracking
if (this._options.enableLogs) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/logs/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function _INTERNAL_captureLog(
return;
}

const { release, environment, enableLogs = false, beforeSendLog } = client.getOptions();
const { release, environment, enableLogs = true, beforeSendLog } = client.getOptions();
if (!enableLogs) {
DEBUG_BUILD && debug.warn('logging option not enabled, log will not be captured.');
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
/**
* If logs support should be enabled.
*
* @default false
* @default true
*/
enableLogs?: boolean;

Expand Down
38 changes: 15 additions & 23 deletions packages/core/test/lib/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('Client', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, test: true });
const client = new TestClient(options);

expect(client.getOptions()).toEqual({ attachStacktrace: true, ...options });
expect(client.getOptions()).toEqual({ attachStacktrace: true, ...options, enableLogs: true });
});
});

Expand Down Expand Up @@ -2242,7 +2242,7 @@ describe('Client', () => {
.spyOn(logsInternalModule, '_INTERNAL_flushLogsBuffer')
.mockImplementation(() => undefined);

const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: true });
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
const client = new TestClient(options);

await client.close();
Expand Down Expand Up @@ -2924,32 +2924,32 @@ describe('Client', () => {
});

describe('enableLogs', () => {
it('defaults to `undefined`', () => {
it('defaults to `true`', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
const client = new TestClient(options);
expect(client.getOptions().enableLogs).toBeUndefined();
expect(client.getOptions().enableLogs).toBe(true);
});

it('can be set as a top-level option', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: true });
it('can be disabled via the top-level option', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableLogs: false });
const client = new TestClient(options);
expect(client.getOptions().enableLogs).toBe(true);
expect(client.getOptions().enableLogs).toBe(false);
});

it('can be set as an experimental option', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableLogs: true } });
it('can be disabled via the experimental option', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableLogs: false } });
const client = new TestClient(options);
expect(client.getOptions().enableLogs).toBe(true);
expect(client.getOptions().enableLogs).toBe(false);
});

test('top-level option takes precedence over experimental option', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
_experiments: { enableLogs: false },
enableLogs: false,
_experiments: { enableLogs: true },
});
const client = new TestClient(options);
expect(client.getOptions().enableLogs).toBe(true);
expect(client.getOptions().enableLogs).toBe(false);
});
});

Expand All @@ -2965,7 +2965,6 @@ describe('Client', () => {
it('flushes logs when weight exceeds 800KB', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -2983,7 +2982,6 @@ describe('Client', () => {
it('accumulates log weight without flushing when under threshold', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3001,7 +2999,6 @@ describe('Client', () => {
it('flushes logs after idle timeout', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3023,7 +3020,6 @@ describe('Client', () => {
it('does not reset idle timeout when new logs are captured', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3050,7 +3046,6 @@ describe('Client', () => {
it('starts new timer after timeout completes and flushes', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand Down Expand Up @@ -3082,7 +3077,6 @@ describe('Client', () => {
it('flushes logs on flush event', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3103,6 +3097,7 @@ describe('Client', () => {
it('does not flush logs when logs are disabled', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: false,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3122,7 +3117,6 @@ describe('Client', () => {

const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
enableLogs: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand All @@ -3140,9 +3134,7 @@ describe('Client', () => {

it('flush() drains the log buffer when client has no transport', async () => {
// Client without DSN — _transport is undefined
const options = getDefaultTestClientOptions({
enableLogs: true,
});
const options = getDefaultTestClientOptions({});
const client = new TestClient(options);
const scope = new Scope();
scope.setClient(client);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/test/lib/integrations/consola.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ describe('createConsolaReporter', () => {
beforeEach(() => {
vi.clearAllMocks();

// Create a test client with enableLogs: true
mockClient = new TestClient({
...getDefaultTestClientOptions({ dsn: 'https://username@domain/123' }),
enableLogs: true,
normalizeDepth: 3,
normalizeMaxBreadth: 1000,
});
Expand Down
2 changes: 0 additions & 2 deletions packages/core/test/lib/logs/console-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('consoleLoggingIntegration', () => {

client = new TestClient({
...getDefaultTestClientOptions({ dsn: 'https://username@domain/123' }),
enableLogs: true,
normalizeDepth: 3,
normalizeMaxBreadth: 1000,
});
Expand Down Expand Up @@ -418,7 +417,6 @@ describe('consoleLoggingIntegration', () => {
it('only captures configured levels', () => {
const filteredClient = new TestClient({
...getDefaultTestClientOptions({ dsn: 'https://username@domain/123' }),
enableLogs: true,
});
vi.mocked(getClient).mockReturnValue(filteredClient);

Expand Down
Loading
Loading