Skip to content

Commit 1523be8

Browse files
committed
refactor(agent): exit wrapper early if conditions are not met
1 parent fa419e3 commit 1523be8

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

agent/lib_aws_sdk_php.c

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -358,57 +358,65 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
358358
int klass_len = 0;
359359

360360
class_entry = Z_OBJCE_P(nr_php_execute_scope(execute_data));
361+
if (NULL == class_entry) {
362+
goto end;
363+
}
364+
361365
klass = nr_php_class_entry_name(class_entry);
362366

363-
if (NULL != klass) {
364-
/* Get the arg command_name. */
365-
command_name = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS);
367+
if (NULL == klass) {
368+
goto end;
369+
}
370+
/* Get the arg command_name. */
371+
command_name = nr_php_arg_get(1, NR_EXECUTE_ORIG_ARGS);
366372

367-
if (nr_php_is_zval_non_empty_string(command_name)) {
368-
command_name_string = Z_STRVAL_P(command_name);
369-
klass_len = nr_php_class_entry_name_length(class_entry);
373+
if (!nr_php_is_zval_non_empty_string(command_name)) {
374+
goto end;
375+
}
376+
command_name_string = Z_STRVAL_P(command_name);
377+
klass_len = nr_php_class_entry_name_length(class_entry);
370378

371379
#define AWS_CLASS_IS(KLASS, SHORT_KLASS) \
372380
(klass_len == (sizeof(KLASS) - 1) \
373381
&& nr_striendswith(klass, klass_len, SHORT_KLASS, sizeof(SHORT_KLASS) - 1))
374382

375-
if AWS_CLASS_IS ("Aws\\Sqs\\SqsClient", "SqsClient") {
376-
nr_lib_aws_sdk_php_sqs_handle(auto_segment, command_name_string,
377-
Z_STRLEN_P(command_name),
378-
NR_EXECUTE_ORIG_ARGS);
379-
}
383+
if AWS_CLASS_IS ("Aws\\Sqs\\SqsClient", "SqsClient") {
384+
nr_lib_aws_sdk_php_sqs_handle(auto_segment, command_name_string,
385+
Z_STRLEN_P(command_name),
386+
NR_EXECUTE_ORIG_ARGS);
387+
}
380388

381389
#undef AWS_CLASS_IS
382390

383-
if (NR_SEGMENT_CUSTOM == auto_segment->type) {
384-
/*
385-
* We need to end the segment that we started in the 'before' wrapper if
386-
* it wasn't handled and ended by the handling function. Handling
387-
* function would have changed the segment type from from default
388-
* (`NR_SEGMENT_CUSTOM`) if it ended it.
389-
*/
390-
nr_segment_discard(&auto_segment);
391-
}
391+
if (NR_SEGMENT_CUSTOM == auto_segment->type) {
392+
/*
393+
* We need to end the segment that we started in the 'before' wrapper if
394+
* it wasn't handled and ended by the handling function. Handling
395+
* function would have changed the segment type from from default
396+
* (`NR_SEGMENT_CUSTOM`) if it ended it.
397+
*/
398+
nr_segment_discard(&auto_segment);
399+
}
392400

393-
/*
394-
* Since we have klass and command_name, we can give the calling segment
395-
* a more meaningful name than Aws/AwsClient::__call We can decode it to
396-
* Aws/CALLING_CLASS_NAME/CALLING_CLASS_CLIENT::CALLING_CLASS_COMMAND
397-
*
398-
* EX: Aws\\Sqs\\SqsClient::sendMessage
399-
*/
400-
401-
segment = nr_txn_get_current_segment(NRPRG(txn), NULL);
402-
if (NULL != segment) {
403-
real_class_and_command
404-
= nr_formatf("Custom/%s::%s", klass, command_name_string);
405-
nr_segment_set_name(segment, real_class_and_command);
406-
nr_free(real_class_and_command);
407-
}
408-
}
409-
/* Release the command_name. */
410-
nr_php_arg_release(&command_name);
401+
/*
402+
* Since we have klass and command_name, we can give the calling segment
403+
* a more meaningful name than Aws/AwsClient::__call We can decode it to
404+
* Aws/CALLING_CLASS_NAME/CALLING_CLASS_CLIENT::CALLING_CLASS_COMMAND
405+
*
406+
* EX: Aws\\Sqs\\SqsClient::sendMessage
407+
*/
408+
409+
segment = nr_txn_get_current_segment(NRPRG(txn), NULL);
410+
if (NULL != segment) {
411+
real_class_and_command
412+
= nr_formatf("Custom/%s::%s", klass, command_name_string);
413+
nr_segment_set_name(segment, real_class_and_command);
414+
nr_free(real_class_and_command);
411415
}
416+
417+
end:
418+
/* Release the command_name. */
419+
nr_php_arg_release(&command_name);
412420
}
413421
NR_PHP_WRAPPER_END
414422

0 commit comments

Comments
 (0)