Skip to content

Commit 48080b4

Browse files
robertcepaLuca Forstner
andauthored
feat(core): Add headers option (#153)
Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
1 parent a7b5e14 commit 48080b4

File tree

11 files changed

+50
-96
lines changed

11 files changed

+50
-96
lines changed

packages/bundler-plugin-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"fix": "eslint ./src ./test --format stylish --fix"
4242
},
4343
"dependencies": {
44-
"@sentry/cli": "^1.74.6",
44+
"@sentry/cli": "^2.10.0",
4545
"@sentry/node": "^7.19.0",
4646
"@sentry/tracing": "^7.19.0",
4747
"magic-string": "0.27.0",

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type OptionalInternalOptions = Partial<
2929
| "deploy"
3030
| "configFile"
3131
| "customHeader"
32+
| "headers"
3233
>
3334
>;
3435

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

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

packages/bundler-plugin-core/src/sentry/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ export type SentryCLILike = SentryCli | SentryDryRunCLI;
1515
* that makes no-ops out of most CLI operations
1616
*/
1717
export function getSentryCli(internalOptions: InternalOptions, logger: Logger): SentryCLILike {
18-
const { silent, org, project, authToken, url, vcsRemote, customHeader, dist } = internalOptions;
18+
const { silent, org, project, authToken, url, vcsRemote, customHeader, headers } =
19+
internalOptions;
1920
const cli = new SentryCli(internalOptions.configFile, {
2021
url,
2122
authToken,
2223
org,
2324
project,
2425
vcsRemote,
25-
dist,
2626
silent,
2727
customHeader,
28+
headers,
2829
});
2930

3031
if (internalOptions.dryRun) {

packages/bundler-plugin-core/src/sentry/releasePipeline.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export async function uploadSourceMaps(
6767
// Since our internal include entries contain all top-level sourcemaps options,
6868
// we only need to pass the include option here.
6969
try {
70-
await ctx.cli.releases.uploadSourceMaps(releaseName, { include: options.include });
70+
await ctx.cli.releases.uploadSourceMaps(releaseName, {
71+
include: options.include,
72+
dist: options.dist,
73+
});
7174
} catch (e) {
7275
ctx.hub.captureException(new Error("CLI Error: Uploading source maps failed"));
7376
throw e;

packages/bundler-plugin-core/src/sentry/telemetry.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,18 @@ export function addPluginOptionInformationToHub(
137137
}
138138

139139
export async function shouldSendTelemetry(options: InternalOptions): Promise<boolean> {
140-
const { silent, org, project, authToken, url, vcsRemote, customHeader, dist, telemetry, dryRun } =
141-
options;
140+
const {
141+
silent,
142+
org,
143+
project,
144+
authToken,
145+
url,
146+
vcsRemote,
147+
customHeader,
148+
headers,
149+
telemetry,
150+
dryRun,
151+
} = options;
142152

143153
// `options.telemetry` defaults to true
144154
if (telemetry === false) {
@@ -159,9 +169,9 @@ export async function shouldSendTelemetry(options: InternalOptions): Promise<boo
159169
org,
160170
project,
161171
vcsRemote,
162-
dist,
163172
silent,
164173
customHeader,
174+
headers,
165175
});
166176

167177
let cliInfo;

packages/bundler-plugin-core/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ export type Options = Omit<IncludeEntry, "paths"> & {
116116
*/
117117
customHeader?: string;
118118

119+
/**
120+
* Headers added to every outgoing network request.
121+
* This value does not set any env variable, and is overridden by customHeader.
122+
*/
123+
headers?: Record<string, string>;
124+
119125
/**
120126
* Attempts a dry run (useful for dev environments), making release creation
121127
* a no-op.

packages/esbuild-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The Sentry Esbuild Plugin takes an options argument with the following propertie
5959
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
6060
| 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. |
6161
| 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. |
62+
| 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`. |
6263
| 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. |
6364
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
6465
| 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**). |

packages/rollup-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The Sentry Rollup Plugin takes an options argument with the following properties
5959
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
6060
| 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. |
6161
| 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. |
62+
| 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`. |
6263
| 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. |
6364
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
6465
| 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**). |

packages/vite-plugin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The Sentry Vite Plugin takes an options argument with the following properties:
5959
| project | `string` | optional | The slug of the Sentry project associated with the app. Can also be specified via the `SENTRY_PROJECT` environment variable. |
6060
| 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. |
6161
| 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. |
62+
| 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`. |
6263
| 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. |
6364
| vcsRemote | `string` | optional | Version control system remote name. This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable. Defaults to `'origin'`. |
6465
| 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. |

0 commit comments

Comments
 (0)