forked from adrien2p/medusa-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleanup old code and start sentry plugin
- Loading branch information
Showing
34 changed files
with
11,976 additions
and
28,552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
8 changes: 1 addition & 7 deletions
8
packages/medusa/payment-paytr/.gitignore → packages/medusa-plugin-sentry/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@medusa-plugins/medusa-plugin-sentry", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"author": "Adrien de Peretti", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "run-s clean build:tsc", | ||
"build:tsc": "tsc -b", | ||
"clean": "rimraf lib coverage tsconfig.tsbuildinfo" | ||
}, | ||
"peerDependencies": { | ||
"@medusajs/medusa": "^1.4.1" | ||
}, | ||
"devDependencies": { | ||
"ts-node": "^8.6.2", | ||
"@medusajs/medusa": "^1.4.1" | ||
}, | ||
"dependencies": { | ||
"@sentry/node": "^7.14.1", | ||
"@sentry/tracing": "^7.14.1", | ||
"@types/express": "types/express", | ||
"express": "^4.18.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Router } from 'express'; | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import { NodeOptions } from '@sentry/node/types/types'; | ||
import { Integration } from '@sentry/types/types/integration'; | ||
import { RequestHandlerOptions } from '@sentry/node/types/handlers'; | ||
|
||
export type SentryOptions = Omit<NodeOptions, 'integrations'> & { | ||
integrations: Integration[] | ((router: Router, sentry: typeof Sentry, tracing: typeof Tracing) => Integration[]); | ||
shouldHandleError: (code: number) => boolean; | ||
requestHandlerOptions?: RequestHandlerOptions; | ||
enableRequestHandler?: boolean; | ||
enableTracing?: boolean; | ||
}; | ||
|
||
export default function (rootDirectory, pluginOptions: SentryOptions) { | ||
const router = Router(); | ||
|
||
const { | ||
integrations, | ||
shouldHandleError = (code) => code >= 400, | ||
requestHandlerOptions = {}, | ||
enableTracing = true, | ||
enableRequestHandler = true, | ||
...options | ||
} = pluginOptions; | ||
|
||
Sentry.init({ | ||
...options, | ||
integrations: Array.isArray(integrations) ? integrations : integrations(router, Sentry, Tracing), | ||
}); | ||
|
||
if (enableRequestHandler) { | ||
// RequestHandler creates a separate execution context using domains, so that every | ||
// transaction/span/breadcrumb is attached to its own Hub instance | ||
router.use(Sentry.Handlers.requestHandler(requestHandlerOptions)); | ||
} | ||
|
||
if (enableTracing) { | ||
// TracingHandler creates a trace for every incoming request | ||
router.use(Sentry.Handlers.tracingHandler()); | ||
} | ||
|
||
const medusaErrorHandler = require('@medusajs/medusa/dist/api/middlewares/error-handler'); | ||
const originalMedusaErrorHandler = medusaErrorHandler.default; | ||
medusaErrorHandler.default = () => { | ||
return (err, req, res, next) => { | ||
let statusCode; | ||
const res_ = { | ||
...res, | ||
status: (status) => { | ||
statusCode = status; | ||
return res; | ||
}, | ||
}; | ||
originalMedusaErrorHandler()(err, req, res_, next); | ||
Sentry.Handlers.errorHandler({ | ||
shouldHandleError: () => shouldHandleError(statusCode), | ||
})(err, req, res, () => void 0); | ||
}; | ||
}; | ||
|
||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"outDir": ".", | ||
"rootDir": "src", | ||
"baseUrl": "./", | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "**/__tests__/*", "**/__e2e__/*"], | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.