Skip to content

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

Closed
@rchl

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 * as Sentry from '@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 * as CoreSdk from '~@sentry/core'
import * as BrowserSdk from '~@sentry/browser-sdk'  // resolves to `@sentry/browser/esm/sdk.js`
// ...
const SentrySdk = { ...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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions