Skip to content

feat(core): Streamline SpanJSON type #14693

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

Merged
merged 4 commits into from
Dec 16, 2024
Merged

feat(core): Streamline SpanJSON type #14693

merged 4 commits into from
Dec 16, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 13, 2024

Previously spanToJSON would return Partial<SpanJSON>. This meant that you always had to guard all the stuff you picked from it - even though in reality, we know that certain stuff will always be there.

To alleviate this, this PR changes this so that spanToJSON actually returns SpanJSON. This means that in the fallback case, we return data: {}, as well as a random (current) timestamp. Since we know that in reality we will only have the two scenarios that we properly handle, this is fine IMHO and makes usage of this everywhere else a little bit less painful.

In a follow up, we can get rid of a bunch of const data = spanToJSON(span).data || {} type code.

While at it, I also updated the type of data to SpanAttributes, which is correct (it was Record<string, any> before). Since we only allow span attributes to be set on this anyhow now, we can type this better. This also uncovered a few places with slightly "incorrect" type checks, I updated those too.

This change is on the v9 branch - I think it should not really be breaking to a user in any way, as we simply return more data from spanToJSON, and type what data is on there more tightly, so no existing code relying on this should break. But to be safe, I figured we may as well do that on v9 only.

@mydea mydea requested review from lforst and AbhiPrasad December 13, 2024 08:36
@mydea mydea self-assigned this Dec 13, 2024
Copy link
Contributor

github-actions bot commented Dec 13, 2024

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.27 KB - -
@sentry/browser - with treeshaking flags 21.95 KB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing) 35.79 KB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Replay) 73.02 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 63.4 KB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 77.44 KB +0.01% +2 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 89.82 KB +0.01% +1 B 🔺
@sentry/browser (incl. Feedback) 40.03 KB +0.01% +1 B 🔺
@sentry/browser (incl. sendFeedback) 27.88 KB +0.01% +1 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.67 KB +0.01% +1 B 🔺
@sentry/react 25.95 KB +0.01% +2 B 🔺
@sentry/react (incl. Tracing) 38.59 KB +0.01% +3 B 🔺
@sentry/vue 27.48 KB +0.01% +1 B 🔺
@sentry/vue (incl. Tracing) 37.62 KB +0.01% +1 B 🔺
@sentry/svelte 23.44 KB +0.01% +2 B 🔺
CDN Bundle 24.42 KB +0.02% +3 B 🔺
CDN Bundle (incl. Tracing) 37.45 KB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay) 72.54 KB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 77.92 KB -0.01% -2 B 🔽
CDN Bundle - uncompressed 71.71 KB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 111.02 KB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 225.07 KB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 238.28 KB +0.01% +3 B 🔺
@sentry/nextjs (client) 38.87 KB +0.01% +3 B 🔺
@sentry/sveltekit (client) 36.28 KB - -
@sentry/node 162.69 KB +0.02% +30 B 🔺
@sentry/node - without tracing 98.86 KB +0.01% +6 B 🔺
@sentry/aws-serverless 126.59 KB - -

View base workflow run

@mydea mydea force-pushed the fn/span-no-optional-data branch from 7fba7db to faa37de Compare December 16, 2024 07:56
@mydea mydea changed the base branch from v9 to develop December 16, 2024 07:56
@mydea mydea enabled auto-merge (squash) December 16, 2024 07:56
@mydea mydea force-pushed the fn/span-no-optional-data branch from faa37de to fb7efb9 Compare December 16, 2024 08:10
@mydea mydea merged commit 655e8a7 into develop Dec 16, 2024
158 checks passed
@mydea mydea deleted the fn/span-no-optional-data branch December 16, 2024 08:54
mydea added a commit that referenced this pull request Dec 17, 2024
Since this was reworked in
#14693 to always
return something, we can safe some checks/fallbacks.

This most likely does not change all the things, but focuses on the
places that were easy to find/replace.
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.

None yet

4 participants