Skip to content

Commit

Permalink
Merge branch 'dev' into feat/rabbitmq_instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zsistla authored Jan 31, 2025
2 parents 71e5e02 + 94a41f5 commit 2335634
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions agent/lib_aws_sdk_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,21 @@
//clang-format on
*/
void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* auto_segment,
char* command_name_string,
size_t command_name_len,
NR_EXECUTE_PROTO) {
char* command_arg_value = NULL;
nr_segment_t* message_segment = NULL;

nr_segment_message_params_t message_params = {
.library = SQS_LIBRARY_NAME,
.destination_type = NR_MESSAGE_DESTINATION_TYPE_QUEUE,
.messaging_system = AWS_SQS_MESSAGING_SERVICE,
};
nr_segment_cloud_attrs_t cloud_attrs = {0};

if (NULL == segment) {
if (NULL == auto_segment) {
return;
}

Expand All @@ -122,6 +124,17 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
}
#undef AWS_COMMAND_IS

/*
* By this point, it's been determined that this call will be instrumented so
* only create the segment now, grab the parent segment start time, add our
* special segment attributes/metrics then close the newly created segment.
*/
message_segment = nr_segment_start(NRPRG(txn), NULL, NULL);
if (NULL == message_segment) {
return;
}
/* re-use start time from auto_segment started in func_begin */
message_segment->start_time = auto_segment->start_time;
cloud_attrs.aws_operation = command_name_string;

command_arg_value = nr_lib_aws_sdk_php_get_command_arg_value(
Expand All @@ -136,10 +149,10 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,

/* Add cloud attributes, if available. */

nr_segment_traces_add_cloud_attributes(segment, &cloud_attrs);
nr_segment_traces_add_cloud_attributes(message_segment, &cloud_attrs);

/* Now end the instrumented segment as a message segment. */
nr_segment_message_end(&segment, &message_params);
nr_segment_message_end(&message_segment, &message_params);

nr_free(command_arg_value);
}
Expand Down Expand Up @@ -332,20 +345,6 @@ char* nr_lib_aws_sdk_php_get_command_arg_value(char* command_arg_name,
* @throws \Exception
*/

NR_PHP_WRAPPER(nr_aws_client_call_before) {
(void)wraprec;
nr_segment_t* segment = NULL;
/*
* Start a segment in case it needs to become an external, message, or
* datastore segment.
*/
segment = nr_segment_start(NRPRG(txn), NULL, NULL);
if (NULL != segment) {
segment->wraprec = auto_segment->wraprec;
}
}
NR_PHP_WRAPPER_END

NR_PHP_WRAPPER(nr_aws_client_call) {
(void)wraprec;

Expand Down Expand Up @@ -388,16 +387,6 @@ NR_PHP_WRAPPER(nr_aws_client_call) {

#undef AWS_CLASS_IS

if (NR_SEGMENT_CUSTOM == auto_segment->type) {
/*
* We need to end the segment that we started in the 'before' wrapper if
* it wasn't handled and ended by the handling function. Handling
* function would have changed the segment type from from default
* (`NR_SEGMENT_CUSTOM`) if it ended it.
*/
nr_segment_discard(&auto_segment);
}

/*
* Since we have klass and command_name, we can give the calling segment
* a more meaningful name than Aws/AwsClient::__call We can decode it to
Expand All @@ -406,11 +395,10 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
* EX: Aws\\Sqs\\SqsClient::sendMessage
*/

segment = nr_txn_get_current_segment(NRPRG(txn), NULL);
if (NULL != segment) {
if (NULL != auto_segment) {
real_class_and_command
= nr_formatf("Custom/%s::%s", klass, command_name_string);
nr_segment_set_name(segment, real_class_and_command);
nr_segment_set_name(auto_segment, real_class_and_command);
nr_free(real_class_and_command);
}

Expand Down Expand Up @@ -576,7 +564,7 @@ void nr_aws_sdk_php_enable() {
/* We only support instrumentation above PHP 8.1 */
/* Called when a service command is issued from a Client */
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Aws\\AwsClient::__call"), nr_aws_client_call_before,
nr_aws_client_call, nr_aws_client_call);
NR_PSTR("Aws\\AwsClient::__call"), NULL, nr_aws_client_call,
nr_aws_client_call);
#endif
}

0 comments on commit 2335634

Please sign in to comment.