2022-02-27 17:57:33 +01:00
|
|
|
import { otelSDK } from "./open-telemetry/sdk"; // needs to be loaded first - always -
|
2020-11-17 22:26:03 +01:00
|
|
|
import { ValidationPipe } from "@nestjs/common";
|
|
|
|
|
import { ConfigService } from "@nestjs/config";
|
2020-01-25 22:19:14 +01:00
|
|
|
import { NestFactory } from "@nestjs/core";
|
2020-01-26 19:07:15 +01:00
|
|
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
2020-02-01 16:11:48 +01:00
|
|
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
2022-02-27 17:57:33 +01:00
|
|
|
import { context, trace } from "@opentelemetry/api";
|
2020-11-17 22:26:03 +01:00
|
|
|
import * as Sentry from "@sentry/node";
|
|
|
|
|
import { RavenInterceptor } from "nest-raven";
|
2021-05-25 18:12:42 +02:00
|
|
|
import { AppModule } from "./app.module";
|
2022-02-27 17:57:33 +01:00
|
|
|
import { Logger } from "nestjs-pino";
|
2022-06-23 18:24:56 +02:00
|
|
|
import { Scope } from "@sentry/node";
|
2022-02-27 17:57:33 +01:00
|
|
|
|
2020-11-17 22:26:03 +01:00
|
|
|
function setupSentry(
|
|
|
|
|
app: NestExpressApplication,
|
|
|
|
|
configService: ConfigService
|
|
|
|
|
) {
|
|
|
|
|
Sentry.init({
|
|
|
|
|
dsn: configService.get<string>("SENTRY_DSN"),
|
|
|
|
|
integrations: [
|
|
|
|
|
new Sentry.Integrations.OnUncaughtException(),
|
|
|
|
|
new Sentry.Integrations.OnUnhandledRejection(),
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-23 18:24:56 +02:00
|
|
|
app.useGlobalInterceptors(
|
|
|
|
|
new RavenInterceptor({
|
|
|
|
|
transformers: [
|
|
|
|
|
(scope: Scope) => {
|
|
|
|
|
const span = trace.getSpan(context.active());
|
|
|
|
|
if (span) {
|
|
|
|
|
const { spanId, traceId } = span.spanContext();
|
|
|
|
|
scope.setContext("trace", { span_id: spanId, trace_id: traceId });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
);
|
2020-11-17 22:26:03 +01:00
|
|
|
}
|
2020-01-25 22:19:14 +01:00
|
|
|
|
|
|
|
|
async function bootstrap() {
|
2022-02-27 17:57:33 +01:00
|
|
|
await otelSDK.start();
|
|
|
|
|
|
|
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
|
|
|
bufferLogs: true,
|
|
|
|
|
});
|
|
|
|
|
app.useLogger(app.get(Logger));
|
2020-05-09 16:29:17 +02:00
|
|
|
app.useGlobalPipes(
|
|
|
|
|
new ValidationPipe({
|
|
|
|
|
transform: true,
|
|
|
|
|
transformOptions: { enableImplicitConversion: true },
|
|
|
|
|
})
|
|
|
|
|
);
|
2020-05-03 04:32:43 +02:00
|
|
|
app.enableShutdownHooks();
|
2020-01-26 19:07:15 +01:00
|
|
|
|
2020-11-17 22:26:03 +01:00
|
|
|
const configService = app.get<ConfigService>(ConfigService);
|
|
|
|
|
|
|
|
|
|
if (configService.get<boolean>("SENTRY_ENABLED")) {
|
|
|
|
|
setupSentry(app, configService);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 16:11:48 +01:00
|
|
|
// Setup API Docs
|
|
|
|
|
const options = new DocumentBuilder()
|
|
|
|
|
.setTitle("Listory")
|
|
|
|
|
.setDescription("Track and analyze your Spotify Listens")
|
|
|
|
|
.setVersion("1.0")
|
|
|
|
|
.addBearerAuth()
|
|
|
|
|
.build();
|
|
|
|
|
const document = SwaggerModule.createDocument(app, options);
|
|
|
|
|
SwaggerModule.setup("api/docs", app, document);
|
2020-01-26 19:07:15 +01:00
|
|
|
|
2023-03-19 16:02:49 +01:00
|
|
|
await app.listen(configService.get<number>("PORT"));
|
2020-01-25 22:19:14 +01:00
|
|
|
}
|
2020-11-17 22:26:03 +01:00
|
|
|
|
2020-01-25 22:19:14 +01:00
|
|
|
bootstrap();
|