feat(api): add sentry event route

This commit is contained in:
Shaun Hamilton
2025-01-02 10:00:41 +00:00
committed by Mrugesh Mohapatra
parent 4d4e617b7d
commit 55deb556ce
7 changed files with 65 additions and 1 deletions

View File

@@ -38,7 +38,8 @@ import {
FCC_ENABLE_DEV_LOGIN_MODE,
FCC_ENABLE_SWAGGER_UI,
FCC_ENABLE_SHADOW_CAPTURE,
FCC_ENABLE_EXAM_ENVIRONMENT
FCC_ENABLE_EXAM_ENVIRONMENT,
FCC_ENABLE_SENTRY_ROUTES
} from './utils/env';
import { isObjectID } from './utils/validation';
import {
@@ -198,6 +199,10 @@ export const build = async (
void fastify.register(examEnvironmentOpenRoutes);
}
if (FCC_ENABLE_SENTRY_ROUTES) {
void fastify.register(publicRoutes.sentryRoutes);
}
void fastify.register(publicRoutes.chargeStripeRoute);
void fastify.register(publicRoutes.signoutRoute);
void fastify.register(publicRoutes.emailSubscribtionRoutes);

View File

@@ -8,3 +8,4 @@ export * from './email-subscription';
export * from './signout';
export * from './status';
export * from './user';
export * from './sentry';

View File

@@ -0,0 +1,41 @@
/* eslint-disable jsdoc/require-returns, jsdoc/require-param */
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
import { type FastifyInstance, type FastifyReply } from 'fastify';
import { UpdateReqType } from '../../utils';
import * as schemas from '../../schemas';
/**
* Plugin for Sentry-related endpoints.
*
* @param fastify The Fastify instance.
* @param _options Options passed to the plugin via `fastify.register(plugin,
* options)`.
* @param done The callback to signal that the plugin is ready.
*/
export const sentryRoutes: FastifyPluginCallbackTypebox = (
fastify,
_options,
done
) => {
fastify.post(
'/sentry/event',
{
schema: schemas.sentryPostEvent
},
postSentryEventHandler
);
done();
};
/**
* Creates a new event in Sentry.
*/
function postSentryEventHandler(
this: FastifyInstance,
req: UpdateReqType<typeof schemas.sentryPostEvent>,
_reply: FastifyReply
) {
throw new Error(`Sentry Test: ${req.body.text}`);
}

View File

@@ -41,3 +41,4 @@ export { reportUser } from './schemas/user/report-user';
export { resetMyProgress } from './schemas/user/reset-my-progress';
export { submitSurvey } from './schemas/user/submit-survey';
export { userExamEnvironmentToken } from './schemas/user/exam-environment-token';
export { sentryPostEvent } from './schemas/sentry/event';

View File

@@ -0,0 +1,13 @@
import { Type } from '@fastify/type-provider-typebox';
export const sentryPostEvent = {
body: Type.Object({
text: Type.String()
}),
response: {
500: Type.Object({
message: Type.Literal('flash.generic-error'),
type: Type.Literal('danger')
})
}
};

View File

@@ -135,6 +135,8 @@ export const FCC_ENABLE_SHADOW_CAPTURE =
process.env.FCC_ENABLE_SHADOW_CAPTURE === 'true';
export const FCC_ENABLE_EXAM_ENVIRONMENT =
process.env.FCC_ENABLE_EXAM_ENVIRONMENT === 'true';
export const FCC_ENABLE_SENTRY_ROUTES =
process.env.FCC_ENABLE_SENTRY_ROUTES === 'true';
export const SENTRY_DSN =
process.env.SENTRY_DSN === 'dsn_from_sentry_dashboard'
? ''

View File

@@ -70,6 +70,7 @@ FCC_ENABLE_SWAGGER_UI=true
FCC_ENABLE_DEV_LOGIN_MODE=true
FCC_ENABLE_SHADOW_CAPTURE=false
FCC_ENABLE_EXAM_ENVIRONMENT=false
FCC_ENABLE_SENTRY_ROUTES=false
# Email
# use ses in production