Skip to content

Make it easier to expose Sentry API and tree shake at the same time #7713

Description

@rchl

Problem Statement

In Sentry Nuxt Module, there is a "Nuxt Context" object on which the module exposes the whole Sentry SDK API. It did that with a code like:

import*asSentryfrom'@sentry/vue'// ...ctx.$sentry=Sentry

The problem with that was that it would import everything from @sentry/vue which includes a bunch of stuff that shouldn't need to be exposed to module users or stuff like @sentry/replay that users are not even using (user would have to manually import this one to use it).

That bloated the client bundle (build by webpack 4) which I haven't noticed until recently.

So my solution that I have already implemented (but I'm not entirely happy about) was to do more targeted importing like:

import{init,Integrations,vueRouterInstrumentation}from'~@sentry/vue'import*asCoreSdkfrom'~@sentry/core'import*asBrowserSdkfrom'~@sentry/browser-sdk'// resolves to `@sentry/browser/esm/sdk.js`// ...constSentrySdk={ ...CoreSdk, ...BrowserSdk}ctx.$sentry=Sentry

And that works to keep the bundle at bay.

The potential problem with that is that I'm just guessing here in regards to which APIs should actually be exported to the user. I've picked the ones from @sentry/core and exports from a specific file in @sentry/browser. This doesn't seem that future proof as Sentry could export new important APIs somewhere else and I wouldn't know about those.

Solution Brainstorm

Create some official list of APIs (methods/properties) that the user should have access to. Ideally have a specific export in the package (like @sentry/vue in this case) that lists all exports that should be exposed at runtime. Not including things like @sentry/replay, of course.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions