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

Update Sentry usage in @strapi/plugin-sentry #17435

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mydea
Copy link

@mydea mydea commented Jul 25, 2023

This updates the used Sentry version to the current latest (7.60.0), and also updates the middlewares based on https://docs.sentry.io/platforms/node/guides/koa/.

  • Update @sentry/node to ^7.60.0 - I think it makes sense to allow the caret version here, as otherwise you do not get bugfixes etc. If you prefer to hard-pin this to 7.60.0, let me know, then I can also do that.
  • Add new option tracesSampleRate which defaults to 0.1. Based on this we can also instrument performance monitoring in Sentry for the user.
  • Update middlewares based on current docs.

Fixes #17425

@strapi-cla
Copy link

strapi-cla commented Jul 25, 2023

CLA assistant check
All committers have signed the CLA.

}

strapi.server.use(async (ctx, next) => {
return new Promise((resolve, reject) => {
Copy link

Choose a reason for hiding this comment

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

Why are we instantiating a promise here?

Copy link
Author

Choose a reason for hiding this comment

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

good point, will just remove these wrapping promises!

Comment on lines 33 to 38
try {
await next();
} catch (err) {
reject(err);
}
resolve();
Copy link

Choose a reason for hiding this comment

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

This is unnecessary if we just remove the surrounding promise.

Copy link
Author

Choose a reason for hiding this comment

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

good point, removed this (and will also update the docs accordingly 😅 )

scope.addEventProcessor((event) =>
Sentry.addRequestDataToEvent(event, ctx.request, {
include: {
user: false,
Copy link

@lforst lforst Jul 25, 2023

Choose a reason for hiding this comment

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

Are there any other default values we should override for pii reasons?

Copy link
Author

Choose a reason for hiding this comment

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

The other things here here are ip which is off by default, request and transaction which should both be fine I think.

category: 'stderr',
message: line,
level: Severity.Error,
level: Sentry.Severity.Error,
Copy link

Choose a reason for hiding this comment

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

// connect to trace of upstream app
let traceparentData;
if (ctx.request.get('sentry-trace')) {
traceparentData = Sentry.extractTraceparentData(ctx.request.get('sentry-trace'));

Choose a reason for hiding this comment

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

we also want to extract baggage here, and also use distributed tracing features (don't gate by hasTracingEnabled). See express as an example:

https://github.com/getsentry/sentry-javascript/blob/53d32a3ac7d2238616ac6dc9c210e3d1d0584bbb/packages/node/src/handlers.ts#L56-L69

Copy link
Author

Choose a reason for hiding this comment

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

I updated this again, can you have another look?

Copy link

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

A concern I have is that bumping the major version of Sentry means introducing a breaking change. It's only a small one and can be corrected though, see my comment there

And I think we tend to prefer fixed version dependencies, to avoid potential bugs in future releases or packages not respecting semver. The dependabot github app makes it easy to upgrade our dependencies, but with a small manual check for extra safety

@mydea
Copy link
Author

mydea commented Sep 13, 2023

Thanks for the PR!

A concern I have is that bumping the major version of Sentry means introducing a breaking change. It's only a small one and can be corrected though, see my comment there

And I think we tend to prefer fixed version dependencies, to avoid potential bugs in future releases or packages not respecting semver. The dependabot github app makes it easy to upgrade our dependencies, but with a small manual check for extra safety

OK, I pinned the deps to an exact version, and also added some code to migrate the old allow/deny URL options! 🚀

@Adaphath
Copy link

Adaphath commented Oct 4, 2023

When can we expect to get the new Sentry SDK version released?

@davidkassa
Copy link

It appears that the changes requested are completed, but now we're up to 7.91.0 :)

@davidkassa
Copy link

This PR, as-is, doesn't work. I was receiving the following error until I changed the strapi.server.use methods to async with await next(). I haven't finished testing, but that solved the closed stream issue.

[2023-12-30 12:09:51.388] http: POST /graphql (12 ms) 404
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
InternalServerError: stream is not readable
    at readStream (/Users/dave/Code/strapi/node_modules/raw-body/index.js:185:17)
    at executor (/Users/dave/Code/strapi/node_modules/raw-body/index.js:120:5)
    at new Promise (<anonymous>)
    at getRawBody (/Users/dave/Code/strapi/node_modules/raw-body/index.js:119:10)
    at module.exports [as json] (/Users/dave/Code/strapi/node_modules/koa-bodyparser/node_modules/co-body/lib/json.js:39:21)
    at parseBody (/Users/dave/Code/strapi/node_modules/koa-bodyparser/index.js:87:26)
    at bodyParser (/Users/dave/Code/strapi/node_modules/koa-bodyparser/index.js:67:25)
    at /Users/dave/Code/strapi/node_modules/apollo-server-koa/dist/ApolloServer.js:15:16
    at dispatch (/Users/dave/Code/strapi/node_modules/koa-compose/index.js:42:32)
    at /Users/dave/Code/strapi/node_modules/apollo-server-koa/dist/ApolloServer.js:18:16

@hanpaine hanpaine added community source: plugin:sentry Source is plugin/sentry package pr: chore This PR contains chore tasks (cleanups, configs, tooling...) labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community pr: chore This PR contains chore tasks (cleanups, configs, tooling...) source: plugin:sentry Source is plugin/sentry package
Projects
Status: To be reviewed
Development

Successfully merging this pull request may close these issues.

Bump Sentry version for @strapi/plugin-sentry to 7.x
8 participants