Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry を導入 #608

Merged
merged 3 commits into from
Dec 6, 2022
Merged

Sentry を導入 #608

merged 3 commits into from
Dec 6, 2022

Conversation

HosokawaR
Copy link
Member

@HosokawaR HosokawaR commented Nov 26, 2022

背景

Resolves #593

概要

  1. Sentry を導入しました
  2. Source Map をビルド時に自動でアップロードするようにしました
    1. 本番環境でのみ Source Map がアップロードされます
  3. 不要なパッケージの削除

細かい意図は下のコメントに続けて書きます。

なお本 PR が Merge された段階で開発メンバーに Sentry プロジェクトの招待を送ります。

動作検証

設定をいじり、ローカルで発生したエラーが Sentry に補足され、 Discord のチャンネルに流れることを確認した。

@vercel
Copy link

vercel bot commented Nov 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
twinte-front ✅ Ready (Inspect) Visit Preview Nov 26, 2022 at 11:27PM (UTC)

I used @sentry/rollup-plugin instead of @sentry/vite-plugin, because @senty/vite-plugin occurd building error.
Comment on lines -21 to -23
app.config.errorHandler = (err, _vm, _info) => {
Sentry.captureException(err); // 手動でSentryに送信
};
Copy link
Member Author

@HosokawaR HosokawaR Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは不要なため消しました。

@sentry/vue の実装を見れば分かるように、Sentry.initは自動でapp.config.errorHandlerにエラーキャプチャを仕込むためです。

逆に

window.addEventListener("error", (event) => {});
window.addEventListener("unhandledrejection", (event) => {});

などはキャプチャしてくれなそうなので、残しました。

Comment on lines 55 to 64
} else if (error instanceof InternalServerError) {
errorMessage.value =
"申し訳ございません。サーバー内でエラーが発生しました。";
return true;
} else {
errorMessage.value = error.message;
return true;
}

return false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://vuejs.org/api/composition-api-lifecycle.html#onerrorcaptured にあるように、onerrorcapturedの返り値が true だと app.config.errorHandler までエラーが伝播し Sentry に補足されます。false だと補足されません。

未認証エラー、ネットワークエラーは Sentry では補足しないつもりです。(意見募集中)

@@ -1,4 +1,5 @@
import path from "path";
import sentryRollupPlugin from "@sentry/rollup-plugin";
Copy link
Member Author

@HosokawaR HosokawaR Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実は @sentry/vite-plugin といのもあるのですが、こちらはビルド時に Vite がエラーを吐いてしまうため使いませんでした。

エラーが出る原因は色々調べたのですがわかりませんでした。

代わりに、 Vite はプロダクションビルド時に内部で Rollup.js を使用しており、Rollup.js の設定を vite.config.js 経由で渡せるため、@sentry/rollup-plugin を使用しました。

また、まだパッケージが公開されて浅いですが、使用することに決めました。
このプラグインは基本的にビルド時に Source Map を Sentry に送るだけなので、プロダクションに動作には大きな影響を与えないと判断したためです。

@HosokawaR HosokawaR marked this pull request as ready for review November 27, 2022 10:03
@HosokawaR
Copy link
Member Author

HosokawaR commented Nov 27, 2022

@takonomura

プロダクションデプロイ時に環境変数を渡す箇所について見てもらえると幸いです。
これは Sentry の Source Map のアップロードに必要なものなので、CI / プレビューデプロイでは不要です。
yarn build:productionSENTRY_AUTH_TOKEN を渡すことが目的です。

@@ -7,7 +7,9 @@ RUN yarn install
ENV VITE_API_URL=https://app.twinte.net/api/v3

COPY . ./
RUN yarn build
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最近 --mount=type=secret 使ってないので確認したいんですが、 # syntax= から始まる行を Dockerfile の先頭に入れてフロントエンド指定しなくてもこれって動くんでしたっけ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。返信が遅れすみません。

https://docs.docker.com/engine/release-notes/#builder-5

Support for RUN --mount options without needing to specify experimental dockerfile #syntax directive.

入れなくても動くようになったようです。

ただ、そう言われるとこれがdocker/build-push-action@v2にでも動くかどうが自信がなくなってきました。

Copy link
Member Author

@HosokawaR HosokawaR Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上記について調べました。
Docker の 20.10.0 # syntac=が不要になり、そしてdocker/build-push-action@v2GitHub Actions のログを見てみると Version: 20.10.21+azure-1の記載があるので、動くと判断しました。

Copy link
Contributor

@HikaruEgashira HikaruEgashira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いいと思います。
Dockerにソースマップアップロード含めるの一瞬気になっちゃうけど、
リリースと紐づけるって意味付けになってるのでいいアイデアかも。

@HosokawaR HosokawaR merged commit 01fb251 into main Dec 6, 2022
@HosokawaR HosokawaR deleted the feature/sentry branch December 6, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentry を導入
4 participants