@@ -9,7 +9,7 @@ import SentryCli from "@sentry/cli";
9
9
import { dynamicSamplingContextToSentryBaggageHeader } from "@sentry/utils" ;
10
10
import { safeFlushTelemetry } from "./sentry/telemetry" ;
11
11
import { stripQueryAndHashFromPath } from "./utils" ;
12
- import { spanToTraceHeader , startSpan } from "@sentry/core" ;
12
+ import { setMeasurement , spanToTraceHeader , startSpan } from "@sentry/core" ;
13
13
import { getDynamicSamplingContextFromSpan , Scope } from "@sentry/core" ;
14
14
import { Client } from "@sentry/types" ;
15
15
@@ -107,76 +107,76 @@ export function createDebugIdUploadFunction({
107
107
"Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option."
108
108
) ;
109
109
} else {
110
- await startSpan ( { name : "prepare-bundles" , scope : sentryScope } , async ( ) => {
111
- // Preparing the bundles can be a lot of work and doing it all at once has the potential of nuking the heap so
112
- // instead we do it with a maximum of 16 concurrent workers
113
- const preparationTasks = debugIdChunkFilePaths . map (
114
- ( chunkFilePath , chunkIndex ) => async ( ) => {
115
- await prepareBundleForDebugIdUpload (
116
- chunkFilePath ,
117
- tmpUploadFolder ,
118
- chunkIndex ,
119
- logger ,
120
- rewriteSourcesHook ?? defaultRewriteSourcesHook
121
- ) ;
122
- }
123
- ) ;
124
- const workers : Promise < void > [ ] = [ ] ;
125
- const worker = async ( ) => {
126
- while ( preparationTasks . length > 0 ) {
127
- const task = preparationTasks . shift ( ) ;
128
- if ( task ) {
129
- await task ( ) ;
110
+ await startSpan (
111
+ { name : "prepare-bundles" , scope : sentryScope } ,
112
+ async ( prepBundlesSpan ) => {
113
+ // Preparing the bundles can be a lot of work and doing it all at once has the potential of nuking the heap so
114
+ // instead we do it with a maximum of 16 concurrent workers
115
+ const preparationTasks = debugIdChunkFilePaths . map (
116
+ ( chunkFilePath , chunkIndex ) => async ( ) => {
117
+ await prepareBundleForDebugIdUpload (
118
+ chunkFilePath ,
119
+ tmpUploadFolder ,
120
+ chunkIndex ,
121
+ logger ,
122
+ rewriteSourcesHook ?? defaultRewriteSourcesHook
123
+ ) ;
130
124
}
125
+ ) ;
126
+ const workers : Promise < void > [ ] = [ ] ;
127
+ const worker = async ( ) => {
128
+ while ( preparationTasks . length > 0 ) {
129
+ const task = preparationTasks . shift ( ) ;
130
+ if ( task ) {
131
+ await task ( ) ;
132
+ }
133
+ }
134
+ } ;
135
+ for ( let workerIndex = 0 ; workerIndex < 16 ; workerIndex ++ ) {
136
+ workers . push ( worker ( ) ) ;
131
137
}
132
- } ;
133
- for ( let workerIndex = 0 ; workerIndex < 16 ; workerIndex ++ ) {
134
- workers . push ( worker ( ) ) ;
135
- }
136
138
137
- await Promise . all ( workers ) ;
138
-
139
- // TODO: Bring back measurements
140
- // There's no easy way to get the root span when not using a global client.
141
-
142
- // const files = await fs.promises.readdir(tmpUploadFolder);
143
- // const stats = files.map((file) => fs.promises.stat(path.join(tmpUploadFolder, file)));
144
- // const uploadSize = (await Promise.all(stats)).reduce(
145
- // (accumulator, { size }) => accumulator + size,
146
- // 0
147
- // );
148
-
149
- // artifactBundleUploadTransaction.setMeasurement("files", files.length, "none");
150
- // artifactBundleUploadTransaction.setMeasurement("upload_size", uploadSize, "byte");
151
-
152
- await startSpan ( { name : "upload" , scope : sentryScope } , async ( uploadSpan ) => {
153
- const cliInstance = new SentryCli ( null , {
154
- ...sentryCliOptions ,
155
- headers : {
156
- "sentry-trace" : spanToTraceHeader ( uploadSpan ) ,
157
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
158
- baggage : dynamicSamplingContextToSentryBaggageHeader (
159
- getDynamicSamplingContextFromSpan ( uploadSpan )
160
- ) ! ,
161
- ...sentryCliOptions . headers ,
162
- } ,
163
- } ) ;
139
+ await Promise . all ( workers ) ;
164
140
165
- await cliInstance . releases . uploadSourceMaps (
166
- releaseName ?? "undefined" , // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
167
- {
168
- include : [
169
- {
170
- paths : [ tmpUploadFolder ] ,
171
- rewrite : false ,
172
- dist : dist ,
173
- } ,
174
- ] ,
175
- useArtifactBundle : true ,
176
- }
141
+ const files = await fs . promises . readdir ( tmpUploadFolder ) ;
142
+ const stats = files . map ( ( file ) => fs . promises . stat ( path . join ( tmpUploadFolder , file ) ) ) ;
143
+ const uploadSize = ( await Promise . all ( stats ) ) . reduce (
144
+ ( accumulator , { size } ) => accumulator + size ,
145
+ 0
177
146
) ;
178
- } ) ;
179
- } ) ;
147
+
148
+ setMeasurement ( "files" , files . length , "none" , prepBundlesSpan ) ;
149
+ setMeasurement ( "upload_size" , uploadSize , "byte" , prepBundlesSpan ) ;
150
+
151
+ await startSpan ( { name : "upload" , scope : sentryScope } , async ( uploadSpan ) => {
152
+ const cliInstance = new SentryCli ( null , {
153
+ ...sentryCliOptions ,
154
+ headers : {
155
+ "sentry-trace" : spanToTraceHeader ( uploadSpan ) ,
156
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
157
+ baggage : dynamicSamplingContextToSentryBaggageHeader (
158
+ getDynamicSamplingContextFromSpan ( uploadSpan )
159
+ ) ! ,
160
+ ...sentryCliOptions . headers ,
161
+ } ,
162
+ } ) ;
163
+
164
+ await cliInstance . releases . uploadSourceMaps (
165
+ releaseName ?? "undefined" , // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
166
+ {
167
+ include : [
168
+ {
169
+ paths : [ tmpUploadFolder ] ,
170
+ rewrite : false ,
171
+ dist : dist ,
172
+ } ,
173
+ ] ,
174
+ useArtifactBundle : true ,
175
+ }
176
+ ) ;
177
+ } ) ;
178
+ }
179
+ ) ;
180
180
181
181
logger . info ( "Successfully uploaded source maps to Sentry" ) ;
182
182
}
0 commit comments