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

fix(loader): provide js sdk assets from 4.x #3415

Merged
merged 10 commits into from
Nov 7, 2024

Conversation

aldy505
Copy link
Collaborator

@aldy505 aldy505 commented Nov 6, 2024

Hopefully fixes getsentry/sentry#22715 (comment)

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@aldy505
Copy link
Collaborator Author

aldy505 commented Nov 6, 2024

Pinging @dlouzan for visibility

@aldy505
Copy link
Collaborator Author

aldy505 commented Nov 6, 2024

I have no idea on why the unit test fails at a very random moment. Will revisit later.

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.01%. Comparing base (db21c6c) to head (8161971).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3415   +/-   ##
=======================================
  Coverage   99.01%   99.01%           
=======================================
  Files           3        3           
  Lines         203      203           
=======================================
  Hits          201      201           
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

fi

echo "Downloading JS SDK v${version} for ${variant}.min.js..."
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx curl --retry 3 -sLo /var/www/js-sdk/${version}/${variant}.min.js "https://browser.sentry-cdn.com/${version}/${variant}.min.js"
Copy link

Choose a reason for hiding this comment

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

I also ended up using curl in our adapted script; busybox's wget is crippled and weird, and doesn't play nice with corporate proxies.

latest_js_v7=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("7.")))) | .[0]')
latest_js_v8=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("8.")))) | .[0]')

echo "Found JS SDKs v${latest_js_v7} and v${latest_js_v8}, downloading from upstream.."
echo "Found JS SDKs: v${latest_js_v4}, v${latest_js_v5}, v${latest_js_v6}, v${latest_js_v7}, v${latest_js_v8}"
Copy link

Choose a reason for hiding this comment

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

I wonder what decides which versions are available, and how this script will be properly kept up to date with newer releases, as this does not do auto-discovery based on metadata 🙇

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's one JSON file that's always populated on Docker build time on the sentry container. (In which tested here https://github.com/getsentry/sentry/blob/fda38c5d70c4ef8c7340cfd5978d97ccf25b6674/self-hosted/Dockerfile#L85)

Copy link
Member

Choose a reason for hiding this comment

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

We can find the current versions at the time of installation from https://github.com/getsentry/sentry-release-registry/tree/master/packages/npm/%40sentry/browser

Co-authored-by: Burak Yigit Kaya <[email protected]>
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx mkdir -p /var/www/js-sdk/${version}
for variant in "tracing" "tracing.replay" "replay" "tracing.replay.feedback" "feedback"; do
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx wget -q -O /var/www/js-sdk/${version}/bundle.${variant}.min.js "https://browser.sentry-cdn.com/${version}/bundle.${variant}.min.js"
for variant in "bundle" "bundle.tracing" "bundle.tracing.replay" "bundle.replay" "bundle.tracing.replay.feedback" "bundle.feedback"; do
Copy link
Member

Choose a reason for hiding this comment

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

Better to pull this list out of the for loops for better visibility and modification in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done! Tests are green too

Comment on lines 39 to 43
status_code=$($dcr --no-deps --rm nginx curl --retry 3 --silent -I "https://browser.sentry-cdn.com/${version}/${variant}.min.js" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [[ "$status_code" != "200" ]]; then
echo "Skipping download of JS SDK v${version} for ${variant}.min.js, because the status code was ${status_code} (non 200)"
continue
fi
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use the -f/--fail flag yet (https://superuser.com/a/657174)

I think it was added in a newer version of curl so not sure if it would be available here. Would be great if it is though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The nginx image has the curl version of 8.1.x. Should be fine.

@aldy505
Copy link
Collaborator Author

aldy505 commented Nov 7, 2024

The unit test is so flaky. I don't know why.

if [[ "$status_code" != "200" ]]; then
echo "Skipping download of JS SDK v${version} for ${variant}.min.js, because the status code was ${status_code} (non 200)"
continue
fi

echo "Downloading JS SDK v${version} for ${variant}.min.js..."
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx curl --retry 3 -sLo /var/www/js-sdk/${version}/${variant}.min.js "https://browser.sentry-cdn.com/${version}/${variant}.min.js"
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx curl --retry 10 -sLo /var/www/js-sdk/${version}/${variant}.min.js "https://browser.sentry-cdn.com/${version}/${variant}.min.js"
Copy link
Member

Choose a reason for hiding this comment

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

These retries are sad :D

@BYK BYK merged commit 2a7abf2 into getsentry:master Nov 7, 2024
11 of 12 checks passed
@aldy505 aldy505 deleted the fix/js-loader-provide-4.x branch November 7, 2024 10:15
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Sentry JS lazily-loadable loader doesn't work
3 participants