Skip to content

Commit 2335634

Browse files
authored
Merge branch 'dev' into feat/rabbitmq_instrumentation
2 parents 71e5e02 + 94a41f5 commit 2335634

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

agent/lib_aws_sdk_php.c

+21-33
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,21 @@
8686
8787
//clang-format on
8888
*/
89-
void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
89+
void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* auto_segment,
9090
char* command_name_string,
9191
size_t command_name_len,
9292
NR_EXECUTE_PROTO) {
9393
char* command_arg_value = NULL;
94+
nr_segment_t* message_segment = NULL;
95+
9496
nr_segment_message_params_t message_params = {
9597
.library = SQS_LIBRARY_NAME,
9698
.destination_type = NR_MESSAGE_DESTINATION_TYPE_QUEUE,
9799
.messaging_system = AWS_SQS_MESSAGING_SERVICE,
98100
};
99101
nr_segment_cloud_attrs_t cloud_attrs = {0};
100102

101-
if (NULL == segment) {
103+
if (NULL == auto_segment) {
102104
return;
103105
}
104106

@@ -122,6 +124,17 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
122124
}
123125
#undef AWS_COMMAND_IS
124126

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

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

137150
/* Add cloud attributes, if available. */
138151

139-
nr_segment_traces_add_cloud_attributes(segment, &cloud_attrs);
152+
nr_segment_traces_add_cloud_attributes(message_segment, &cloud_attrs);
140153

141154
/* Now end the instrumented segment as a message segment. */
142-
nr_segment_message_end(&segment, &message_params);
155+
nr_segment_message_end(&message_segment, &message_params);
143156

144157
nr_free(command_arg_value);
145158
}
@@ -332,20 +345,6 @@ char* nr_lib_aws_sdk_php_get_command_arg_value(char* command_arg_name,
332345
* @throws \Exception
333346
*/
334347

335-
NR_PHP_WRAPPER(nr_aws_client_call_before) {
336-
(void)wraprec;
337-
nr_segment_t* segment = NULL;
338-
/*
339-
* Start a segment in case it needs to become an external, message, or
340-
* datastore segment.
341-
*/
342-
segment = nr_segment_start(NRPRG(txn), NULL, NULL);
343-
if (NULL != segment) {
344-
segment->wraprec = auto_segment->wraprec;
345-
}
346-
}
347-
NR_PHP_WRAPPER_END
348-
349348
NR_PHP_WRAPPER(nr_aws_client_call) {
350349
(void)wraprec;
351350

@@ -388,16 +387,6 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
388387

389388
#undef AWS_CLASS_IS
390389

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-
}
400-
401390
/*
402391
* Since we have klass and command_name, we can give the calling segment
403392
* a more meaningful name than Aws/AwsClient::__call We can decode it to
@@ -406,11 +395,10 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
406395
* EX: Aws\\Sqs\\SqsClient::sendMessage
407396
*/
408397

409-
segment = nr_txn_get_current_segment(NRPRG(txn), NULL);
410-
if (NULL != segment) {
398+
if (NULL != auto_segment) {
411399
real_class_and_command
412400
= nr_formatf("Custom/%s::%s", klass, command_name_string);
413-
nr_segment_set_name(segment, real_class_and_command);
401+
nr_segment_set_name(auto_segment, real_class_and_command);
414402
nr_free(real_class_and_command);
415403
}
416404

@@ -576,7 +564,7 @@ void nr_aws_sdk_php_enable() {
576564
/* We only support instrumentation above PHP 8.1 */
577565
/* Called when a service command is issued from a Client */
578566
nr_php_wrap_user_function_before_after_clean(
579-
NR_PSTR("Aws\\AwsClient::__call"), nr_aws_client_call_before,
580-
nr_aws_client_call, nr_aws_client_call);
567+
NR_PSTR("Aws\\AwsClient::__call"), NULL, nr_aws_client_call,
568+
nr_aws_client_call);
581569
#endif
582570
}

0 commit comments

Comments
 (0)