Skip to content

Commit b7683f7

Browse files
committed
feat: Integrate Sentry logging and enhance SSE timeout configurations
1 parent 5517ccd commit b7683f7

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

apps/api/src/core/logger/internal.logger.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ConsoleLogger, Injectable, LogLevel } from '@nestjs/common';
22
import { MongooseModuleOptions } from '@nestjs/mongoose';
33
import { Request } from 'express';
44
import { Connection, connect } from 'mongoose';
5+
import * as Sentry from '@sentry/nestjs';
56

67
export interface InternalLoggerOptions {
78
logLevel: LogLevel[];
@@ -32,11 +33,17 @@ export class InternalLogger extends ConsoleLogger {
3233
}
3334

3435
public async initialize() {
36+
Sentry.logger.info('Initializing logs database connection...', {
37+
'module': this.constructor.name,
38+
});
3539
super.log('Initializing logs database connection...', this.constructor.name);
3640
try {
3741
const mongoose = await connect(this._options.mongoose.uri, this._options.mongoose.options);
3842
this.connection = mongoose.connection;
3943
} catch (e) {
44+
Sentry.logger.error('Failed to connect to the logs database', e, {
45+
'module': this.constructor.name,
46+
});
4047
super.error('Failed to connect to the logs database', e, this.constructor.name);
4148
setTimeout(() => this.initialize(), 5000);
4249
}
@@ -56,6 +63,9 @@ export class InternalLogger extends ConsoleLogger {
5663
if (!options.target.includes(InternalLogLevel.CONSOLE)) return;
5764
}
5865

66+
Sentry.logger.error(message, {
67+
'module': typeof lastParam === 'string' ? lastParam : this.constructor.name,
68+
});
5969
super.error(...[message, ...optionalParams]);
6070
}
6171

@@ -72,6 +82,7 @@ export class InternalLogger extends ConsoleLogger {
7282
if (!options.target.includes(InternalLogLevel.CONSOLE)) return;
7383
}
7484

85+
Sentry.logger.warn(message);
7586
super.warn(...[message, ...optionalParams]);
7687
}
7788

@@ -85,6 +96,7 @@ export class InternalLogger extends ConsoleLogger {
8596
if (!options.target.includes(InternalLogLevel.CONSOLE)) return;
8697
}
8798

99+
Sentry.logger.info(message);
88100
super.log(...[message, ...optionalParams]);
89101
}
90102

@@ -101,6 +113,7 @@ export class InternalLogger extends ConsoleLogger {
101113
if (!options.target.includes(InternalLogLevel.CONSOLE)) return;
102114
}
103115

116+
Sentry.logger.debug(message);
104117
super.debug(...[message, ...optionalParams]);
105118
}
106119

@@ -133,6 +146,7 @@ export class InternalLogger extends ConsoleLogger {
133146
if (!options.target.includes(InternalLogLevel.CONSOLE)) return;
134147
}
135148

149+
Sentry.logger.fatal(message);
136150
super.fatal(...[message, ...optionalParams]);
137151
}
138152

apps/api/src/instrument.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ if (!process.env.SESAME_SENTRY_DSN) {
77
} else {
88
Sentry.init({
99
dsn: process.env.SESAME_SENTRY_DSN!,
10+
release: process.env.npm_package_name + '@' + process.env.npm_package_version,
1011
debug: false,
1112

1213
sendDefaultPii: true,
1314
tracesSampleRate: 1.0,
1415
profilesSampleRate: 1.0,
1516
includeLocalVariables: true,
17+
profileLifecycle: 'trace',
18+
19+
enableLogs: true,
1620

1721
integrations: [
1822
nodeProfilingIntegration(),
1923

20-
2124
Sentry.mongooseIntegration(),
2225
Sentry.consoleIntegration(),
2326
Sentry.httpIntegration(),
@@ -27,5 +30,10 @@ if (!process.env.SESAME_SENTRY_DSN) {
2730
Sentry.fsIntegration(),
2831
],
2932
})
33+
Sentry.startSpan({
34+
name: "My Span",
35+
}, () => {
36+
// The code executed here will be profiled
37+
});
3038
Logger.log(`Sentry initialized successfully`, 'SentryInit')
3139
}

apps/api/src/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,23 @@ declare const module: any;
6464

6565
const shutdownObserver = app.get(ShutdownObserver);
6666
const httpServer = http.createServer(server).listen(4000);
67+
68+
// Set timeout to 0 for SSE connections
69+
httpServer.timeout = 0;
70+
httpServer.keepAliveTimeout = 0;
71+
httpServer.headersTimeout = 0;
72+
6773
shutdownObserver.addHttpServer(httpServer);
6874
logger.log(`Sesame - Orchestrator is READY on <http://127.0.0.1:4000> !`);
6975

7076
if (cfg.application?.https?.enabled) {
7177
const httpsServer = https.createServer(extraOptions.httpsOptions!, server).listen(4443);
78+
79+
// Set timeout to 0 for SSE connections
80+
httpsServer.timeout = 0;
81+
httpsServer.keepAliveTimeout = 0;
82+
httpsServer.headersTimeout = 0;
83+
7284
shutdownObserver.addHttpServer(httpsServer);
7385
logger.log(`Sesame - Orchestrator is READY on <https://127.0.0.1:4443> !`);
7486
}

apps/web/nuxt.config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ export default defineNuxtConfig({
137137
secure: false,
138138
changeOrigin: true,
139139
xfwd: true,
140+
configure: (proxy, options) => {
141+
proxy.on('proxyReq', (proxyReq, req, res) => {
142+
// Disable timeout for SSE endpoints
143+
if (req.url?.includes('/backends/sse')) {
144+
proxyReq.setTimeout(0);
145+
res.setTimeout(0);
146+
}
147+
});
148+
},
140149
}
141150
},
142151
cors: false,
@@ -196,6 +205,21 @@ export default defineNuxtConfig({
196205
future: {
197206
typescriptBundlerResolution: true,
198207
},
208+
nitro: {
209+
experimental: {
210+
websocket: false,
211+
},
212+
routeRules: {
213+
'/api/core/backends/sse': {
214+
// Disable compression and caching for SSE
215+
headers: {
216+
'Cache-Control': 'no-cache, no-transform',
217+
'Connection': 'keep-alive',
218+
'X-Accel-Buffering': 'no', // Disable buffering in nginx
219+
},
220+
},
221+
},
222+
},
199223
experimental: {
200224
appManifest: false,
201225
},
@@ -227,7 +251,7 @@ export default defineNuxtConfig({
227251
console.log('[OpenapiTS] Generating .nuxt/types/service-api.d.ts...')
228252
try {
229253
const fileData = await openapiTS(`${SESAME_APP_API_URL}/swagger/json`)
230-
writeFileSync('.nuxt/types/service-api.d.ts', fileData)
254+
writeFileSync('.nuxt/types/service-api.d.ts', String(fileData))
231255
console.log('[OpenapiTS] Generated .nuxt/types/service-api.d.ts !')
232256
} catch (error) {
233257
console.debug('[OpenapiTS] Error while generating .nuxt/types/service-api.d.ts', error)

0 commit comments

Comments
 (0)