UNPKG

1.31 kBPlain TextView Raw
1#!/usr/bin/env node
2
3var os = require('os');
4var raven = require('../');
5
6function usage() {
7 var path = require('path');
8 console.log('usage:', path.basename(process.argv[1]), 'test [SENTRY_DSN]');
9}
10
11if (process.argv[2] !== 'test') {
12 usage();
13 process.exit(1);
14}
15
16var dsn = process.argv.slice(3).join(' ') || process.env.SENTRY_DSN;
17if (!dsn) {
18 usage();
19 console.log();
20 console.log('Error: No configuration detected!');
21 console.log('You must either pass a DSN to the command or set the SENTRY_DSN environment variable.');
22 process.exit(1);
23}
24
25console.log('Using DSN configuration:');
26console.log(' ', dsn);
27console.log();
28
29var client = new raven.Client(dsn);
30
31console.log('Sending a test message...');
32
33client.on('logged', function(result) {
34 console.log('success!');
35 console.log('Event ID was', client.getIdent(result));
36});
37client.on('error', function(err) {
38 console.log('error!');
39 throw err;
40});
41
42try {
43 test
44} catch (ex) {
45 client.captureException(ex, {
46 message: 'This is a test message generated using ``raven test``',
47 level: 'info',
48 logger: 'sentry.test',
49 transaction: 'bin:raven at main',
50 request: {
51 method: 'GET',
52 url: 'http://example.com'
53 },
54 extra: {
55 user: process.getuid && process.getuid(),
56 loadavg: os.loadavg()
57 }
58 });
59}