Skip to content

Commit

Permalink
Add datadog metrics for request and latencies per endpoint. (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
godwinpang authored Dec 26, 2020
1 parent 8095ae4 commit 3b4807d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
70 changes: 59 additions & 11 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^7.2.1",
"@types/connect-datadog": "0.0.5",
"body-parser": "^1.19.0",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"class-validator-jsonschema": "^2.0.2",
"compression": "^1.7.4",
"connect-datadog": "0.0.9",
"cors": "^2.8.5",
"date-fns": "^2.16.1",
"express": "^4.17.1",
Expand Down
11 changes: 11 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'module-alias/register'; // required for aliases
import express from 'express';
import rateLimit from 'express-rate-limit';
import compression from 'compression';
import connect_datadog from 'connect-datadog';

import { UserRouter } from './routers/UserRouter';
import { DocsRouter } from './routers/DocsRouter';
Expand All @@ -12,6 +13,7 @@ import { useExpressServer, useContainer as routingUseContainer } from 'routing-c
import { controllers, ControllerContainer } from './controllers';

import { loadFirebase, loadORM } from './loaders';
import { config } from './config';
import morgan from 'morgan';

import { checkCurrentUserToken } from './decorators';
Expand All @@ -31,6 +33,15 @@ export const getExpressApp = async () => {
app.use(express.urlencoded({ extended: true }));
app.use(morgan('tiny'));
app.use(limiter);
if (config.nodeEnv !== 'development') {
app.use(
connect_datadog({
method: true,
response_code: true,
tags: [config.ddMetricTag],
})
);
}

// load controllers; maybe move into loader?

Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type Config = {
clientAppID: string;
clientApiKey: string;
devAuth: boolean;
ddMetricTag: string;
nodeEnv: string;
};

const {
Expand All @@ -20,6 +22,8 @@ const {
FIREBASE_CLIENT_ID,
FIREBASE_CLIENT_API_KEY,
DEV_AUTH,
DD_METRIC_TAG,
NODE_ENV,
} = process.env;

const firebaseConfig: FirebaseConfig = {
Expand All @@ -34,4 +38,6 @@ export const config: Config = {
clientAppID: FIREBASE_CLIENT_ID,
clientApiKey: FIREBASE_CLIENT_API_KEY,
devAuth: DEV_AUTH === 'true',
ddMetricTag: DD_METRIC_TAG,
nodeEnv: NODE_ENV,
};

0 comments on commit 3b4807d

Please sign in to comment.