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

feat(core): Deprecate parseUrl #14404

Closed
wants to merge 1 commit into from
Closed

feat(core): Deprecate parseUrl #14404

wants to merge 1 commit into from

Conversation

lforst
Copy link
Member

@lforst lforst commented Nov 21, 2024

Ref #14267

Deprecates and removes usages of parseUrl which can be replaced with the URL constructor with our current version support.

Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.78 KB -0.44% -102 B 🔽
@sentry/browser - with treeshaking flags 21.48 KB -0.44% -96 B 🔽
@sentry/browser (incl. Tracing) 35.41 KB -0.06% -20 B 🔽
@sentry/browser (incl. Tracing, Replay) 72.12 KB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.4 KB -0.03% -18 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 76.41 KB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 88.88 KB -0.02% -10 B 🔽
@sentry/browser (incl. Feedback) 39.51 KB -0.27% -106 B 🔽
@sentry/browser (incl. sendFeedback) 27.41 KB -0.37% -103 B 🔽
@sentry/browser (incl. FeedbackAsync) 32.22 KB -0.3% -98 B 🔽
@sentry/react 25.48 KB -0.41% -105 B 🔽
@sentry/react (incl. Tracing) 38.26 KB -0.07% -25 B 🔽
@sentry/vue 26.93 KB -0.38% -105 B 🔽
@sentry/vue (incl. Tracing) 37.23 KB -0.05% -16 B 🔽
@sentry/svelte 22.91 KB -0.51% -119 B 🔽
CDN Bundle 23.95 KB -0.4% -97 B 🔽
CDN Bundle (incl. Tracing) 36.98 KB -0.03% -11 B 🔽
CDN Bundle (incl. Tracing, Replay) 71.67 KB -0.03% -22 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 77.02 KB -0.04% -28 B 🔽
CDN Bundle - uncompressed 70.72 KB -0.27% -190 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 110.15 KB +0.03% +28 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 222.68 KB +0.02% +28 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 235.89 KB +0.02% +28 B 🔺
@sentry/nextjs (client) 38.36 KB -0.08% -31 B 🔽
@sentry/sveltekit (client) 35.92 KB -0.05% -16 B 🔽
@sentry/node 134.41 KB -0.06% -74 B 🔽
@sentry/node - without tracing 96.25 KB -0.07% -65 B 🔽
@sentry/aws-serverless 106.5 KB -0.07% -72 B 🔽

View base workflow run

Copy link

codecov bot commented Nov 21, 2024

❌ 17 Tests Failed:

Tests completed Failed Passed Skipped
653 17 636 28
View the top 3 failed tests by shortest run time
transactions.test.ts Sends an API route transaction
Stack Traces | 0.021s run time
transactions.test.ts:4:5 Sends an API route transaction
transactions.test.ts Sends an API route transaction from module
Stack Traces | 0.021s run time
transactions.test.ts:4:5 Sends an API route transaction from module
transactions.test.ts Sends successful transaction
Stack Traces | 0.028s run time
transactions.test.ts:4:5 Sends successful transaction

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

attributes['server.address'] = parsedUrl.host;
try {
// The URL constructor can throw when there is no protocol or host.
const parsedUrl = new URL(resourceUrl);
Copy link
Member

Choose a reason for hiding this comment

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

can resourceUrl be a path-only, without a host? 🤔 just double checking.

if (parsedUrl.protocol) {
attributes['url.scheme'] = parsedUrl.protocol.split(':').pop(); // the protocol returned by parseUrl includes a :, but OTEL spec does not, so we remove it.
}
if (parsedUrl.host) {
Copy link
Member

Choose a reason for hiding this comment

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

can host even be empty? 🤔

try {
// The URL constructor can throw when there is no protocol or host.
const parsedUrl = new URL(resourceUrl);
if (parsedUrl.protocol) {
Copy link
Member

Choose a reason for hiding this comment

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

can protocol be empty?

let parsedFrom = from ? parseUrl(from) : undefined;
const parsedTo = parseUrl(to);
let parsedFrom = from ? new URL(from, DUMMY_URL_BASE) : undefined;
const parsedTo = new URL(to, DUMMY_URL_BASE);
Copy link
Member

Choose a reason for hiding this comment

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

we should always try-catch this, to avoid stuff blowing up IMHO!

const attributes: SpanAttributes = {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.bun.serve',
[SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD]: request.method || 'GET',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
};

const parsedUrl = new URL(request.url, DUMMY_URL_BASE);
Copy link
Member

Choose a reason for hiding this comment

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

try-catch, maybe?

@mydea
Copy link
Member

mydea commented Nov 21, 2024

IMHO this is fine, but:

  1. let's always try-catch new URL( calls to ensure we do not throw for weird input or so.
  2. Let's also make sure we do not regress anything by not handling relative paths only. Now, we seem to handle it sometimes, but not always.

Generally I wonder if it would not be easier/better to just let the method be and just rewrite it to use new URL under the hood 😅 then we could centralize/streamline both points I mentioned above. I'm also fine with repeating this everywhere we use this, but it does feel a bit boiler-platey to me 🤷

@lforst
Copy link
Member Author

lforst commented Nov 22, 2024

Generally I wonder if it would not be easier/better to just let the method be and just rewrite it to use new URL under the hood 😅 then we could centralize/streamline both points I mentioned above. I'm also fine with repeating this everywhere we use this, but it does feel a bit boiler-platey to me 🤷

I had the exact same thought today, the only problem I had with it was that it is maybe too generic to be exported as API from a Sentry package. At the same time, nobody probably cares.

@lforst
Copy link
Member Author

lforst commented Nov 22, 2024

Let's keep this funciton and replace the implementation with URL in a non-breaking way.

@lforst lforst closed this Nov 22, 2024
@lforst lforst deleted the lforst-rm-parseUrl branch December 3, 2024 09:54
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.

3 participants