@@ -1276,6 +1276,7 @@ static int s_s3_meta_request_incoming_headers(
12761276
12771277 struct aws_s3_meta_request * meta_request = request -> meta_request ;
12781278 AWS_PRECONDITION (meta_request );
1279+ bool collect_metrics = request -> send_data .metrics != NULL ;
12791280
12801281 if (aws_http_stream_get_incoming_response_status (stream , & request -> send_data .response_status )) {
12811282 AWS_LOGF_ERROR (
@@ -1284,23 +1285,13 @@ static int s_s3_meta_request_incoming_headers(
12841285 (void * )meta_request ,
12851286 (void * )request );
12861287 }
1287- if (request -> send_data .metrics ) {
1288+
1289+ if (collect_metrics ) {
12881290 /* Record the headers to the metrics */
12891291 struct aws_s3_request_metrics * s3_metrics = request -> send_data .metrics ;
12901292 if (s3_metrics -> req_resp_info_metrics .response_headers == NULL ) {
12911293 s3_metrics -> req_resp_info_metrics .response_headers = aws_http_headers_new (meta_request -> allocator );
12921294 }
1293-
1294- for (size_t i = 0 ; i < headers_count ; ++ i ) {
1295- const struct aws_byte_cursor * name = & headers [i ].name ;
1296- const struct aws_byte_cursor * value = & headers [i ].value ;
1297- if (aws_byte_cursor_eq (name , & g_request_id_header_name )) {
1298- s3_metrics -> req_resp_info_metrics .request_id =
1299- aws_string_new_from_cursor (connection -> request -> allocator , value );
1300- }
1301-
1302- aws_http_headers_add (s3_metrics -> req_resp_info_metrics .response_headers , * name , * value );
1303- }
13041295 s3_metrics -> req_resp_info_metrics .response_status = request -> send_data .response_status ;
13051296 }
13061297
@@ -1320,11 +1311,25 @@ static int s_s3_meta_request_incoming_headers(
13201311 if (request -> send_data .response_headers == NULL ) {
13211312 request -> send_data .response_headers = aws_http_headers_new (meta_request -> allocator );
13221313 }
1314+ }
13231315
1324- for (size_t i = 0 ; i < headers_count ; ++ i ) {
1325- const struct aws_byte_cursor * name = & headers [i ].name ;
1326- const struct aws_byte_cursor * value = & headers [i ].value ;
1327-
1316+ for (size_t i = 0 ; i < headers_count ; ++ i ) {
1317+ const struct aws_byte_cursor * name = & headers [i ].name ;
1318+ const struct aws_byte_cursor * value = & headers [i ].value ;
1319+ if (request -> send_data .request_id == NULL && aws_byte_cursor_eq (name , & g_request_id_header_name )) {
1320+ request -> send_data .request_id = aws_string_new_from_cursor (connection -> request -> allocator , value );
1321+ if (collect_metrics ) {
1322+ request -> send_data .metrics -> req_resp_info_metrics .request_id =
1323+ aws_string_new_from_cursor (connection -> request -> allocator , value );
1324+ }
1325+ }
1326+ if (request -> send_data .amz_id_2 == NULL && aws_byte_cursor_eq (name , & g_amz_id_2_header_name )) {
1327+ request -> send_data .amz_id_2 = aws_string_new_from_cursor (connection -> request -> allocator , value );
1328+ }
1329+ if (collect_metrics ) {
1330+ aws_http_headers_add (request -> send_data .metrics -> req_resp_info_metrics .response_headers , * name , * value );
1331+ }
1332+ if (should_record_headers ) {
13281333 aws_http_headers_add (request -> send_data .response_headers , * name , * value );
13291334 }
13301335 }
@@ -1624,12 +1629,15 @@ void aws_s3_meta_request_send_request_finish_default(
16241629
16251630 AWS_LOGF_DEBUG (
16261631 AWS_LS_S3_META_REQUEST ,
1627- "id=%p: Request %p finished with error code %d (%s) and response status %d" ,
1632+ "id=%p: Request %p finished with error code %d (%s) and response status %d, x-amz-request-id: %s, x-amz-id-2: "
1633+ "%s" ,
16281634 (void * )meta_request ,
16291635 (void * )request ,
16301636 error_code ,
16311637 aws_error_debug_str (error_code ),
1632- response_status );
1638+ response_status ,
1639+ request -> send_data .request_id ? aws_string_c_str (request -> send_data .request_id ) : "N/A" ,
1640+ request -> send_data .amz_id_2 ? aws_string_c_str (request -> send_data .amz_id_2 ) : "N/A" );
16331641
16341642 enum aws_s3_connection_finish_code finish_code = AWS_S3_CONNECTION_FINISH_CODE_FAILED ;
16351643
0 commit comments