Skip to content

Commit

Permalink
feat: добавлен чистый Sentry/node
Browse files Browse the repository at this point in the history
  • Loading branch information
mxseev committed Feb 25, 2023
1 parent d62f167 commit 9c593b5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"test:unit": "jest"
},
"dependencies": {
"@sentry/node": "^7.38.0",
"@sentry/tracing": "^7.38.0",
"dotenv": "16.0.3"
},
"devDependencies": {
Expand Down
82 changes: 79 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
/* eslint-disable no-console */
import * as Sentry from "@sentry/node"
import {createInterface} from "readline"

import "./monitoring"
import "./sentry"

const greet = (name?: string): string => {
if (!name) {
throw new Error("Name not found")
}

if (name === "cat") {
Sentry.captureMessage("warn: cats can't use a keyboard")
}

return `Hello, ${name}`
}

if (require.main === module) {
const main = async () => {
const reader = createInterface({
input: process.stdin,
output: process.stdout
})

reader.question("What is your name?: ", answer => {
const greeting = greet(answer)
try {
const greeting = greet(answer)

console.log(greeting)
} catch (error) {
console.error(error)
Sentry.captureException(error)
}

reader.close()
})

await Sentry.flush(2500)
}

if (require.main === module) {
main()
}

export default greet
10 changes: 10 additions & 0 deletions src/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from "@sentry/node"
import "@sentry/tracing"

import env from "./env"

Sentry.init({
dsn: env.sentryDsn,
environment: env.sentryEnv,
tracesSampleRate: 1.0
})

0 comments on commit 9c593b5

Please sign in to comment.