Skip to content

Commit e79bfe7

Browse files
committed
Refactor tracing initialization
1 parent 976335e commit e79bfe7

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

src/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import http from 'http';
22
import { createTerminus } from '@godaddy/terminus';
3-
import app from './app';
43
import config from './config';
54
import logger from './logger';
65
import services from './services';
76

8-
const server = http.createServer(app);
9-
107
async function onSignal(): Promise<void> {
118
logger.warn('Server is going to shut down! Starting cleanup...');
129
}
@@ -19,26 +16,28 @@ async function onHealthCheck(): Promise<void> {
1916
return;
2017
}
2118

22-
createTerminus(server, {
23-
healthChecks: {
24-
'/health/liveness': onHealthCheck,
25-
},
26-
onSignal,
27-
onShutdown,
28-
});
29-
3019
async function start(): Promise<void> {
3120
try {
32-
console.log('Main.start();');
3321
const namespace = config.services.trace.daemonAddressNamespace;
3422
const name = config.services.trace.daemonAddressName;
3523
if (typeof namespace === 'string' && typeof name === 'string') {
3624
const address = await services.ServiceDiscovery.discoverInstance(namespace, name);
3725

3826
(services.Trace as any).setDaemonAddress(address);
39-
(services.Trace as any).captureHTTPRequests();
4027
}
4128

29+
const app = (await import('./app')).default;
30+
31+
const server = http.createServer(app);
32+
33+
createTerminus(server, {
34+
healthChecks: {
35+
'/health/liveness': onHealthCheck,
36+
},
37+
onSignal,
38+
onShutdown,
39+
});
40+
4241
server.listen(config.port, () => {
4342
logger.info(`Server started at http://localhost:${ config.port }`);
4443
});
@@ -48,5 +47,4 @@ async function start(): Promise<void> {
4847
}
4948
}
5049

51-
console.log('What the kurwa?!');
5250
start();

src/services/trace/AWSXRay.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import https from 'https';
55
class AWSXRay implements Services.Trace {
66
constructor (plugins: string) {
77
this.setPlugins(plugins);
8+
9+
XRay.captureHTTPsGlobal(http, true);
10+
XRay.captureHTTPsGlobal(https, true);
811
}
912

1013
public openSegment(defaultName: string) {
@@ -60,11 +63,6 @@ class AWSXRay implements Services.Trace {
6063

6164
XRay.config(xrayPlugins);
6265
}
63-
64-
public captureHTTPRequests(): void {
65-
XRay.captureHTTPsGlobal(http, true);
66-
XRay.captureHTTPsGlobal(https, true);
67-
}
6866
}
6967

7068
export default AWSXRay;

src/services/trace/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import config from '../../config';
44

55
const container = {
66
get AWSXRay() {
7-
console.log('Trace.AWSXRay()');
8-
97
if (typeof this._awsXRay === 'undefined') {
108
this._awsXRay = new AWSXRay(config.services.trace.plugins);
119
}
@@ -14,7 +12,6 @@ const container = {
1412
},
1513

1614
get CLSHooked() {
17-
console.log('Trace.CLSHooked()');
1815
if (typeof this._clsHooked === 'undefined') {
1916
this._clsHooked = new CLSHooked();
2017
}

src/worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ async function start() {
1010
const address = await services.ServiceDiscovery.discoverInstance(namespace, name);
1111

1212
(services.Trace as any).setDaemonAddress(address);
13-
(services.Trace as any).captureHTTPRequests();
1413
}
1514

1615
logger.info('Upload worker is running');

0 commit comments

Comments
 (0)