@@ -67,6 +67,15 @@ export type SentryBuildPluginManager = {
6767 */
6868 createRelease ( ) : Promise < void > ;
6969
70+ /**
71+ * Injects debug IDs into the build artifacts.
72+ *
73+ * This is a separate function from `uploadSourcemaps` because that needs to run before the sourcemaps are uploaded.
74+ * Usually the respective bundler-plugin will take care of this before the sourcemaps are uploaded.
75+ * Only use this if you need to manually inject debug IDs into the build artifacts.
76+ */
77+ injectDebugIds ( buildArtifactPaths : string [ ] ) : Promise < void > ;
78+
7079 /**
7180 * Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
7281 */
@@ -80,6 +89,24 @@ export type SentryBuildPluginManager = {
8089 createDependencyOnBuildArtifacts : ( ) => ( ) => void ;
8190} ;
8291
92+ function createCliInstance (
93+ options : NormalizedOptions ,
94+ additionalHeaders : Record < string , string > = { }
95+ ) : SentryCli {
96+ return new SentryCli ( null , {
97+ authToken : options . authToken ,
98+ org : options . org ,
99+ project : options . project ,
100+ silent : options . silent ,
101+ url : options . url ,
102+ vcsRemote : options . release . vcsRemote ,
103+ headers : {
104+ ...options . headers ,
105+ ...additionalHeaders ,
106+ } ,
107+ } ) ;
108+ }
109+
83110/**
84111 * Creates a build plugin manager that exposes primitives for everything that a Sentry JavaScript SDK or build tooling may do during a build.
85112 *
@@ -153,6 +180,9 @@ export function createSentryBuildPluginManager(
153180 createDependencyOnBuildArtifacts : ( ) => ( ) => {
154181 /* noop */
155182 } ,
183+ injectDebugIds : async ( ) => {
184+ /* noop */
185+ } ,
156186 } ;
157187 }
158188
@@ -424,15 +454,7 @@ export function createSentryBuildPluginManager(
424454 createDependencyOnBuildArtifacts ( ) ;
425455
426456 try {
427- const cliInstance = new SentryCli ( null , {
428- authToken : options . authToken ,
429- org : options . org ,
430- project : options . project ,
431- silent : options . silent ,
432- url : options . url ,
433- vcsRemote : options . release . vcsRemote ,
434- headers : options . headers ,
435- } ) ;
457+ const cliInstance = createCliInstance ( options ) ;
436458
437459 if ( options . release . create ) {
438460 await cliInstance . releases . new ( options . release . name ) ;
@@ -502,6 +524,33 @@ export function createSentryBuildPluginManager(
502524 }
503525 } ,
504526
527+ /*
528+ Injects debug IDs into the build artifacts.
529+
530+ This is a separate function from `uploadSourcemaps` because that needs to run before the sourcemaps are uploaded.
531+ Usually the respective bundler-plugin will take care of this before the sourcemaps are uploaded.
532+ Only use this if you need to manually inject debug IDs into the build artifacts.
533+ */
534+ async injectDebugIds ( buildArtifactPaths : string [ ] ) {
535+ await startSpan (
536+ { name : "inject-debug-ids" , scope : sentryScope , forceTransaction : true } ,
537+ async ( ) => {
538+ try {
539+ const cliInstance = createCliInstance ( options ) ;
540+ await cliInstance . execute (
541+ [ "sourcemaps" , "inject" , ...buildArtifactPaths ] ,
542+ options . debug ?? false
543+ ) ;
544+ } catch ( e ) {
545+ sentryScope . captureException ( 'Error in "debugIdInjectionPlugin" writeBundle hook' ) ;
546+ handleRecoverableError ( e , false ) ;
547+ } finally {
548+ await safeFlushTelemetry ( sentryClient ) ;
549+ }
550+ }
551+ ) ;
552+ } ,
553+
505554 /**
506555 * Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
507556 */
@@ -618,21 +667,12 @@ export function createSentryBuildPluginManager(
618667 setMeasurement ( "upload_size" , uploadSize , "byte" , prepBundlesSpan ) ;
619668
620669 await startSpan ( { name : "upload" , scope : sentryScope } , async ( uploadSpan ) => {
621- const cliInstance = new SentryCli ( null , {
622- authToken : options . authToken ,
623- org : options . org ,
624- project : options . project ,
625- silent : options . silent ,
626- url : options . url ,
627- vcsRemote : options . release . vcsRemote ,
628- headers : {
629- "sentry-trace" : spanToTraceHeader ( uploadSpan ) ,
630- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
631- baggage : dynamicSamplingContextToSentryBaggageHeader (
632- getDynamicSamplingContextFromSpan ( uploadSpan )
633- ) ! ,
634- ...options . headers ,
635- } ,
670+ const cliInstance = createCliInstance ( options , {
671+ "sentry-trace" : spanToTraceHeader ( uploadSpan ) ,
672+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
673+ baggage : dynamicSamplingContextToSentryBaggageHeader (
674+ getDynamicSamplingContextFromSpan ( uploadSpan )
675+ ) ! ,
636676 } ) ;
637677
638678 await cliInstance . releases . uploadSourceMaps (
0 commit comments