Skip to content

feat(cloudflare): Improve http span data #16232

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

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

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented May 7, 2025

While helping debug work in https://github.com/getsentry/sentry-mcp, I noticed that we didn't attach url.path to the http fetch spans, which made using the trace explorer harder to use.

This PR updates the cloudflare http instrumentation (fetch handlers for regular workers and durable objects) to use a new getHttpSpanDetailsFromUrlObject abstraction I built.

getHttpSpanDetailsFromUrlObject returns the http span name and it's associated attributes, taking care to handle source, route names, and handling both relative and full URLs.

This is related to all the #15767 work I've been doing.

@AbhiPrasad AbhiPrasad requested a review from a team May 7, 2025 23:09
@AbhiPrasad AbhiPrasad self-assigned this May 7, 2025
@AbhiPrasad AbhiPrasad requested review from lforst and RulaKhaled and removed request for a team May 7, 2025 23:09
Copy link
Contributor

github-actions bot commented May 8, 2025

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 23.35 KB - -
@sentry/browser - with treeshaking flags 23.19 KB - -
@sentry/browser (incl. Tracing) 37.26 KB +0.03% +11 B 🔺
@sentry/browser (incl. Tracing, Replay) 74.48 KB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.34 KB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 79.13 KB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 90.94 KB +0.01% +3 B 🔺
@sentry/browser (incl. Feedback) 39.75 KB - -
@sentry/browser (incl. sendFeedback) 27.98 KB - -
@sentry/browser (incl. FeedbackAsync) 32.74 KB - -
@sentry/react 25.16 KB - -
@sentry/react (incl. Tracing) 39.25 KB +0.03% +10 B 🔺
@sentry/vue 27.63 KB - -
@sentry/vue (incl. Tracing) 39.02 KB +0.03% +11 B 🔺
@sentry/svelte 23.38 KB - -
CDN Bundle 24.55 KB - -
CDN Bundle (incl. Tracing) 37.31 KB +0.04% +14 B 🔺
CDN Bundle (incl. Tracing, Replay) 72.34 KB +0.02% +8 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.65 KB +0.01% +6 B 🔺
CDN Bundle - uncompressed 71.62 KB - -
CDN Bundle (incl. Tracing) - uncompressed 110.36 KB +0.03% +23 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 221.65 KB +0.02% +23 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 234.17 KB +0.01% +23 B 🔺
@sentry/nextjs (client) 40.86 KB +0.04% +15 B 🔺
@sentry/sveltekit (client) 37.75 KB +0.04% +14 B 🔺
@sentry/node 151.37 KB - -
@sentry/node - without tracing 95.77 KB -0.01% -1 B 🔽
@sentry/aws-serverless 120.16 KB - -

View base workflow run

@AbhiPrasad AbhiPrasad force-pushed the abhi-improve-cloudflare-context branch from 0aa0999 to 52b7884 Compare May 8, 2025 22:37
*/
export function getHttpSpanDetailsFromUrlObject(
urlObject: URLObject | undefined,
kind: 'server' | 'client',
Copy link
Member Author

Choose a reason for hiding this comment

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

I know during our bikeshedding session we said we wanted to get rid of this, but I had to add it back so that we could generate the name correctly.

See the getHttpSpanNameFromUrlObject implementation.

@@ -53,7 +61,7 @@ export function isURLObjectRelative(url: URLObject): url is RelativeURL {
* @returns The parsed URL object or undefined if the URL is invalid
*/
export function parseStringToURLObject(url: string, urlBase?: string | URL | undefined): URLObject | undefined {
const isRelative = url.startsWith('/');
const isRelative = url.indexOf('://') <= 0 && url.indexOf('//') !== 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

This check is now much more robust. I've added way more tests for this as well.

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.

1 participant