Skip to content
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

feat(core): Add headers option #153

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bundler-plugin-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"fix": "eslint ./src ./test --format stylish --fix"
},
"dependencies": {
"@sentry/cli": "^1.74.6",
"@sentry/cli": "^2.10.0",
"@sentry/node": "^7.19.0",
"@sentry/tracing": "^7.19.0",
"magic-string": "0.27.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/bundler-plugin-core/src/options-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type OptionalInternalOptions = Partial<
| "deploy"
| "configFile"
| "customHeader"
| "headers"
>
>;

Expand Down Expand Up @@ -101,6 +102,7 @@ export function normalizeUserOptions(userOptions: UserOptions): InternalOptions
// In the spirit of maximum compatibility, we allow both here.
customHeader:
userOptions.customHeader ?? process.env["SENTRY_HEADER"] ?? process.env["CUSTOM_HEADER"],
headers: userOptions.headers,

vcsRemote: userOptions.vcsRemote, // env var: `SENTRY_VSC_REMOTE`

Expand Down
5 changes: 3 additions & 2 deletions packages/bundler-plugin-core/src/sentry/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export type SentryCLILike = SentryCli | SentryDryRunCLI;
* that makes no-ops out of most CLI operations
*/
export function getSentryCli(internalOptions: InternalOptions, logger: Logger): SentryCLILike {
const { silent, org, project, authToken, url, vcsRemote, customHeader, dist } = internalOptions;
const { silent, org, project, authToken, url, vcsRemote, customHeader, headers } =
internalOptions;
const cli = new SentryCli(internalOptions.configFile, {
url,
authToken,
org,
project,
vcsRemote,
dist,
silent,
customHeader,
headers,
});

if (internalOptions.dryRun) {
Expand Down
5 changes: 4 additions & 1 deletion packages/bundler-plugin-core/src/sentry/releasePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export async function uploadSourceMaps(
// Since our internal include entries contain all top-level sourcemaps options,
// we only need to pass the include option here.
try {
await ctx.cli.releases.uploadSourceMaps(releaseName, { include: options.include });
await ctx.cli.releases.uploadSourceMaps(releaseName, {
include: options.include,
dist: options.dist,
});
} catch (e) {
ctx.hub.captureException(new Error("CLI Error: Uploading source maps failed"));
throw e;
Expand Down
16 changes: 13 additions & 3 deletions packages/bundler-plugin-core/src/sentry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,18 @@ export function addPluginOptionInformationToHub(
}

export async function shouldSendTelemetry(options: InternalOptions): Promise<boolean> {
const { silent, org, project, authToken, url, vcsRemote, customHeader, dist, telemetry, dryRun } =
options;
const {
silent,
org,
project,
authToken,
url,
vcsRemote,
customHeader,
headers,
telemetry,
dryRun,
} = options;

// `options.telemetry` defaults to true
if (telemetry === false) {
Expand All @@ -159,9 +169,9 @@ export async function shouldSendTelemetry(options: InternalOptions): Promise<boo
org,
project,
vcsRemote,
dist,
silent,
customHeader,
headers,
});

let cliInfo;
Expand Down
6 changes: 6 additions & 0 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ export type Options = Omit<IncludeEntry, "paths"> & {
*/
customHeader?: string;

/**
* Headers added to every outgoing network request.
* This value does not set any env variable, and is overridden by customHeader.
*/
headers?: Record<string, string>;

/**
* Attempts a dry run (useful for dev environments), making release creation
* a no-op.
Expand Down
1 change: 1 addition & 0 deletions packages/esbuild-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The Sentry Esbuild Plugin takes an options argument with the following propertie
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
| authToken | `string` | optional | The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes: `project:releases` (and `org:read` if `setCommits` option is used). Can also be specified via the `SENTRY_AUTH_TOKEN` env variable. |
| url | `string` | optional | The base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io. This value can also be set via the `SENTRY_URL` environment variable. Defaults to https://sentry.io/, which is the correct value for SaaS customers. |
| headers | `Record<string, string>` | optional | Headers added to every outgoing network request. This value does not set any env variable, and is overridden by `customHeader`. |
| customHeader | `string` | optional | A header added to every outgoing network request. The format should be `header-key: header-value`. This value can also be specified via the `CUSTOM_HEADER` environment variable. |
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
| release | `string` | optional | Unique identifier for the release. This value can also be specified via the `SENTRY_RELEASE` environment variable. Defaults to the output of the `sentry-cli releases propose-version` command, which automatically detects values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git `HEAD`'s commit SHA. (**the latter requires access to `git` CLI and for the root directory to be a valid repository**). |
Expand Down
1 change: 1 addition & 0 deletions packages/rollup-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The Sentry Rollup Plugin takes an options argument with the following properties
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
| authToken | `string` | optional | The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes: `project:releases` (and `org:read` if `setCommits` option is used). Can also be specified via the `SENTRY_AUTH_TOKEN` env variable. |
| url | `string` | optional | The base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io. This value can also be set via the `SENTRY_URL` environment variable. Defaults to https://sentry.io/, which is the correct value for SaaS customers. |
| headers | `Record<string, string>` | optional | Headers added to every outgoing network request. This value does not set any env variable, and is overridden by `customHeader`. |
| customHeader | `string` | optional | A header added to every outgoing network request. The format should be `header-key: header-value`. This value can also be specified via the `CUSTOM_HEADER` environment variable. |
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
| release | `string` | optional | Unique identifier for the release. This value can also be specified via the `SENTRY_RELEASE` environment variable. Defaults to the output of the `sentry-cli releases propose-version` command, which automatically detects values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git `HEAD`'s commit SHA. (**the latter requires access to `git` CLI and for the root directory to be a valid repository**). |
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The Sentry Vite Plugin takes an options argument with the following properties:
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
| authToken | `string` | optional | The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes: `project:releases` (and `org:read` if `setCommits` option is used). Can also be specified via the `SENTRY_AUTH_TOKEN` env variable. |
| url | `string` | optional | The base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io. This value can also be set via the `SENTRY_URL` environment variable. Defaults to https://sentry.io/, which is the correct value for SaaS customers. |
| headers | `Record<string, string>` | optional | Headers added to every outgoing network request. This value does not set any env variable, and is overridden by `customHeader`. |
| customHeader | `string` | optional | A header added to every outgoing network request. The format should be `header-key: header-value`. This value can also be specified via the `CUSTOM_HEADER` environment variable. |
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
| releaseInjectionTargets | `array`/`RegExp`/`(string \| RegExp)[]`/`function(filePath: string): bool` | optional | Filter for modules that the release should be injected in. This option takes a string, a regular expression, or an array containing strings, regular expressions, or both. It's also possible to provide a filter function that takes the absolute path of a processed module. It should return `true` if the release should be injected into the module and `false` otherwise. String values of this option require a full match with the absolute path of the module. By default, the release will be injected into all modules - however, bundlers will include the injected release code only once per entrypoint. If release injection should be disabled, provide an empty array here. |
Expand Down
Loading