/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/plugins/sentry/server/src/middlewares/sentry.ts
45 строк
1 KB
Nico André
chore(lint): add non-blocking oxlint setup (#26923)
31 июл 2026, 16:56
Не верифицирован
31 июл 2026, 16:56
6469af3
Код
Авторство
О чём код?
import type { Core } from '@strapi/strapi'; import type * as Sentry from '@sentry/node'; import type createSentryService from '../services/sentry'; /** * Programmatic sentry middleware. We do not want to expose it in the plugin */ export default ({ strapi }: { strapi: Core.Strapi }) => { const sentryService: ReturnType<typeof createSentryService> = strapi .plugin('sentry') .service('sentry'); sentryService.init(); const sentry = sentryService.getInstance(); if (!sentry) { // initialization failed return; } strapi.server.use(async (ctx, next) => { try { await next(); } catch (error) { if (error instanceof Error) { sentryService.sendError(error, (scope: Sentry.Scope) => { scope.addEventProcessor((event) => { // Parse Koa context to add error metadata return sentry.Handlers.parseRequest(event, ctx.request as Sentry.Request, { // Don't parse the transaction name, we'll do it manually transaction: false, }); }); // Manually add transaction name scope.setTag('transaction', `${ctx.method} ${ctx._matchedRoute}`); // Manually add Strapi version scope.setTag('strapi_version', strapi.config.info.strapi); scope.setTag('method', ctx.method); }); } throw error; } }); };