@@ -23,7 +23,8 @@ static const unsigned int MAX_TCP_PORT_ALLOWED = UINT16_MAX;
2323
2424static dd_result _pack_command (mpack_writer_t * nonnull w , void * nullable ctx );
2525static dd_result _process_response (mpack_node_t root , void * nullable ctx );
26- static void _process_meta_and_metrics (mpack_node_t root );
26+ static void _process_meta_and_metrics (
27+ mpack_node_t root , struct req_info * nonnull ctx );
2728static void _pack_agent_details (mpack_writer_t * nonnull w );
2829
2930static const dd_command_spec _spec = {
@@ -78,24 +79,22 @@ static void _pack_agent_details(mpack_writer_t *nonnull w)
7879 }
7980}
8081
81- dd_result dd_client_init (dd_conn * nonnull conn )
82+ dd_result dd_client_init (dd_conn * nonnull conn , struct req_info * nonnull ctx )
8283{
83- return dd_command_exec_cred (conn , & _spec , NULL );
84+ return dd_command_exec_cred (conn , & _spec , ctx );
8485}
8586
8687static dd_result _pack_command (
8788 mpack_writer_t * nonnull w , ATTR_UNUSED void * nullable ctx )
8889{
89- // unsigned pid, string client_version, runtime_version, rules_file
9090 mpack_write (w , (uint32_t )getpid ());
9191 dd_mpack_write_lstr (w , PHP_DDAPPSEC_VERSION );
9292 dd_mpack_write_lstr (w , PHP_VERSION );
9393
94- enabled_configuration configuration = DDAPPSEC_G (enabled_by_configuration );
95- if (configuration == NOT_CONFIGURED ) {
94+ if (DDAPPSEC_G (enabled ) == APPSEC_ENABLED_VIA_REMCFG ) {
9695 mpack_write_nil (w );
9796 } else {
98- mpack_write_bool (w , configuration == ENABLED ? true : false );
97+ mpack_write_bool (w , DDAPPSEC_G ( active ) );
9998 }
10099
101100 // Service details
@@ -206,7 +205,7 @@ static dd_result _process_response(
206205 mpack_node_t root , ATTR_UNUSED void * nullable ctx )
207206{
208207 // Add any tags and metrics provided by the helper
209- _process_meta_and_metrics (root );
208+ _process_meta_and_metrics (root , ctx );
210209
211210 // check verdict
212211 mpack_node_t verdict = mpack_node_array_at (root , 0 );
@@ -246,15 +245,23 @@ static dd_result _process_response(
246245 return dd_error ;
247246}
248247
249- static void _process_meta_and_metrics (mpack_node_t root )
248+ static void _process_meta_and_metrics (
249+ mpack_node_t root , struct req_info * nonnull ctx )
250250{
251+ zend_object * span = ctx -> root_span ;
252+ if (!span ) {
253+ mlog (
254+ dd_log_debug , "Meta/metrics in client_init ignored (no root span)" );
255+ return ;
256+ }
257+
251258 mpack_node_t meta = mpack_node_array_at (root , 3 );
252259 if (mpack_node_map_count (meta ) > 0 ) {
253- dd_command_process_meta (meta );
260+ dd_command_process_meta (meta , span );
254261 }
255262
256263 mpack_node_t metrics = mpack_node_array_at (root , 4 );
257- dd_command_process_metrics (metrics );
264+ dd_command_process_metrics (metrics , span );
258265}
259266
260267static dd_result _check_helper_version (mpack_node_t root )
0 commit comments