Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Feat/5.x.x request metrics #1036

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/integration/__snapshots__/one-app.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports[`Tests that require Docker setup one-app successfully started metrics ha
Array [
"circuit",
"circuit_perf",
"http_request_duration_seconds",
"nodejs_active_handles",
"nodejs_active_handles_total",
"nodejs_active_requests",
Expand Down
38 changes: 38 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"create-shared-react-context": "^1.0.3",
"cross-fetch": "^3.0.6",
"express": "^4.17.1",
"express-prom-bundle": "^6.6.0",
"helmet": "^3.22.0",
"holocron": "^1.7.0",
"holocron-module-route": "^1.2.1",
Expand Down
10 changes: 9 additions & 1 deletion src/server/ssrServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import cookieParser from 'cookie-parser';
import { json, urlencoded } from 'body-parser';
import helmet from 'helmet';
import cors from 'cors';
import promBundle from 'express-prom-bundle';

import conditionallyAllowCors from './middleware/conditionallyAllowCors';
import ensureCorrelationId from './middleware/ensureCorrelationId';
Expand All @@ -52,6 +53,12 @@ import {
} from './middleware/pwa';
import { completeTracer, initializeTracer, traceMiddleware } from './utils/tracer';

const metricsMiddleware = promBundle({
includeMethod: true,
includePath: false,
includeUp: false,
});

export function createApp({ enablePostToModuleRoutes = false } = {}) {
const app = express();

Expand All @@ -61,7 +68,6 @@ export function createApp({ enablePostToModuleRoutes = false } = {}) {
app.get('*', addSecurityHeaders);
app.use(setAppVersionHeader);
app.use(forwardedHeaderParser);

app.use('/_/static', express.static(path.join(__dirname, '../../build'), { maxage: '182d' }));
app.get('/_/status', (req, res) => res.sendStatus(200));
app.get('/_/pwa/service-worker.js', serviceWorkerMiddleware());
Expand All @@ -81,6 +87,8 @@ export function createApp({ enablePostToModuleRoutes = false } = {}) {
app.get('**/*.(json|js|css|map)', (req, res) => res.sendStatus(404));

app.get('/_/pwa/shell', offlineMiddleware(oneApp));
// only register metrics for module routes.
app.use(metricsMiddleware);
app.get(
'*',
initializeTracer,
Expand Down