1 | // Copyright (c) 2015 Uber Technologies, Inc.
|
2 | //
|
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy
|
4 | // of this software and associated documentation files (the "Software"), to deal
|
5 | // in the Software without restriction, including without limitation the rights
|
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7 | // copies of the Software, and to permit persons to whom the Software is
|
8 | // furnished to do so, subject to the following conditions:
|
9 | //
|
10 | // The above copyright notice and this permission notice shall be included in
|
11 | // all copies or substantial portions of the Software.
|
12 | //
|
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19 | // THE SOFTWARE.
|
20 |
|
21 | var test = require('tape');
|
22 | var http = require('http');
|
23 | var zlib = require('zlib');
|
24 | var body = require('body');
|
25 |
|
26 | var Logger = require('../logger.js');
|
27 | var SentryBackend = require('../backends/sentry.js');
|
28 |
|
29 | test('sentry logging', function (assert) {
|
30 | var PORT = 20000 + Math.round(Math.random() * 10000);
|
31 | var dsn = 'http://public:private@localhost:' + PORT + '/269';
|
32 |
|
33 | var server = http.createServer(function (req, res) {
|
34 | body(req, res, function (err, body) {
|
35 | assert.equal(req.method, 'POST');
|
36 | assert.equal(req.url, '/api/269/store/');
|
37 | assert.ok(req.headers['x-sentry-auth']);
|
38 | assert.ok(body.length > 0);
|
39 |
|
40 | var buf = new Buffer(body, 'base64');
|
41 | zlib.inflate(buf, function (err, str) {
|
42 | var json = JSON.parse(String(str));
|
43 |
|
44 | assert.equal(json.message, 'sentry.js: oh hi');
|
45 | server.close();
|
46 | res.end();
|
47 | assert.end();
|
48 | });
|
49 | });
|
50 | });
|
51 | server.listen(PORT);
|
52 |
|
53 | var logger = Logger({
|
54 | backends: {
|
55 | sentry: SentryBackend({ dsn: dsn })
|
56 | },
|
57 | meta: {}
|
58 | });
|
59 |
|
60 | assert.ok(logger);
|
61 |
|
62 | logger.error('oh hi');
|
63 | });
|