Skip to content

Commit

Permalink
Adding performance tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpropst committed Nov 17, 2020
1 parent dd9f748 commit 37dc0ba
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 48 deletions.
25 changes: 23 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ var app = express();

// Initalize Sentry (import library and instantiate)
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://[email protected]/1366275'});
const Tracing = require('@sentry/tracing');

Sentry.init({
dsn: 'https://[email protected]/1366275',
integrations: [
// Enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// Enable Express.js middleware tracing
new Tracing.Integrations.Express({ app }),
],

// Sample rate can be set as a decimal between 0 and 1
// representing the percent of transactions to record
//
// For our example, we will collect all transactions
tracesSampleRate: 1.0,
});

let Inventory = {
wrench: 0,
Expand All @@ -30,6 +46,8 @@ let checkout = (cart) => {

// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());

app.use(bodyParser.json());
app.use(cors());
Expand Down Expand Up @@ -69,8 +87,11 @@ app.post('/checkout', function (req, res) {
});

app.get('/capture-message', function (req, res) {
// Simulate an API call that takes a random amount
// of time and goes long
let delay = 2500;
Sentry.captureMessage('Custom Message');
res.send('Success');
setTimeout(() => { res.send('Success'); }, delay);
});

app.get('/unhandled', function (req, res) {
Expand Down
119 changes: 74 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "t-em-backend",
"version": "1.0.0",
"dependencies": {
"@sentry/node": "^5.2",
"@sentry/cli": "^1.37.0",
"@sentry/node": "^5.27.4",
"@sentry/tracing": "^5.27.4",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1"
Expand Down

0 comments on commit 37dc0ba

Please sign in to comment.