@@ -20,22 +20,17 @@ function sleep(ms) {
2020}
2121
2222function fetchFromSentry ( url ) {
23- console . log ( `[DEBUG] Fetching ${ url } ` ) ;
23+ console . log ( `Fetching ${ url } ` ) ;
2424 let retries = 0 ;
2525 const shouldRetry = ( response ) => {
26- console . log ( `[DEBUG] Response status: ${ response . status } ` ) ;
27- if ( response . status !== 200 ) {
28- console . log ( `[DEBUG] Non-200 response body (first 1000 chars): ${ response . body . slice ( 0 , 1000 ) } ` ) ;
29- }
30-
3126 switch ( response . status ) {
3227 case 200 :
3328 return false ;
3429 case 403 :
3530 throw new Error ( `Could not fetch ${ url } : ${ response . status } | ${ response . body } ` ) ;
3631 default :
3732 if ( retries ++ < RETRY_COUNT ) {
38- console . log ( `[DEBUG] Request failed (HTTP ${ response . status } ), retrying: ${ retries } /${ RETRY_COUNT } ` ) ;
33+ console . log ( `Request failed (HTTP ${ response . status } ), retrying: ${ retries } /${ RETRY_COUNT } ` ) ;
3934 return true ;
4035 }
4136 throw new Error ( `Could not fetch ${ url } within retry limit: ${ response . status } | ${ response . body } ` ) ;
@@ -45,7 +40,7 @@ function fetchFromSentry(url) {
4540 while ( true ) {
4641 const response = http . get ( url , { headers : requestHeaders } )
4742 if ( ! shouldRetry ( response ) ) {
48- console . log ( `[DEBUG] Received HTTP ${ response . status } : body length ${ response . body . length } ` ) ;
43+ console . log ( `Received HTTP ${ response . status } : body length ${ response . body . length } ` ) ;
4944 return response . body ;
5045 }
5146 sleep ( RETRY_INTERVAL ) ;
@@ -60,74 +55,26 @@ function setOutput(data) {
6055}
6156
6257// Note: "fetch", "id", "eventId", etc. are script inputs, see for example assertEventIdIVisible.yml
63- try {
64- switch ( fetch ) {
65- case 'event' : {
66- console . log ( `[DEBUG] Fetching event with id: ${ id } ` ) ;
67- const data = json ( fetchFromSentry ( `${ baseUrl } /events/${ id } /json/` ) ) ;
68- console . log ( `[DEBUG] Event data received, event_id: ${ data . event_id } ` ) ;
69- setOutput ( { eventId : data . event_id } ) ;
70- break ;
71- }
72- case 'replay' : {
73- console . log ( `[DEBUG] === Starting replay fetch for eventId: ${ eventId } ===` ) ;
74-
75- console . log ( `[DEBUG] Step 1: Fetching event data` ) ;
76- const event = json ( fetchFromSentry ( `${ baseUrl } /events/${ eventId } /json/` ) ) ;
77-
78- console . log ( `[DEBUG] Event fetched successfully` ) ;
79- console . log ( `[DEBUG] Event has _dsc: ${ ! ! event . _dsc } ` ) ;
80- console . log ( `[DEBUG] Event has contexts: ${ ! ! event . contexts } ` ) ;
81- console . log ( `[DEBUG] Event has contexts.replay: ${ ! ! event . contexts ?. replay } ` ) ;
82-
83- if ( event . _dsc ) {
84- console . log ( `[DEBUG] event._dsc keys: ${ Object . keys ( event . _dsc ) . join ( ', ' ) } ` ) ;
85- console . log ( `[DEBUG] event._dsc.replay_id: ${ event . _dsc . replay_id } ` ) ;
86- } else {
87- console . log ( `[DEBUG] event._dsc is undefined/null` ) ;
88- }
89-
90- if ( event . contexts ?. replay ) {
91- console . log ( `[DEBUG] event.contexts.replay keys: ${ Object . keys ( event . contexts . replay ) . join ( ', ' ) } ` ) ;
92- console . log ( `[DEBUG] event.contexts.replay.replay_id: ${ event . contexts . replay . replay_id } ` ) ;
93- }
94-
95- console . log ( `[DEBUG] Step 2: Extracting replay_id` ) ;
96- if ( ! event . _dsc || ! event . _dsc . replay_id ) {
97- console . log ( `[DEBUG] ERROR: No replay_id in event._dsc` ) ;
98- console . log ( `[DEBUG] Event structure (first 2000 chars): ${ JSON . stringify ( event ) . slice ( 0 , 2000 ) } ` ) ;
99- throw new Error ( `No replay_id found in event._dsc. Available: _dsc=${ ! ! event . _dsc } , contexts.replay=${ ! ! event . contexts ?. replay } ` ) ;
100- }
101-
102- const replayId = event . _dsc . replay_id . replace ( / \- / g, '' ) ;
103- console . log ( `[DEBUG] Replay ID extracted: ${ replayId } (raw: ${ event . _dsc . replay_id } )` ) ;
104-
105- console . log ( `[DEBUG] Step 3: Fetching replay metadata` ) ;
106- const replay = json ( fetchFromSentry ( `${ baseUrl } /replays/${ replayId } /` ) ) ;
107- console . log ( `[DEBUG] Replay metadata received: id=${ replay . data ?. id } , duration=${ replay . data ?. duration } , segments=${ replay . data ?. count_segments } ` ) ;
108-
109- console . log ( `[DEBUG] Step 4: Fetching video segment` ) ;
110- const segment = fetchFromSentry ( `${ baseUrl } /replays/${ replayId } /videos/0/` ) ;
111- const codec = segment . slice ( 4 , 12 ) ;
112- console . log ( `[DEBUG] Video segment received: size=${ segment . length } bytes, codec=${ codec } ` ) ;
113-
114- setOutput ( {
115- replayId : replay . data . id ,
116- replayDuration : replay . data . duration ,
117- replaySegments : replay . data . count_segments ,
118- replayCodec : codec
119- } ) ;
120-
121- console . log ( `[DEBUG] === Replay fetch completed successfully ===` ) ;
122- break ;
123- }
124- default :
125- throw new Error ( `Unknown "fetch" value: '${ fetch } '` ) ;
58+ switch ( fetch ) {
59+ case 'event' : {
60+ const data = json ( fetchFromSentry ( `${ baseUrl } /events/${ id } /json/` ) ) ;
61+ setOutput ( { eventId : data . event_id } ) ;
62+ break ;
63+ }
64+ case 'replay' : {
65+ const event = json ( fetchFromSentry ( `${ baseUrl } /events/${ eventId } /json/` ) ) ;
66+ const replayId = event . _dsc . replay_id . replace ( / \- / g, '' ) ;
67+ const replay = json ( fetchFromSentry ( `${ baseUrl } /replays/${ replayId } /` ) ) ;
68+ const segment = fetchFromSentry ( `${ baseUrl } /replays/${ replayId } /videos/0/` ) ;
69+
70+ setOutput ( {
71+ replayId : replay . data . id ,
72+ replayDuration : replay . data . duration ,
73+ replaySegments : replay . data . count_segments ,
74+ replayCodec : segment . slice ( 4 , 12 )
75+ } ) ;
76+ break ;
12677 }
127- } catch ( error ) {
128- console . log ( `[DEBUG] === ERROR in sentryApi.js ===` ) ;
129- console . log ( `[DEBUG] Error type: ${ error . constructor . name } ` ) ;
130- console . log ( `[DEBUG] Error message: ${ error . message } ` ) ;
131- console . log ( `[DEBUG] Error stack: ${ error . stack } ` ) ;
132- throw error ;
78+ default :
79+ throw new Error ( `Unknown "fetch" value: '${ fetch } '` ) ;
13380}
0 commit comments