Skip to content

Add a way to auto-detect JS package for imports #9013

@mydea

Description

@mydea

Currently, for code snippets in the JavaScript SDKs, if we want to have fully correct snippets for the different packages, you have to have a slightly different snippet for each:

// Browser JS
import * as Sentry from '@sentry/browser';

Sentry.init({
  // more stuff comes here...
});

vs.

// Browser JS
import * as Sentry from '@sentry/angular';

Sentry.init({
  // more stuff comes here...
});

etc. In many cases, the only thing that has to be changed is the package name itself. It would be very helpful to have a code helper similar to ___PUBLIC_DSN___ that could be used in a code block that would automatically resolve to the correct package - or some other way to solve this. I'm thinking of something like:

// Browser JS
import * as Sentry from '__SENTRY_JS_PACKAGE__';

Sentry.init({
  // more stuff comes here...
});

This would help to cut down on code duplication quite a lot. Noticed this again e.g. here: https://github.com/getsentry/sentry-docs/pull/9005 Where this is basically the only customization that has to be done for each package, but it makes keeping stuff in sync much harder.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions