Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add integration tests
  • Loading branch information
s1gr1d committed Feb 27, 2026
commit 5e20cdd9b2270ada950f9c54a0fcab1e0e639e9a
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
import { consola } from 'consola';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0.0',
environment: 'test',
enableLogs: true,
transport: loggingTransport,
});

async function run(): Promise<void> {
consola.level = 5;
const sentryReporter = Sentry.createConsolaReporter();
consola.addReporter(sentryReporter);

// Object-first: args = [object, string] — first object becomes attributes, second arg is part of formatted message
consola.info({ userId: 100, action: 'login' }, 'User logged in');

// Object-first: args = [object] only — object keys become attributes, message is stringified object
consola.info({ event: 'click', count: 2 });

await Sentry.flush();
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
void run();
51 changes: 51 additions & 0 deletions dev-packages/node-integration-tests/suites/consola/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,55 @@ describe('consola integration', () => {

await runner.completed();
});

test('should capture object-first consola logs (object as first arg)', async () => {
const runner = createRunner(__dirname, 'subject-object-first.ts')
.expect({
log: {
items: [
{
timestamp: expect.any(Number),
level: 'info',
body: '{"userId":100,"action":"login"} User logged in',
severity_number: expect.any(Number),
trace_id: expect.any(String),
attributes: {
'sentry.origin': { value: 'auto.log.consola', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
'server.address': { value: expect.any(String), type: 'string' },
'consola.type': { value: 'info', type: 'string' },
'consola.level': { value: 3, type: 'integer' },
userId: { value: 100, type: 'integer' },
action: { value: 'login', type: 'string' },
},
},
{
timestamp: expect.any(Number),
level: 'info',
body: '{"event":"click","count":2}',
severity_number: expect.any(Number),
trace_id: expect.any(String),
attributes: {
'sentry.origin': { value: 'auto.log.consola', type: 'string' },
'sentry.release': { value: '1.0.0', type: 'string' },
'sentry.environment': { value: 'test', type: 'string' },
'sentry.sdk.name': { value: 'sentry.javascript.node', type: 'string' },
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
'server.address': { value: expect.any(String), type: 'string' },
'consola.type': { value: 'info', type: 'string' },
'consola.level': { value: 3, type: 'integer' },
event: { value: 'click', type: 'string' },
count: { value: 2, type: 'integer' },
},
},
],
},
})
.start();

await runner.completed();
});
});