You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ref(tracing): Split @sentry/tracing into runtime specific packages #5815
After some discussions around supporting newer JavaScript runtimes (#5611) @lforst pointed out the first thing that needs tackling is @sentry/tracing!
This package currently contains:
Runtime agnostic code used to add transaction support to the hub
Browser specific instrumentation code
Node.js specific instrumentation code
Goal: Remove the tracing package, move stuff into core/browser/node
Solution Brainstorm
It looks like the runtime agnostic code can safely be moved to @sentry/core without affecting bundle sizes since if it goes unused it gets tree-shaken.
The runtime specific code could be moved into package exports under the specific runtime, ie. @sentry/browser/tracing and @sentry/node/tracing. We've been using this in the Electron SDK for a while to keep bundlers happy with the two different contexts we run in. We can't export the tracing code at the root of the packages since importing tracing has side-effects!
I haven't marked this issue as Breaking yet because I think it would be possible to move this code while keeping @sentry/tracing as a stub that would simply re-export the moved code. @sentry/tracing would have to depend on both @sentry/browser and @sentry/node so I'm not sure how viable this is yet or if it's worth that extra step 🤔
Would we want to add all the hub extensions by default too?
I think so. Ideally, we wouldn't need hub extensions anymore since it's all already there.
We wouldn't want to run _autoloadDatabaseIntegrations in the Electron SDK because it hits app startup time significantly!
We had an internal discussion about this some time ago and we would like to turn off auto-discovery by default for the next major because of the startup time.
If we move the existing runtime agnostic code over to @sentry/core without any significant changes and simply export the existing code there is no change to browser bundle size since it's just a load of isolated functions.
I still need to do some experimentation to see how much it adds if the code is fully integrated to the hub without extensions. I would guess this could add 5-10kB since the code ends up in the Hub class where tree shaking can't works its magic.
I did the experimenting and moved tracing into @sentry/core and moved the code into Hub (removing hub extensions) and it adds roughly 7kB to the minified, uncompressed browser bundle (bundle.min.js).
This PR on my fork shows how the runtime agnostic code from @sentry/tracing can be moved to @sentry/core without impacting bundle size. This is possible because it retains the use of hub extensions and the tracing code is not referenced by @sentry/core so it can be tree-shaken.
A possible option we can take on here is to create a new tracing package - and then make @sentry/tracing, @sentry/node and @sentry/browser all import from that new package.
This new package can export everything without side effects so it can be tree-shaken/not slow down the node package.
It's been a while, but I think we worked around the older bundler issues while still having named package exports with the Electron SDK by outputting the cjs build output into correctly named directories in the root of the package.
We don't actually have any webpack 4 e2e tests, but I just did some quick testing and with the above, both const { init } = require('@sentry/electron/renderer'); and import { init } from '@sentry/electron/renderer'; work with webpack 4.
The major downside here is that cjs gets used and therefore no tree shaking occurs. In the case of the Electron SDK, this means that all the session replay code gets bundled. cjs is no doubt why we've seen issues like this even when Replay isn't used.
We need to think about what types need re-exporting from node/browser from @sentry/core. getActiveTransaction is the obvious one but I'm sure there are more.
Once the migration is complete, but before we add any deprecation jsdocs, we'll try to migrate all the Sentry packages to use node/browser rather than tracing. This should give us a good idea of what exports we need!
Since we've removed @sentry/tracing from all the sdks that use it, and migrated the imports to node/core/browser accordingly, I think we can consider this done.
Next up is docs work in getsentry/sentry-docs#6518 and final deprecation in #7586, but we can use those issues to track this.
Activity
lforst commentedon Sep 26, 2022
Continuing the thread from #5611 (comment):
I think so. Ideally, we wouldn't need hub extensions anymore since it's all already there.
We had an internal discussion about this some time ago and we would like to turn off auto-discovery by default for the next major because of the startup time.
timfish commentedon Sep 26, 2022
If we move the existing runtime agnostic code over to
@sentry/corewithout any significant changes and simply export the existing code there is no change to browser bundle size since it's just a load of isolated functions.I still need to do some experimentation to see how much it adds if the code is fully integrated to the hub without extensions. I would guess this could add 5-10kB since the code ends up in the
Hubclass where tree shaking can't works its magic.timfish commentedon Sep 27, 2022
I did the experimenting and moved tracing into
@sentry/coreand moved the code intoHub(removing hub extensions) and it adds roughly 7kB to the minified, uncompressed browser bundle (bundle.min.js).timfish commentedon Oct 5, 2022
This PR on my fork shows how the runtime agnostic code from
@sentry/tracingcan be moved to@sentry/corewithout impacting bundle size. This is possible because it retains the use of hub extensions and the tracing code is not referenced by@sentry/coreso it can be tree-shaken.1 remaining item
AbhiPrasad commentedon Mar 7, 2023
After doing some experimenting, we cannot use the approach in #7345 because this would break older bundlers.
AbhiPrasad commentedon Mar 7, 2023
As per #7372, we must do this change in v8
AbhiPrasad commentedon Mar 9, 2023
A possible option we can take on here is to create a new tracing package - and then make
@sentry/tracing,@sentry/nodeand@sentry/browserall import from that new package.This new package can export everything without side effects so it can be tree-shaken/not slow down the node package.
mydea commentedon Mar 9, 2023
IMHO that can be fine, we can make the package purely private/internal, so it would really just be an implementation detail!
timfish commentedon Mar 10, 2023
It's been a while, but I think we worked around the older bundler issues while still having named package exports with the Electron SDK by outputting the cjs build output into correctly named directories in the root of the package.
We don't actually have any webpack 4 e2e tests, but I just did some quick testing and with the above, both
const { init } = require('@sentry/electron/renderer');andimport { init } from '@sentry/electron/renderer';work with webpack 4.The major downside here is that cjs gets used and therefore no tree shaking occurs. In the case of the Electron SDK, this means that all the session replay code gets bundled. cjs is no doubt why we've seen issues like this even when Replay isn't used.
AbhiPrasad commentedon Mar 10, 2023
This is what I ran into, and unfortunately means we can't move forward with this for the stock browser package.
timfish commentedon Mar 13, 2023
Once the above two linked PRs are merged, I'm guessing the next steps go something like:
BrowserTracingand related consts/types from@sentry/browser@sentry/browser@sentry/node@sentry/tracingFor v8
@sentry/tracingpackageAbhiPrasad commentedon Mar 14, 2023
@timfish one thing we'll have to consider is hub extensions and auto discovery of database integrations.
We'll want to make sure the flow looks like so:
Browser
If you don't want to use
BrowserTracing, you'll have to add the tracing extensions yourself:Node
timfish commentedon Mar 17, 2023
We need to think about what types need re-exporting from node/browser from
@sentry/core.getActiveTransactionis the obvious one but I'm sure there are more.Once the migration is complete, but before we add any deprecation jsdocs, we'll try to migrate all the Sentry packages to use node/browser rather than tracing. This should give us a good idea of what exports we need!
AbhiPrasad commentedon Mar 23, 2023
Since we've removed
@sentry/tracingfrom all the sdks that use it, and migrated the imports to node/core/browser accordingly, I think we can consider this done.Next up is docs work in getsentry/sentry-docs#6518 and final deprecation in #7586, but we can use those issues to track this.