From 4fc2d10ded58a973a8328c36344a44b6bfe57613 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:09:31 -0700 Subject: [PATCH 1/7] change project install command to specifically use bash --- packages/nextjs/vercel/install-sentry-from-branch.sh | 2 +- packages/nextjs/vercel/instructions.md | 2 +- packages/nextjs/vercel/make-project-use-current-branch.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index 5933b5a1d675..65518aa879a1 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -1,7 +1,7 @@ # SCRIPT TO INCLUDE AS PART OF A VERCEL-DEPLOYED PROJECT, SO THAT IT USES A BRANCH FROM THE SDK REPO # USE `yarn vercel:project ` TO HAVE IT AUTOMATICALLY ADDED TO YOUR PROJECT -# CUSTOM INSTALL COMMAND FOR PROJECT ON VERCEL: `source .sentry/install-sentry-from-branch.sh` +# CUSTOM INSTALL COMMAND FOR PROJECT ON VERCEL: `bash .sentry/install-sentry-from-branch.sh` PROJECT_DIR=$(pwd) diff --git a/packages/nextjs/vercel/instructions.md b/packages/nextjs/vercel/instructions.md index 333df8a73db9..530bc367d58e 100644 --- a/packages/nextjs/vercel/instructions.md +++ b/packages/nextjs/vercel/instructions.md @@ -33,7 +33,7 @@ commit (but not push) this change. Go into your project settings on Vercel and change the install command to - `source .sentry/install-sentry-from-branch.sh`. + `bash .sentry/install-sentry-from-branch.sh`. If you're using bundle analyzer, change the build command to diff --git a/packages/nextjs/vercel/make-project-use-current-branch.sh b/packages/nextjs/vercel/make-project-use-current-branch.sh index f0ebe9a3b13d..817ec0fa7fa5 100644 --- a/packages/nextjs/vercel/make-project-use-current-branch.sh +++ b/packages/nextjs/vercel/make-project-use-current-branch.sh @@ -58,5 +58,5 @@ cd $NEXTJS_SDK_DIR echo " " echo "SUCCESS!" echo "Your project will now use this branch of the SDK repo when deployed to Vercel. If you haven't done so already, go to your project settings in Vercel and set a custom install command:" -echo " $(source .sentry/install-sentry-from-branch.sh)" +echo " $(bash .sentry/install-sentry-from-branch.sh)" echo " " From ab530f7eac0f60d65a3bf6d0d0dd6590b42eef88 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:09:53 -0700 Subject: [PATCH 2/7] remove stray subshell markers --- packages/nextjs/vercel/make-project-use-current-branch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/vercel/make-project-use-current-branch.sh b/packages/nextjs/vercel/make-project-use-current-branch.sh index 817ec0fa7fa5..fb28d99178e1 100644 --- a/packages/nextjs/vercel/make-project-use-current-branch.sh +++ b/packages/nextjs/vercel/make-project-use-current-branch.sh @@ -58,5 +58,5 @@ cd $NEXTJS_SDK_DIR echo " " echo "SUCCESS!" echo "Your project will now use this branch of the SDK repo when deployed to Vercel. If you haven't done so already, go to your project settings in Vercel and set a custom install command:" -echo " $(bash .sentry/install-sentry-from-branch.sh)" +echo " bash .sentry/install-sentry-from-branch.sh" echo " " From 5a77445e0c7c205d01f2e446223437527adf0e13 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:12:09 -0700 Subject: [PATCH 3/7] improve install script logging --- .../nextjs/vercel/install-sentry-from-branch.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index 65518aa879a1..8595a1dcb094 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -4,6 +4,7 @@ # CUSTOM INSTALL COMMAND FOR PROJECT ON VERCEL: `bash .sentry/install-sentry-from-branch.sh` PROJECT_DIR=$(pwd) +REPO_DIR="${PROJECT_DIR}/sentry-javascript" # Set BRANCH_NAME as an environment variable source .sentry/set-branch-name.sh @@ -11,9 +12,13 @@ source .sentry/set-branch-name.sh echo " " echo "CLONING SDK REPO" git clone https://github.com/getsentry/sentry-javascript.git -cd sentry-javascript + +echo " " +echo "MOVING INTO REPO DIRECTORY AND CHECKING OUT BRANCH" +cd $REPO_DIR git checkout $BRANCH_NAME -echo "Latest commit: $(git log --format="%C(auto) %h - %s" | head -n 1)" + +echo "LATEST COMMIT: $(git log --format="%C(auto) %h - %s" | head -n 1)" echo " " echo "INSTALLING SDK DEPENDENCIES" @@ -27,6 +32,9 @@ echo "BUILDING SDK" yarn build:es5 # we need to build esm versions because that's what `next` actually uses when it builds the app yarn build:esm + +echo " " +echo "MOVING BACK TO PROJECT DIRECTORY" cd $PROJECT_DIR # Add built SDK as a file dependency. This has the side effect of forcing yarn to install all of the other dependencies, @@ -39,6 +47,8 @@ yarn add file:sentry-javascript/packages/nextjs # In case for any reason we ever need to link the local SDK rather than adding it as a file dependency: # for abs_package_path in ${PROJECT_DIR}/sentry-javascript/packages/*; do +# echo " " +# echo "LINKING LOCAL SDK INTO PROJECT" # # link the built packages into project dependencies # for abs_package_path in sentry-javascript/packages/*; do From e19f66d1c593a3336253ec5c8e937ba8ee5cd894 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:12:27 -0700 Subject: [PATCH 4/7] random cleanup --- packages/nextjs/vercel/install-sentry-from-branch.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index 8595a1dcb094..c334c3f21cec 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -27,10 +27,10 @@ yarn --prod false echo " " echo "BUILDING SDK" -# we need to build es5 versions because `next.config.js` calls `require` on the SDK (to get `withSentryConfig`) and +# We need to build es5 versions because `next.config.js` calls `require` on the SDK (to get `withSentryConfig`) and # therefore it looks for `dist/index.js` yarn build:es5 -# we need to build esm versions because that's what `next` actually uses when it builds the app +# We need to build esm versions because that's what `next` actually uses when it builds the app yarn build:esm echo " " @@ -46,11 +46,9 @@ yarn add file:sentry-javascript/packages/nextjs # In case for any reason we ever need to link the local SDK rather than adding it as a file dependency: -# for abs_package_path in ${PROJECT_DIR}/sentry-javascript/packages/*; do # echo " " # echo "LINKING LOCAL SDK INTO PROJECT" -# # link the built packages into project dependencies # for abs_package_path in sentry-javascript/packages/*; do # package=$(basename $abs_package_path) From 7665f3fd4fc0adf961a1d2c023069645404870b2 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:14:05 -0700 Subject: [PATCH 5/7] patch config files to add tags to events --- .../vercel/install-sentry-from-branch.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index c334c3f21cec..1b95ebbbd782 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -37,6 +37,33 @@ echo " " echo "MOVING BACK TO PROJECT DIRECTORY" cd $PROJECT_DIR +# TODO move this into `yarn vercel:project` script, accounting for differences in SDK repo location between running the +# test app locally and on vercel +echo " " +echo "PATCHING SENTRY.SERVER.CONFIG.JS AND SENTRY.CLIENT.CONFIG.JS" +echo "Removing frame limit on stacktraces" +echo "Tagging events with $(vercel) tag" +echo "Tagging events with SDK repo's most recent commit message" +echo "Tagging events with test project repo's most recent commit message" + +INFINITE_STACKTRACE_CODE=" +Error.stackTraceLimit = Infinity; + " + +SDK_COMMIT_MESSAGE=$(cd sentry-javascript && git log --format="%C(auto)%s" | head -n 1) +CONFIGURE_SCOPE_CODE=" +Sentry.configureScope(scope => { + if (process.env.VERCEL) { + scope.setTag('vercel', true); + } + scope.setTag('commitMessage', process.env.VERCEL_GIT_COMMIT_MESSAGE); + scope.setTag('sdkCommitMessage', \"$SDK_COMMIT_MESSAGE\"); +}); + " + +echo "$INFINITE_STACKTRACE_CODE" "$CONFIGURE_SCOPE_CODE" >>sentry.server.config.js +echo "$INFINITE_STACKTRACE_CODE" "$CONFIGURE_SCOPE_CODE" >>sentry.client.config.js + # Add built SDK as a file dependency. This has the side effect of forcing yarn to install all of the other dependencies, # saving us the trouble of needing to call `yarn` separately after this echo " " From 4487aa0caee27e971ff815fb2183231e7c5eb684 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Thu, 15 Jul 2021 23:14:24 -0700 Subject: [PATCH 6/7] use file deps for all sentry packages --- .../vercel/install-sentry-from-branch.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index 1b95ebbbd782..0c1f594034c3 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -33,6 +33,34 @@ yarn build:es5 # We need to build esm versions because that's what `next` actually uses when it builds the app yarn build:esm +# Set all packages in the repo to point to their siblings as file dependencies. That way, when we install the local copy +# of @sentry/nextjs, it'll pull the local copy of each of its @sentry/* dependents. This mimics what Lerna does with +# symlinks, just with file dependencies (which we have to use because linking seems to lead to module resolution +# errors). +echo " " +echo "POINTING SIBLING DEPENDENCIES IN PACKAGE.JSON AT LOCAL DIRECTORIES" +PACKAGES_DIR="$REPO_DIR/packages" +# Escape all of the slashes in the path for use in sed +ESCAPED_PACKAGES_DIR=$(echo $PACKAGES_DIR | sed s/'\/'/'\\\/'/g) + +# Get the names of all of the packages +package_names=() +for abs_package_path in ${PACKAGES_DIR}/*; do + package_names+=($(basename $abs_package_path)) +done + +# Modify each package's package.json file by searching in it for sentry dependencies from the monorepo and, for each +# sibling dependency found, replacing the version number with a file dependency pointing to the sibling itself (so +# `"@sentry/utils": "6.9.0"` becomes `"@sentry/utils": "file:/abs/path/to/sentry-javascript/packages/utils"`) +for package in ${package_names[@]}; do + cd ${PACKAGES_DIR}/${package} + + # Within a given package.json file, search for each of the other packages in turn, and if found, make the replacement + for package_dep in ${package_names[@]}; do + sed -Ei /"@sentry\/${package_dep}"/s/"[0-9]+\.[0-9]+\.[0-9]+"/"file:${ESCAPED_PACKAGES_DIR}\/${package_dep}"/ package.json + done +done + echo " " echo "MOVING BACK TO PROJECT DIRECTORY" cd $PROJECT_DIR From 0729817aeca4da0355be090564d8af6761758dc4 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 16 Jul 2021 15:23:08 -0700 Subject: [PATCH 7/7] code review fixes --- .../nextjs/vercel/install-sentry-from-branch.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/nextjs/vercel/install-sentry-from-branch.sh b/packages/nextjs/vercel/install-sentry-from-branch.sh index 0c1f594034c3..f54c1ab7ce30 100644 --- a/packages/nextjs/vercel/install-sentry-from-branch.sh +++ b/packages/nextjs/vercel/install-sentry-from-branch.sh @@ -43,21 +43,15 @@ PACKAGES_DIR="$REPO_DIR/packages" # Escape all of the slashes in the path for use in sed ESCAPED_PACKAGES_DIR=$(echo $PACKAGES_DIR | sed s/'\/'/'\\\/'/g) -# Get the names of all of the packages -package_names=() -for abs_package_path in ${PACKAGES_DIR}/*; do - package_names+=($(basename $abs_package_path)) -done +PACKAGE_NAMES=$(ls PACKAGES_DIR) # Modify each package's package.json file by searching in it for sentry dependencies from the monorepo and, for each # sibling dependency found, replacing the version number with a file dependency pointing to the sibling itself (so # `"@sentry/utils": "6.9.0"` becomes `"@sentry/utils": "file:/abs/path/to/sentry-javascript/packages/utils"`) -for package in ${package_names[@]}; do - cd ${PACKAGES_DIR}/${package} - +for package in $PACKAGE_NAMES; do # Within a given package.json file, search for each of the other packages in turn, and if found, make the replacement - for package_dep in ${package_names[@]}; do - sed -Ei /"@sentry\/${package_dep}"/s/"[0-9]+\.[0-9]+\.[0-9]+"/"file:${ESCAPED_PACKAGES_DIR}\/${package_dep}"/ package.json + for package_dep in $PACKAGE_NAMES; do + sed -Ei /"@sentry\/${package_dep}"/s/"[0-9]+\.[0-9]+\.[0-9]+"/"file:${ESCAPED_PACKAGES_DIR}\/${package_dep}"/ ${PACKAGES_DIR}/${package}/package.json done done