@@ -67,10 +67,9 @@ public static function register(): void
6767 return ;
6868 }
6969
70- $ attr = self ::getAttributeFromCurlOption ($ params [1 ], $ params [2 ]);
71- if ($ attr ) {
72- $ handleAttributes = &$ curlHandleToAttributes [$ params [0 ]];
73- $ handleAttributes [$ attr [0 ]] = $ attr [1 ];
70+ $ attribute = self ::getAttributeFromCurlOption ($ params [1 ], $ params [2 ]);
71+ if ($ attribute ) {
72+ $ curlHandleToAttributes [$ params [0 ]][$ attribute [0 ]] = $ attribute [1 ];
7473 }
7574 }
7675 );
@@ -85,10 +84,9 @@ public static function register(): void
8584 }
8685
8786 foreach ($ params [1 ] as $ option => $ value ) {
88- $ attr = self ::getAttributeFromCurlOption ($ option , $ value );
89- if ($ attr ) {
90- $ handleAttributes = &$ curlHandleToAttributes [$ params [0 ]];
91- $ handleAttributes [$ attr [0 ]] = $ attr [1 ];
87+ $ attribute = self ::getAttributeFromCurlOption ($ option , $ value );
88+ if ($ attribute ) {
89+ $ curlHandleToAttributes [$ params [0 ]][$ attribute [0 ]] = $ attribute [1 ];
9290 }
9391 }
9492 }
@@ -131,12 +129,11 @@ public static function register(): void
131129 null ,
132130 'curl_exec ' ,
133131 pre: static function ($ obj , array $ params , ?string $ class , ?string $ function , ?string $ filename , ?int $ lineno ) use ($ instrumentation , $ curlHandleToAttributes ) {
134- /** @psalm-suppress ArgumentTypeCoercion */
135132 if (!($ params [0 ] instanceof CurlHandle)) {
136133 return ;
137134 }
138135
139- $ spanName = array_key_exists (TraceAttributes:: HTTP_REQUEST_METHOD , $ curlHandleToAttributes [$ params [0 ]]) ? $ curlHandleToAttributes [ $ params [ 0 ]][ TraceAttributes::HTTP_REQUEST_METHOD ] : 'curl_exec ' ;
136+ $ spanName = $ curlHandleToAttributes [$ params [0 ]][ TraceAttributes::HTTP_REQUEST_METHOD ] ?? 'curl_exec ' ;
140137
141138 $ builder = $ instrumentation ->tracer ()
142139 ->spanBuilder ($ spanName )
@@ -196,8 +193,7 @@ public static function register(): void
196193 pre: null ,
197194 post: static function ($ obj , array $ params , mixed $ retVal ) use ($ curlMultiToHandle ) {
198195 if ($ retVal == 0 ) {
199- $ mHandle = &$ curlMultiToHandle [$ params [0 ]];
200- $ mHandle ['handles ' ][$ params [1 ]] = ['finished ' => false , 'span ' => null ];
196+ $ curlMultiToHandle [$ params [0 ]]['handles ' ][$ params [1 ]] = ['finished ' => false , 'span ' => null ];
201197 }
202198 }
203199 );
@@ -240,7 +236,7 @@ public static function register(): void
240236 if (!$ mHandle ['started ' ]) { // on first call to curl_multi_exec we're marking it's a transfer start for all curl handles attached to multi handle
241237 $ parent = Context::getCurrent ();
242238 foreach ($ handles as $ cHandle => &$ metadata ) {
243- $ spanName = array_key_exists (TraceAttributes:: HTTP_REQUEST_METHOD , $ curlHandleToAttributes [$ cHandle ]) ? $ curlHandleToAttributes [ $ cHandle ][ TraceAttributes::HTTP_REQUEST_METHOD ] : 'curl_multi_exec ' ;
239+ $ spanName = $ curlHandleToAttributes [$ cHandle ][ TraceAttributes::HTTP_REQUEST_METHOD ] ?? 'curl_multi_exec ' ;
244240 $ builder = $ instrumentation ->tracer ()
245241 ->spanBuilder ($ spanName )
246242 ->setSpanKind (SpanKind::KIND_CLIENT )
@@ -363,23 +359,23 @@ private static function getAttributeFromCurlOption(int $option, mixed $value): ?
363359 private static function setAttributesFromCurlGetInfo (CurlHandle $ handle , SpanInterface $ span )
364360 {
365361 $ info = curl_getinfo ($ handle );
366- if (array_key_exists ( 'http_code ' , $ info ) ) {
367- $ span ->setAttribute (TraceAttributes::HTTP_RESPONSE_STATUS_CODE , $ info [ ' http_code ' ] );
362+ if (( $ value = $ info [ 'http_code ' ] ?? null ) != 0 ) {
363+ $ span ->setAttribute (TraceAttributes::HTTP_RESPONSE_STATUS_CODE , $ value );
368364 }
369- if (array_key_exists ( ' download_content_length ' , $ info ) && $ info ['download_content_length ' ] > -1 ) {
370- $ span ->setAttribute (TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH , $ info [ ' download_content_length ' ] );
365+ if (( $ value = $ info ['download_content_length ' ] ?? null ) > -1 ) {
366+ $ span ->setAttribute (TraceAttributes::HTTP_RESPONSE_CONTENT_LENGTH , $ value );
371367 }
372- if (array_key_exists ( ' upload_content_length ' , $ info ) && $ info ['upload_content_length ' ] > -1 ) {
373- $ span ->setAttribute (TraceAttributes::HTTP_REQUEST_BODY_SIZE , $ info [ ' upload_content_length ' ] );
368+ if (( $ value = $ info ['upload_content_length ' ] ?? null ) > -1 ) {
369+ $ span ->setAttribute (TraceAttributes::HTTP_REQUEST_BODY_SIZE , $ value );
374370 }
375- if (array_key_exists ( 'scheme ' , $ info ) ) {
376- $ span ->setAttribute (TraceAttributes::URL_SCHEME , $ info [ ' scheme ' ] );
371+ if ($ value = $ info [ 'scheme ' ] ?? null ) {
372+ $ span ->setAttribute (TraceAttributes::URL_SCHEME , $ value );
377373 }
378- if (array_key_exists ( 'primary_ip ' , $ info ) ) {
379- $ span ->setAttribute (TraceAttributes::SERVER_ADDRESS , $ info [ ' primary_ip ' ] );
374+ if ($ value = $ info [ 'primary_ip ' ] ?? null ) {
375+ $ span ->setAttribute (TraceAttributes::SERVER_ADDRESS , $ value );
380376 }
381- if (array_key_exists ( 'primary_port ' , $ info ) ) {
382- $ span ->setAttribute (TraceAttributes::SERVER_PORT , $ info [ ' primary_port ' ] );
377+ if ($ value = $ info [ 'primary_port ' ] ?? null ) {
378+ $ span ->setAttribute (TraceAttributes::SERVER_PORT , $ value );
383379 }
384380 }
385381}
0 commit comments