|
| 1 | +const http = require('http'); |
| 2 | +const express = require('express'); |
| 3 | +const app = express(); |
| 4 | +const Sentry = require('../../dist'); |
| 5 | + |
| 6 | +function assertTags(actual, expected) { |
| 7 | + if (JSON.stringify(actual) !== JSON.stringify(expected)) { |
| 8 | + console.error('FAILED: Scope contains incorrect tags'); |
| 9 | + process.exit(1); |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +let remaining = 3; |
| 14 | + |
| 15 | +class DummyTransport { |
| 16 | + captureEvent(event) { |
| 17 | + --remaining; |
| 18 | + |
| 19 | + if (!remaining) { |
| 20 | + console.error('SUCCESS: All scopes contain correct tags'); |
| 21 | + process.exit(0); |
| 22 | + } |
| 23 | + |
| 24 | + return Promise.resolve({ |
| 25 | + status: 'success', |
| 26 | + }); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +Sentry.init({ |
| 31 | + dsn: 'http://[email protected]/1337', |
| 32 | + transport: DummyTransport, |
| 33 | + beforeSend(event) { |
| 34 | + if (event.message === 'Error: foo') { |
| 35 | + assertTags(event.tags, { |
| 36 | + global: 'wat', |
| 37 | + foo: 'wat', |
| 38 | + }); |
| 39 | + } else if (event.message === 'Error: bar') { |
| 40 | + assertTags(event.tags, { |
| 41 | + global: 'wat', |
| 42 | + bar: 'wat', |
| 43 | + }); |
| 44 | + } else if (event.message === 'Error: baz') { |
| 45 | + assertTags(event.tags, { |
| 46 | + global: 'wat', |
| 47 | + baz: 'wat', |
| 48 | + }); |
| 49 | + } |
| 50 | + return event; |
| 51 | + }, |
| 52 | +}); |
| 53 | + |
| 54 | +Sentry.configureScope(scope => { |
| 55 | + scope.setTag('global', 'wat'); |
| 56 | +}); |
| 57 | + |
| 58 | +app.use(Sentry.Handlers.requestHandler()); |
| 59 | + |
| 60 | +app.get('/foo', req => { |
| 61 | + Sentry.configureScope(scope => { |
| 62 | + scope.setTag('foo', 'wat'); |
| 63 | + }); |
| 64 | + |
| 65 | + throw new Error('foo'); |
| 66 | +}); |
| 67 | + |
| 68 | +app.get('/bar', req => { |
| 69 | + Sentry.configureScope(scope => { |
| 70 | + scope.setTag('bar', 'wat'); |
| 71 | + }); |
| 72 | + |
| 73 | + throw new Error('bar'); |
| 74 | +}); |
| 75 | + |
| 76 | +app.get('/baz', req => { |
| 77 | + Sentry.configureScope(scope => { |
| 78 | + scope.setTag('baz', 'wat'); |
| 79 | + }); |
| 80 | + |
| 81 | + throw new Error('baz'); |
| 82 | +}); |
| 83 | + |
| 84 | +app.use(Sentry.Handlers.errorHandler()); |
| 85 | + |
| 86 | +app.listen(3000); |
| 87 | + |
| 88 | +http.get('http://localhost:3000/foo'); |
| 89 | +http.get('http://localhost:3000/bar'); |
| 90 | +http.get('http://localhost:3000/baz'); |
0 commit comments