Skip to content

Commit e94d78f

Browse files
fix: logging adjustments
1 parent d8b613e commit e94d78f

File tree

4 files changed

+143
-221
lines changed

4 files changed

+143
-221
lines changed

app.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
11
const logger = require('./logger').logger;
22

3-
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
4-
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
5-
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
6-
const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-express');
7-
8-
const provider = new NodeTracerProvider();
9-
// const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
10-
// const { ConsoleSpanExporter } = require('@opentelemetry/tracing');
11-
// provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
12-
provider.register();
13-
14-
let expressInstrumentation = new ExpressInstrumentation();
15-
expressInstrumentation.setTracerProvider(provider);
16-
17-
registerInstrumentations({
18-
instrumentations: [
19-
// Express instrumentation expects HTTP layer to be instrumented
20-
new HttpInstrumentation({
21-
ignoreIncomingRequestHook: (req) => {
22-
return req.connection.localPort === 6060; // ignore incoming requests to prometheus
23-
},
24-
ignoreOutgoingRequestHook: (req) => {
25-
return ![ // we care about performance of outgoing requests to those hosts only
26-
'www.webpagetest.org',
27-
'api.cloudinary.com'
28-
].includes(req.hostname);
29-
},
30-
}),
31-
expressInstrumentation,
32-
],
33-
});
34-
353
const express = require('express');
364
const app = express();
375

@@ -55,7 +23,7 @@ const wpt = require('./routes/wpt');
5523
wpt(app);
5624

5725
// catch 404 and forward to error handler
58-
app.all('*any', function (req, res) {
26+
app.all('*', function (req, res) {
5927
res.status(404).send('what???');
6028
});
6129

instrumentation.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const opentelemetry = require('@opentelemetry/sdk-node');
22
const {Resource} = require('@opentelemetry/resources');
3+
const {registerInstrumentations} = require('@opentelemetry/instrumentation');
4+
const {HttpInstrumentation} = require('@opentelemetry/instrumentation-http');
5+
const {ExpressInstrumentation} = require('@opentelemetry/instrumentation-express');
6+
const {PrometheusExporter} = require('@opentelemetry/exporter-prometheus');
7+
38
const {
49
ATTR_SERVICE_NAME,
510
ATTR_SERVICE_VERSION
611
} = require('@opentelemetry/semantic-conventions');
7-
const {PrometheusExporter} = require('@opentelemetry/exporter-prometheus');
12+
813
const sdk = new opentelemetry.NodeSDK({
914
resource: new Resource({
1015
[ATTR_SERVICE_NAME]: 'web-speed-test-server',
@@ -15,3 +20,21 @@ const sdk = new opentelemetry.NodeSDK({
1520
}),
1621
});
1722
sdk.start();
23+
24+
registerInstrumentations({
25+
instrumentations: [
26+
// Express instrumentation expects HTTP layer to be instrumented
27+
new HttpInstrumentation({
28+
ignoreIncomingRequestHook: (req) => {
29+
return req.connection.localPort === 6060; // ignore incoming requests to prometheus
30+
},
31+
ignoreOutgoingRequestHook: (req) => {
32+
return ![ // we care about performance of outgoing requests to those hosts only
33+
'www.webpagetest.org',
34+
'api.cloudinary.com'
35+
].includes(req.hostname);
36+
},
37+
}),
38+
new ExpressInstrumentation()
39+
],
40+
});

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"private": true,
55
"scripts": {
66
"test": "mocha",
7-
"start": "node start.js",
8-
"start-with-instrumentation": "node --require ./instrumentation.js start.js",
7+
"start": "node --require ./instrumentation.js start.js",
98
"postinstall": "patch-package"
109
},
1110
"dependencies": {
@@ -25,7 +24,7 @@
2524
"cookie-parser": "~1.4.7",
2625
"debug": "~4.4.0",
2726
"dotenv": "^16.4.7",
28-
"express": "^5.0.1",
27+
"express": "^4.21.2",
2928
"got": "^14.4.5",
3029
"lodash": "^4.17.21",
3130
"rollbar": "^2.26.4",

0 commit comments

Comments
 (0)