@@ -11,7 +11,7 @@ static VALUE _native_configurator_get(VALUE self);
1111static VALUE _native_configurator_with_local_path (DDTRACE_UNUSED VALUE _self , VALUE rb_configurator , VALUE path );
1212static VALUE _native_configurator_with_fleet_path (DDTRACE_UNUSED VALUE _self , VALUE rb_configurator , VALUE path );
1313
14- static VALUE config_vec_class = Qnil ;
14+ static VALUE config_logged_result_class = Qnil ;
1515
1616// ddog_Configurator memory management
1717static void configurator_free (void * configurator_ptr ) {
@@ -29,29 +29,29 @@ static const rb_data_type_t configurator_typed_data = {
2929 .flags = RUBY_TYPED_FREE_IMMEDIATELY
3030};
3131
32- // ddog_Vec_LibraryConfig memory management
33- static void config_vec_free (void * config_vec_ptr ) {
34- ddog_Vec_LibraryConfig * config_vec = (ddog_Vec_LibraryConfig * )config_vec_ptr ;
32+ // ddog_LibraryConfigLoggedResult memory management
33+ static void config_logged_result_free (void * config_logged_result_ptr ) {
34+ ddog_LibraryConfigLoggedResult * config_logged_result = (ddog_LibraryConfigLoggedResult * )config_logged_result_ptr ;
3535
36- ddog_library_config_drop (* config_vec );
37- ruby_xfree (config_vec_ptr );
36+ ddog_library_config_drop (* config_logged_result );
37+ ruby_xfree (config_logged_result_ptr );
3838}
3939
40- static const rb_data_type_t config_vec_typed_data = {
41- .wrap_struct_name = "Datadog::Core::Configuration::StableConfigVec " ,
40+ static const rb_data_type_t config_logged_result_typed_data = {
41+ .wrap_struct_name = "Datadog::Core::Configuration::StableConfigLoggedResult " ,
4242 .function = {
43- .dfree = config_vec_free ,
43+ .dfree = config_logged_result_free ,
4444 .dsize = NULL ,
4545 },
4646 .flags = RUBY_TYPED_FREE_IMMEDIATELY
4747};
4848
4949void library_config_init (VALUE core_module ) {
50- rb_global_variable (& config_vec_class );
50+ rb_global_variable (& config_logged_result_class );
5151 VALUE configuration_module = rb_define_module_under (core_module , "Configuration" );
5252 VALUE stable_config_module = rb_define_module_under (configuration_module , "StableConfig" );
5353 VALUE configurator_class = rb_define_class_under (stable_config_module , "Configurator" , rb_cObject );
54- config_vec_class = rb_define_class_under (configuration_module , "StableConfigVec " , rb_cObject );
54+ config_logged_result_class = rb_define_class_under (configuration_module , "StableConfigLoggedResult " , rb_cObject );
5555
5656 rb_define_alloc_func (configurator_class , _native_configurator_new );
5757 rb_define_method (configurator_class , "get" , _native_configurator_get , 0 );
@@ -61,11 +61,12 @@ void library_config_init(VALUE core_module) {
6161 rb_define_singleton_method (testing_module , "with_local_path" , _native_configurator_with_local_path , 2 );
6262 rb_define_singleton_method (testing_module , "with_fleet_path" , _native_configurator_with_fleet_path , 2 );
6363
64- rb_undef_alloc_func (config_vec_class ); // It cannot be created from Ruby code and only serves as an intermediate object for the Ruby GC
64+ rb_undef_alloc_func (config_logged_result_class ); // It cannot be created from Ruby code and only serves as an intermediate object for the Ruby GC
6565}
6666
6767static VALUE _native_configurator_new (VALUE klass ) {
68- ddog_Configurator * configurator = ddog_library_configurator_new (false, DDOG_CHARSLICE_C ("ruby" ));
68+ // We always collect debug logs, so if DD_TRACE_DEBUG is set by stable config, we'll be able to log them.
69+ ddog_Configurator * configurator = ddog_library_configurator_new (true, DDOG_CHARSLICE_C ("ruby" ));
6970
7071 ddog_library_configurator_with_detect_process_info (configurator );
7172
@@ -98,27 +99,33 @@ static VALUE _native_configurator_get(VALUE self) {
9899 ddog_Configurator * configurator ;
99100 TypedData_Get_Struct (self , ddog_Configurator , & configurator_typed_data , configurator );
100101
101- ddog_Result_VecLibraryConfig configurator_result = ddog_library_configurator_get (configurator );
102+ // Wrapping config_logged_result into a Ruby object enables the Ruby GC to manage its memory
103+ // We need to allocate memory for config_logged_result because once it is out of scope, it will be freed (at the end of this function)
104+ // So we cannot reference it with &config_logged_result
105+ // We are doing this in case one of the ruby API raises an exception before the end of this function,
106+ // so the allocated memory will still be freed
107+ ddog_LibraryConfigLoggedResult * configurator_logged_result = ruby_xcalloc (1 , sizeof (ddog_LibraryConfigLoggedResult ));
108+ * configurator_logged_result = ddog_library_configurator_get (configurator );
109+ VALUE config_logged_result_rb = TypedData_Wrap_Struct (config_logged_result_class , & config_logged_result_typed_data , configurator_logged_result );
102110
103- if (configurator_result . tag == DDOG_RESULT_VEC_LIBRARY_CONFIG_ERR_VEC_LIBRARY_CONFIG ) {
104- ddog_Error err = configurator_result . err ;
111+ if (configurator_logged_result -> tag == DDOG_LIBRARY_CONFIG_LOGGED_RESULT_ERR ) {
112+ ddog_Error err = configurator_logged_result -> err ;
105113 VALUE message = get_error_details_and_drop (& err );
106114 if (is_config_loaded ()) {
107115 log_warning (message );
108116 } else {
109117 log_warning_without_config (message );
110118 }
119+ RB_GC_GUARD (config_logged_result_rb );
111120 return rb_hash_new ();
112121 }
113122
114- // Wrapping config_vec into a Ruby object enables the Ruby GC to manage its memory
115- // We need to allocate memory for config_vec because once it is out of scope, it will be freed (at the end of this function)
116- // So we cannot reference it with &config_vec
117- // We are doing this in case one of the ruby API raises an exception before the end of this function,
118- // so the allocated memory will still be freed
119- ddog_Vec_LibraryConfig * config_vec = ruby_xmalloc (sizeof (ddog_Vec_LibraryConfig ));
120- * config_vec = configurator_result .ok ;
121- VALUE config_vec_rb = TypedData_Wrap_Struct (config_vec_class , & config_vec_typed_data , config_vec );
123+ VALUE logs = Qnil ;
124+ if (configurator_logged_result -> ok .logs .length > 0 ) {
125+ logs = rb_utf8_str_new_cstr (configurator_logged_result -> ok .logs .ptr );
126+ }
127+
128+ ddog_Vec_LibraryConfig config_vec = configurator_logged_result -> ok .value ;
122129
123130 VALUE local_config_hash = rb_hash_new ();
124131 VALUE fleet_config_hash = rb_hash_new ();
@@ -127,8 +134,8 @@ static VALUE _native_configurator_get(VALUE self) {
127134 bool fleet_config_id_set = false;
128135 VALUE local_hash = rb_hash_new ();
129136 VALUE fleet_hash = rb_hash_new ();
130- for (uintptr_t i = 0 ; i < config_vec -> len ; i ++ ) {
131- ddog_LibraryConfig config = config_vec -> ptr [i ];
137+ for (uintptr_t i = 0 ; i < config_vec . len ; i ++ ) {
138+ ddog_LibraryConfig config = config_vec . ptr [i ];
132139 VALUE selected_hash ;
133140 if (config .source == DDOG_LIBRARY_CONFIG_SOURCE_LOCAL_STABLE_CONFIG ) {
134141 selected_hash = local_config_hash ;
@@ -156,9 +163,10 @@ static VALUE _native_configurator_get(VALUE self) {
156163 rb_hash_aset (fleet_hash , ID2SYM (rb_intern ("config" )), fleet_config_hash );
157164
158165 VALUE result = rb_hash_new ();
166+ rb_hash_aset (result , ID2SYM (rb_intern ("logs" )), logs );
159167 rb_hash_aset (result , ID2SYM (rb_intern ("local" )), local_hash );
160168 rb_hash_aset (result , ID2SYM (rb_intern ("fleet" )), fleet_hash );
161169
162- RB_GC_GUARD (config_vec_rb );
170+ RB_GC_GUARD (config_logged_result_rb );
163171 return result ;
164172}
0 commit comments