Skip to content

Commit

Permalink
feat(sourcemaps): Add --use-debug-ids flag to force Artifact Bundles …
Browse files Browse the repository at this point in the history
…usage (#1557)

Co-authored-by: Riccardo Busetti <riccardob36@gmail.com>
  • Loading branch information
kamilogorek and iambriccardo authored Apr 3, 2023
1 parent 3ec0445 commit 412d0b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
3 changes: 0 additions & 3 deletions js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ async function execute(args, live, silent, configFile, config = {}) {
if (config.vcsRemote) {
env.SENTRY_VCS_REMOTE = config.vcsRemote;
}
if (config.forceArtifactBundles) {
env.SENTRY_FORCE_ARTIFACT_BUNDLES = config.forceArtifactBundles;
}
if (config.customHeader) {
env.CUSTOM_HEADER = config.customHeader;
} else if (config.headers) {
Expand Down
10 changes: 4 additions & 6 deletions js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ declare module '@sentry/cli' {
* If true, all logs are suppressed.
*/
silent?: boolean;
/**
* Whether to use the debug ID method of uploading source maps.
* This value will update `SENTRY_FORCE_ARTIFACT_BUNDLES` env variable.
* @experimental
*/
forceArtifactBundles?: string;
/**
* A header added to every outgoing network request.
* This value will update `CUSTOM_HEADER` env variable.
Expand Down Expand Up @@ -129,6 +123,10 @@ declare module '@sentry/cli' {
* Usually your build number.
*/
dist?: string;
/**
* Use new Artifact Bundles upload, that enables use of Debug ID for Source Maps discovery.
*/
useDebugIds?: boolean;
}

export interface SentryCliNewDeployOptions {
Expand Down
4 changes: 4 additions & 0 deletions js/releases/options/uploadSourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ module.exports = {
param: '--ext',
type: 'array',
},
useDebugIds: {
param: '--use-debug-ids',
type: 'boolean',
},
};
10 changes: 1 addition & 9 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,15 +1125,7 @@ impl Api {
.get(&url)?
.convert_rnf::<ChunkUploadOptions>(ApiErrorKind::ChunkUploadNotSupported)
{
Ok(mut options) => {
// TODO: remove this logic after we can trust the server responses
if !options.supports(ChunkUploadCapability::ArtifactBundles)
&& env::var("SENTRY_FORCE_ARTIFACT_BUNDLES").ok().as_deref() == Some("1")
{
options.accept.push(ChunkUploadCapability::ArtifactBundles);
}
Ok(Some(options))
}
Ok(options) => Ok(Some(options)),
Err(error) => {
if error.kind() == ApiErrorKind::ChunkUploadNotSupported {
Ok(None)
Expand Down
42 changes: 23 additions & 19 deletions src/commands/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
use glob::{glob_with, MatchOptions};
use log::{debug, warn};

use crate::api::Api;
use crate::api::{Api, ChunkUploadCapability};
use crate::config::Config;
use crate::utils::args::validate_distribution;
use crate::utils::file_search::ReleaseFileSearch;
Expand Down Expand Up @@ -180,6 +180,17 @@ pub fn make_command(command: Command) -> Command {
Defaults to: `--ext=js --ext=map --ext=jsbundle --ext=bundle`",
),
)
// NOTE: Hidden until we decide to expose it publicly
.arg(
Arg::new("use_debug_ids")
.long("use-debug-ids")
.action(ArgAction::SetTrue)
.help(
"Use new Artifact Bundles upload, that enables the use of Debug IDs \
for Source Maps discovery.",
)
.hide(true),
)
// Legacy flag that has no effect, left hidden for backward compatibility
.arg(
Arg::new("rewrite")
Expand All @@ -195,17 +206,6 @@ pub fn make_command(command: Command) -> Command {
.short('v')
.hide(true),
)
// NOTE: Hidden until we decide to expose it publicly
.arg(
Arg::new("no_inject")
.long("no-inject")
.action(ArgAction::SetTrue)
.help(
"Skip injection of debug ids into source files \
and sourcemaps prior to uploading.",
)
.hide(true),
)
}

fn get_prefixes_from_args(matches: &ArgMatches) -> Vec<&str> {
Expand Down Expand Up @@ -353,12 +353,6 @@ fn process_sources_from_paths(
}
}

if env::var("SENTRY_FORCE_ARTIFACT_BUNDLES").ok().as_deref() == Some("1")
&& !matches.get_flag("no_inject")
{
processor.inject_debug_ids(false)?;
}

if !matches.get_flag("no_rewrite") {
let prefixes = get_prefixes_from_args(matches);
processor.rewrite(&prefixes)?;
Expand All @@ -381,7 +375,17 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let (org, project) = config.get_org_and_project(matches)?;
let api = Api::current();
let mut processor = SourceMapProcessor::new();
let chunk_upload_options = api.get_chunk_upload_options(&org)?;
let mut chunk_upload_options = api.get_chunk_upload_options(&org)?;

if matches.get_flag("use_debug_ids")
|| env::var("SENTRY_FORCE_ARTIFACT_BUNDLES").ok().as_deref() == Some("1")
{
if let Some(ref mut options) = chunk_upload_options {
if !options.supports(ChunkUploadCapability::ArtifactBundles) {
options.accept.push(ChunkUploadCapability::ArtifactBundles);
}
}
}

if matches.contains_id("bundle") && matches.contains_id("bundle_sourcemap") {
process_sources_from_bundle(matches, &mut processor)?;
Expand Down

0 comments on commit 412d0b3

Please sign in to comment.