@@ -67,6 +67,15 @@ export type SentryBuildPluginManager = {
67
67
*/
68
68
createRelease ( ) : Promise < void > ;
69
69
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
+
70
79
/**
71
80
* Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
72
81
*/
@@ -80,6 +89,24 @@ export type SentryBuildPluginManager = {
80
89
createDependencyOnBuildArtifacts : ( ) => ( ) => void ;
81
90
} ;
82
91
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
+
83
110
/**
84
111
* Creates a build plugin manager that exposes primitives for everything that a Sentry JavaScript SDK or build tooling may do during a build.
85
112
*
@@ -153,6 +180,9 @@ export function createSentryBuildPluginManager(
153
180
createDependencyOnBuildArtifacts : ( ) => ( ) => {
154
181
/* noop */
155
182
} ,
183
+ injectDebugIds : async ( ) => {
184
+ /* noop */
185
+ } ,
156
186
} ;
157
187
}
158
188
@@ -424,15 +454,7 @@ export function createSentryBuildPluginManager(
424
454
createDependencyOnBuildArtifacts ( ) ;
425
455
426
456
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 ) ;
436
458
437
459
if ( options . release . create ) {
438
460
await cliInstance . releases . new ( options . release . name ) ;
@@ -502,6 +524,33 @@ export function createSentryBuildPluginManager(
502
524
}
503
525
} ,
504
526
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
+
505
554
/**
506
555
* Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
507
556
*/
@@ -618,21 +667,12 @@ export function createSentryBuildPluginManager(
618
667
setMeasurement ( "upload_size" , uploadSize , "byte" , prepBundlesSpan ) ;
619
668
620
669
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
+ ) ! ,
636
676
} ) ;
637
677
638
678
await cliInstance . releases . uploadSourceMaps (
0 commit comments