Listory/src/main.ts

76 lines
2.2 KiB
TypeScript
Raw Normal View History

import { otelSDK } from "./open-telemetry/sdk"; // needs to be loaded first - always -
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";
import { context, trace } from "@opentelemetry/api";
import * as Sentry from "@sentry/node";
import { RavenInterceptor } from "nest-raven";
2021-05-25 18:12:42 +02:00
import { AppModule } from "./app.module";
import { Logger } from "nestjs-pino";
import { Scope } from "@sentry/node";
function setupSentry(
app: NestExpressApplication,
2023-09-16 13:02:19 +02:00
configService: ConfigService,
) {
Sentry.init({
dsn: configService.get<string>("SENTRY_DSN"),
integrations: [
new Sentry.Integrations.OnUncaughtException(),
new Sentry.Integrations.OnUnhandledRejection(),
],
});
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 });
}
},
],
2023-09-16 13:02:19 +02:00
}),
);
}
2020-01-25 22:19:14 +01:00
async function bootstrap() {
await otelSDK.start();
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
bufferLogs: true,
});
app.useLogger(app.get(Logger));
app.useGlobalPipes(
new ValidationPipe({
transform: true,
transformOptions: { enableImplicitConversion: true },
2023-09-16 13:02:19 +02:00
}),
);
app.enableShutdownHooks();
2020-01-26 19:07:15 +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-01-25 22:19:14 +01:00
bootstrap();