Sentryをreact.jsプロジェクトへ適用する

公式サイト の見ながらreact.jsプロジェクトにSentryを適用してみました。 バージョン react 17.0.1 Sentry @sentry/react 6.2.5 @sentry/tracing 6.2.5 Sentryへプロジェクト追加及び設定 Sentryへログイン後、プロジェクト作成。 Client Keys (DSN)メニューに書いてある、DSNキーをコピーしておきます。 sentry パッケージインストール npm install --save @sentry/react @sentry/tracing index.jsにSentryを初期化するコードを追加します。 import React from "react"; import ReactDOM from "react-dom"; import * as Sentry from "@sentry/react"; import { Integrations } from "@sentry/tracing"; import App from "./App"; import "./index.css"; Sentry.init({ // 全ての環境に設定時 dsn: "https://xxxxxxxxxxxxxxxxxxxxxxxxxxx@xxxxxx.ingest.sentry.io/xxxxx", // productionのみ設定時 dsn: process.env.NODE_ENV === "production" ? "https://xxxxxxxxxxxxxxxxxxxxxxxxxxx@xxxxxx.ingest.sentry.io/xxxxx" : false, integrations: [new Integrations.BrowserTracing()], environment: process.env.NODE_ENV, tracesSampleRate: 1....

2021-04-16 · bokyung

SentryをSpringBootプロジェクトへ適用する

react.jsへSentryを適用しようと思い、公式ドキュメントを見てみると対応言語の中にSpringBootがあったため、試してみました。 バージョン Spring Boot 2.4.1 Sentry sentry-spring-boot-starter 4.3.0 Sentryへプロジェクト追加及び設定 Sentryへログイン後、プロジェクト作成。 Client Keys (DSN)メニューに書いてある、DSNキーをコピーしておきます。 build.gradle.ktsに依存関係を追加します。 build.gradle.kts implementation("io.sentry:sentry-spring-boot-starter:4.3.0") application.properties에 DSN (Data Source Name)を設定します。 application.properties # DSN設定 sentry.dsn=https://xxxxxxxxxxxxxxxxxxxxxxxxxxx@xxxxxx.ingest.sentry.io/xxxxx # エラートレース設定 sentry.enable-tracing=true application-development.properties # 各環境の設定も可能です。 sentry.environment=development Sentryにエラーを送るための設定 サンプルプロジェクトがRestApiプロジェクトなので、@RestControllerAdviceを利用して共通エラー処理を追加しました。 @RestControllerAdvice class SampleControllerAdvice { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MissingPathVariableException::class) fun handleMissingPathVariable(ex: MissingPathVariableException): Map<String, String> { Sentry.captureException(ex) val error: Map<String, String> = mapOf("code" to "E0001", "message" to "Parameter error") return error } @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) @ExceptionHandler(HttpMediaTypeNotSupportedException::class) fun handleHttpMediaTypeNotSupported(ex: HttpMediaTypeNotSupportedException): Map<String, String> { Sentry....

2021-04-15 · bokyung