Skip to content

Commit 1bff661

Browse files
vpellandmehalaivoanjodd-apm-ecosystems-autobot[bot]
authored
[APMAPI-1607] Upgrade libdatadog dependency to version 22.0.1 (#4902)
Co-authored-by: Damien Mehala <[email protected]> Co-authored-by: Ivo Anjo <[email protected]> Co-authored-by: dd-apm-ecosystems-autobot[bot] <214617597+dd-apm-ecosystems-autobot[bot]@users.noreply.github.com>
1 parent 0c3ed07 commit 1bff661

File tree

734 files changed

+2600
-2453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

734 files changed

+2600
-2453
lines changed

datadog.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Gem::Specification.new do |spec|
6969

7070
# When updating the version here, please also update the version in `libdatadog_extconf_helpers.rb`
7171
# (and yes we have a test for it)
72-
spec.add_dependency 'libdatadog', '~> 18.1.0.1.0'
72+
spec.add_dependency 'libdatadog', '~> 22.0.1.1.0'
7373

7474
# Will no longer be a default gem on Ruby 3.5, see
7575
# https://github.com/ruby/ruby/commit/d7e558e3c48c213d0e8bedca4fb547db55613f7c and

ext/libdatadog_api/library_config.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static VALUE _native_configurator_get(VALUE self);
1111
static VALUE _native_configurator_with_local_path(DDTRACE_UNUSED VALUE _self, VALUE rb_configurator, VALUE path);
1212
static 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
1717
static 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

4949
void 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

6767
static 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
}

ext/libdatadog_api/process_discovery.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,40 @@ static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, VALUE self) {
4242
rb_scan_args(argc, argv, "1:", &logger, &options);
4343
if (options == Qnil) options = rb_hash_new();
4444

45-
VALUE schema_version = rb_hash_fetch(options, ID2SYM(rb_intern("schema_version")));
4645
VALUE runtime_id = rb_hash_fetch(options, ID2SYM(rb_intern("runtime_id")));
4746
VALUE tracer_language = rb_hash_fetch(options, ID2SYM(rb_intern("tracer_language")));
4847
VALUE tracer_version = rb_hash_fetch(options, ID2SYM(rb_intern("tracer_version")));
4948
VALUE hostname = rb_hash_fetch(options, ID2SYM(rb_intern("hostname")));
5049
VALUE service_name = rb_hash_fetch(options, ID2SYM(rb_intern("service_name")));
5150
VALUE service_env = rb_hash_fetch(options, ID2SYM(rb_intern("service_env")));
5251
VALUE service_version = rb_hash_fetch(options, ID2SYM(rb_intern("service_version")));
52+
VALUE process_tags = rb_hash_fetch(options, ID2SYM(rb_intern("process_tags")));
53+
VALUE container_id = rb_hash_fetch(options, ID2SYM(rb_intern("container_id")));
5354

54-
ENFORCE_TYPE(schema_version, T_FIXNUM);
5555
ENFORCE_TYPE(runtime_id, T_STRING);
5656
ENFORCE_TYPE(tracer_language, T_STRING);
5757
ENFORCE_TYPE(tracer_version, T_STRING);
5858
ENFORCE_TYPE(hostname, T_STRING);
5959
ENFORCE_TYPE(service_name, T_STRING);
6060
ENFORCE_TYPE(service_env, T_STRING);
6161
ENFORCE_TYPE(service_version, T_STRING);
62-
63-
ddog_Result_TracerMemfdHandle result = ddog_store_tracer_metadata(
64-
(uint8_t) NUM2UINT(schema_version),
65-
char_slice_from_ruby_string(runtime_id),
66-
char_slice_from_ruby_string(tracer_language),
67-
char_slice_from_ruby_string(tracer_version),
68-
char_slice_from_ruby_string(hostname),
69-
char_slice_from_ruby_string(service_name),
70-
char_slice_from_ruby_string(service_env),
71-
char_slice_from_ruby_string(service_version)
72-
);
62+
ENFORCE_TYPE(process_tags, T_STRING);
63+
ENFORCE_TYPE(container_id, T_STRING);
64+
65+
void* builder = ddog_tracer_metadata_new();
66+
67+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_RUNTIME_ID, StringValueCStr(runtime_id));
68+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_TRACER_LANGUAGE, StringValueCStr(tracer_language));
69+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_TRACER_VERSION, StringValueCStr(tracer_version));
70+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_HOSTNAME, StringValueCStr(hostname));
71+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_SERVICE_NAME, StringValueCStr(service_name));
72+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_SERVICE_ENV, StringValueCStr(service_env));
73+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_SERVICE_VERSION, StringValueCStr(service_version));
74+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_PROCESS_TAGS, StringValueCStr(process_tags));
75+
ddog_tracer_metadata_set(builder, DDOG_METADATA_KIND_CONTAINER_ID, StringValueCStr(container_id));
76+
77+
ddog_Result_TracerMemfdHandle result = ddog_tracer_metadata_store(builder);
78+
ddog_tracer_metadata_free(builder);
7379

7480
if (result.tag == DDOG_RESULT_TRACER_MEMFD_HANDLE_ERR_TRACER_MEMFD_HANDLE) {
7581
rb_funcall(logger, rb_intern("debug"), 1, rb_sprintf("Failed to store the tracer configuration in a memory file descriptor: %"PRIsVALUE, get_error_details_and_drop(&result.err)));

ext/libdatadog_extconf_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Datadog
1010
module LibdatadogExtconfHelpers
1111
# Used to make sure the correct gem version gets loaded, as extconf.rb does not get run with "bundle exec" and thus
1212
# may see multiple libdatadog versions. See https://github.com/DataDog/dd-trace-rb/pull/2531 for the horror story.
13-
LIBDATADOG_VERSION = '~> 18.1.0.1.0'
13+
LIBDATADOG_VERSION = '~> 22.0.1.1.0'
1414

1515
# Used as an workaround for a limitation with how dynamic linking works in environments where the datadog gem and
1616
# libdatadog are moved after the extension gets compiled.

gemfiles/jruby_9.2_activesupport.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/jruby_9.2_aws.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/jruby_9.2_contrib.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/jruby_9.2_contrib_old.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/jruby_9.2_core_old.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/jruby_9.2_dalli_2.gemfile.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)