ddtrace 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/README.md +2 -2
  4. data/ext/ddtrace_profiling_loader/extconf.rb +4 -1
  5. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +1 -1
  6. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +3 -2
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +15 -41
  8. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +1 -1
  9. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +284 -74
  10. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c +142 -0
  11. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h +14 -0
  12. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +241 -0
  13. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
  14. data/ext/ddtrace_profiling_native_extension/extconf.rb +21 -7
  15. data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
  16. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +8 -0
  17. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +108 -24
  18. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
  19. data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
  20. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
  21. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
  22. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +23 -4
  23. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +4 -0
  24. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +15 -18
  25. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  26. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  27. data/lib/datadog/core/configuration/components.rb +27 -6
  28. data/lib/datadog/core/configuration/ext.rb +18 -0
  29. data/lib/datadog/core/configuration/settings.rb +14 -341
  30. data/lib/datadog/core/diagnostics/health.rb +4 -22
  31. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  32. data/lib/datadog/core/utils.rb +0 -21
  33. data/lib/datadog/core.rb +21 -1
  34. data/lib/datadog/opentracer/distributed_headers.rb +2 -2
  35. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +16 -5
  36. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  37. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  38. data/lib/datadog/profiling/stack_recorder.rb +14 -0
  39. data/lib/datadog/profiling.rb +2 -0
  40. data/lib/datadog/tracing/configuration/ext.rb +33 -3
  41. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  42. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
  43. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  44. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
  45. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  46. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
  47. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  48. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
  49. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  50. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
  51. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  52. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
  53. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  54. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
  55. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +9 -4
  56. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  57. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +6 -1
  58. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +9 -4
  59. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  60. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +6 -1
  61. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  62. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +6 -1
  63. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  64. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
  65. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  66. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
  67. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  68. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
  69. data/lib/datadog/tracing/contrib/patcher.rb +3 -2
  70. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
  71. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  72. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +12 -2
  73. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
  74. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  75. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
  76. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
  77. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
  78. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  79. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -23
  80. data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
  81. data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
  82. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  83. data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
  84. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  85. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
  86. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  87. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  88. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  89. data/lib/datadog/tracing/distributed/{b3.rb → b3_multi.rb} +2 -2
  90. data/lib/datadog/tracing/distributed/helpers.rb +2 -1
  91. data/lib/datadog/tracing/distributed/none.rb +19 -0
  92. data/lib/datadog/tracing/distributed/trace_context.rb +369 -0
  93. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  94. data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
  95. data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
  96. data/lib/datadog/tracing/span.rb +3 -19
  97. data/lib/datadog/tracing/span_operation.rb +5 -4
  98. data/lib/datadog/tracing/trace_digest.rb +75 -2
  99. data/lib/datadog/tracing/trace_operation.rb +5 -4
  100. data/lib/datadog/tracing/utils.rb +50 -0
  101. data/lib/ddtrace/version.rb +1 -1
  102. metadata +20 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38409b6f228216767057d98b4acb4cc0effeecd34e6b98e202dde946aa4aec99
4
- data.tar.gz: 6a5b909f6a73516c965c1125b7c70fe212972bf89ac829e0cabc356d82a353a0
3
+ metadata.gz: '02285d37473e8fe6c731e55ae7864860a311e2b6d509f56a41f31094cd198f09'
4
+ data.tar.gz: 8857a0f43f96fef23309cd7fced88b846d5ad48834b6c87d0f40181cc3bd5dd9
5
5
  SHA512:
6
- metadata.gz: 73d2114938c7a420a6846042c3172f4b08b5a9fb5b68efc6aa155441fa80d6221201ff1a09afbcbd8ccb12655590622326510cf17995443cd1e5cadca0fedbb3
7
- data.tar.gz: 6c8005ac09cb122bbcf32ee569799f61ada81f8e7a735b2b754e0b0f2969a77980b95a1d8871440efe8e617a3c53c77b4f286dceb98be00dd446684ed5bec43b
6
+ metadata.gz: afcde0e01258f5ab997fa6bcfa51c29a82f0e730258056a9efae86130445dbd63471269c047878b1ee554cc4ec956fe6e95a597ce65930e73549b0e32cbec50c
7
+ data.tar.gz: 292867c7c22146d0bd3147bb8863dd51fc89200a08efe640f05ae053fb93bdaeb068eefb6c89466b40ebbe749174844aa6b874c5a2b6aae30cb5055c9f2dc3cd
data/CHANGELOG.md CHANGED
@@ -2,6 +2,38 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.8.0] - 2022-12-14
6
+
7
+ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v1.8.0
8
+
9
+ As of ddtrace 1.8.0, CPU Profiling 2.0 is now in opt-in (that is, disabled by default) public beta. For more details,
10
+ check the release notes.
11
+
12
+ ### Added
13
+
14
+ * Core: Profiling: [PROF-6559] Mark Ruby CPU Profiling 2.0 as being in beta ([#2489][])
15
+ * Tracing: Attempt to parse future version of TraceContext ([#2473][])
16
+ * Tracing: Add DD_TRACE_PROPAGATION_STYLE option ([#2466][])
17
+ * Integrations: Tracing: SQL comment propagation full mode with traceparent ([#2464][])
18
+ * Integrations: Tracing: Wire W3C propagator to HTTP & gRPC propagation ([#2458][])
19
+ * Integrations: Tracing: Auto-instrumentation with service_name from environmental variable ([#2455][])
20
+ * Core: Integrations: Tracing: Deprecation notice for B3 propagation configuration ([#2454][])
21
+ * Tracing: Add W3C Trace Context propagator ([#2451][])
22
+ * Integrations: Tracing: Redis 5 Instrumentation ([#2428][])
23
+
24
+ ### Changed
25
+
26
+ * Tracing: Changes `error.msg` to `error.message` for UNC ([#2469][])
27
+ * Tracing: Semicolons not allowed in 'origin' ([#2461][])
28
+ * Core: Dev/refactor: Tracing: Dev/internal: Move Utils#next_id and constants to Tracing::Utils ([#2463][])
29
+ * Core: Dev/refactor: Tracing: Dev/internal: Move Tracing config settings from Core to Tracing ([#2459][])
30
+ * Core: Dev/refactor: Tracing: Dev/internal: Move Tracing diagnostic code from Core to Tracing ([#2453][])
31
+
32
+ ### Fixed
33
+
34
+ * Integrations: Tracing: Improve redis integration patching ([#2470][])
35
+ * Tracing: Extra testing from W3C spec ([#2460][])
36
+
5
37
  ## [1.7.0] - 2022-11-29
6
38
 
7
39
  ### Added
@@ -2218,7 +2250,8 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
2218
2250
 
2219
2251
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
2220
2252
 
2221
- [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.7.0...master
2253
+ [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.8.0...master
2254
+ [1.8.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.7.0...v1.8.0
2222
2255
  [1.7.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.6.1...v1.7.0
2223
2256
  [1.6.1]: https://github.com/DataDog/dd-trace-rb/compare/v1.6.0...v1.6.1
2224
2257
  [1.6.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.5.2...v1.6.0
@@ -3161,7 +3194,23 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3161
3194
  [#2413]: https://github.com/DataDog/dd-trace-rb/issues/2413
3162
3195
  [#2419]: https://github.com/DataDog/dd-trace-rb/issues/2419
3163
3196
  [#2420]: https://github.com/DataDog/dd-trace-rb/issues/2420
3197
+ [#2428]: https://github.com/DataDog/dd-trace-rb/issues/2428
3164
3198
  [#2435]: https://github.com/DataDog/dd-trace-rb/issues/2435
3199
+ [#2451]: https://github.com/DataDog/dd-trace-rb/issues/2451
3200
+ [#2453]: https://github.com/DataDog/dd-trace-rb/issues/2453
3201
+ [#2454]: https://github.com/DataDog/dd-trace-rb/issues/2454
3202
+ [#2455]: https://github.com/DataDog/dd-trace-rb/issues/2455
3203
+ [#2458]: https://github.com/DataDog/dd-trace-rb/issues/2458
3204
+ [#2459]: https://github.com/DataDog/dd-trace-rb/issues/2459
3205
+ [#2460]: https://github.com/DataDog/dd-trace-rb/issues/2460
3206
+ [#2461]: https://github.com/DataDog/dd-trace-rb/issues/2461
3207
+ [#2463]: https://github.com/DataDog/dd-trace-rb/issues/2463
3208
+ [#2464]: https://github.com/DataDog/dd-trace-rb/issues/2464
3209
+ [#2466]: https://github.com/DataDog/dd-trace-rb/issues/2466
3210
+ [#2469]: https://github.com/DataDog/dd-trace-rb/issues/2469
3211
+ [#2470]: https://github.com/DataDog/dd-trace-rb/issues/2470
3212
+ [#2473]: https://github.com/DataDog/dd-trace-rb/issues/2473
3213
+ [#2489]: https://github.com/DataDog/dd-trace-rb/issues/2489
3165
3214
  [@AdrianLC]: https://github.com/AdrianLC
3166
3215
  [@Azure7111]: https://github.com/Azure7111
3167
3216
  [@BabyGroot]: https://github.com/BabyGroot
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- **We've recently released the 1.x version series. If you're upgrading from a 0.x version, check out our [upgrade guide](https://github.com/DataDog/dd-trace-rb/blob/master/docs/UpgradeGuide.md#from-0x-to-10).**
2
-
3
1
  # Datadog Trace Client
4
2
 
5
3
  [![Gem](https://img.shields.io/gem/v/ddtrace)](https://rubygems.org/gems/ddtrace/)
@@ -12,6 +10,8 @@ databases and microservices so that developers have great visiblity into bottlen
12
10
 
13
11
  ## Getting started
14
12
 
13
+ **If you're upgrading from a 0.x version, check out our [upgrade guide](https://github.com/DataDog/dd-trace-rb/blob/master/docs/UpgradeGuide.md#from-0x-to-10).**
14
+
15
15
  For a basic product overview, check out our [setup documentation][setup docs].
16
16
 
17
17
  For installation, configuration, and details about using the API, check out our [API documentation][api docs] and [gem documentation][gem docs].
@@ -34,7 +34,7 @@ add_compiler_flag '-Werror' if ENV['DDTRACE_CI'] == 'true'
34
34
  # (https://github.com/msgpack/msgpack-ruby/blob/18ce08f6d612fe973843c366ac9a0b74c4e50599/ext/msgpack/extconf.rb#L8)
35
35
  add_compiler_flag '-std=gnu99'
36
36
 
37
- # Gets really noisy when we include the MJIT header, let's omit it
37
+ # Gets really noisy when we include the MJIT header, let's omit it (TODO: Use #pragma GCC diagnostic instead?)
38
38
  add_compiler_flag '-Wno-unused-function'
39
39
 
40
40
  # Allow defining variables at any point in a function
@@ -55,6 +55,9 @@ add_compiler_flag '-Wunused-parameter'
55
55
  # For more details see https://gcc.gnu.org/wiki/Visibility
56
56
  add_compiler_flag '-fvisibility=hidden'
57
57
 
58
+ # Avoid legacy C definitions
59
+ add_compiler_flag '-Wold-style-definition'
60
+
58
61
  # Enable all other compiler warnings
59
62
  add_compiler_flag '-Wall'
60
63
  add_compiler_flag '-Wextra'
@@ -57,7 +57,7 @@ Non-exhaustive list of APIs that cause exceptions to be raised:
57
57
 
58
58
  * `Check_TypedStruct`, `Check_Type`, `ENFORCE_TYPE`
59
59
  * `rb_funcall`
60
- * `rb_thread_call_without_gvl`, `rb_thread_call_without_gvl2`
60
+ * `rb_thread_call_without_gvl`
61
61
  * [Numeric conversion APIs, e.g. `NUM2LONG`, `NUM2INT`, etc.](https://silverhammermba.github.io/emberb/c/?#translation)
62
62
  * Our `char_slice_from_ruby_string` helper
63
63
 
@@ -7,11 +7,12 @@
7
7
  #include <pthread.h>
8
8
  #include <time.h>
9
9
  #include <errno.h>
10
-
11
10
  #include <ruby.h>
11
+
12
12
  #include "helpers.h"
13
13
  #include "private_vm_api_access.h"
14
14
  #include "clock_id.h"
15
+ #include "time_helpers.h"
15
16
 
16
17
  // Validate that our home-cooked pthread_id_for() matches pthread_self() for the current thread
17
18
  void self_test_clock_id(void) {
@@ -68,7 +69,7 @@ thread_cpu_time thread_cpu_time_for(thread_cpu_time_id time_id) {
68
69
  // TODO: Include the error code in some way in the output?
69
70
  if (clock_gettime(time_id.clock_id, &current_cpu) != 0) return error;
70
71
 
71
- return (thread_cpu_time) {.valid = true, .result_ns = current_cpu.tv_nsec + (current_cpu.tv_sec * 1000 * 1000 * 1000)};
72
+ return (thread_cpu_time) {.valid = true, .result_ns = current_cpu.tv_nsec + SECONDS_AS_NS(current_cpu.tv_sec)};
72
73
  }
73
74
 
74
75
  #endif
@@ -1,11 +1,13 @@
1
1
  #include <ruby.h>
2
- #include "helpers.h"
2
+
3
3
  #include "clock_id.h"
4
+ #include "collectors_cpu_and_wall_time.h"
4
5
  #include "collectors_stack.h"
6
+ #include "helpers.h"
5
7
  #include "libdatadog_helpers.h"
6
8
  #include "private_vm_api_access.h"
7
9
  #include "stack_recorder.h"
8
- #include "collectors_cpu_and_wall_time.h"
10
+ #include "time_helpers.h"
9
11
 
10
12
  // Used to periodically sample threads, recording elapsed CPU-time and Wall-time between samples.
11
13
  //
@@ -60,8 +62,6 @@
60
62
 
61
63
  #define INVALID_TIME -1
62
64
  #define THREAD_ID_LIMIT_CHARS 44 // Why 44? "#{2**64} (#{2**64})".size + 1 for \0
63
- #define RAISE_ON_FAILURE true
64
- #define DO_NOT_RAISE_ON_FAILURE false
65
65
  #define IS_WALL_TIME true
66
66
  #define IS_NOT_WALL_TIME false
67
67
  #define MISSING_TRACER_CONTEXT_KEY 0
@@ -128,9 +128,8 @@ struct trace_identifiers {
128
128
 
129
129
  bool valid;
130
130
  ddog_CharSlice local_root_span_id;
131
- ddog_CharSlice span_id;
131
+ uint64_t span_id;
132
132
  char local_root_span_id_buffer[MAXIMUM_LENGTH_64_BIT_IDENTIFIER];
133
- char span_id_buffer[MAXIMUM_LENGTH_64_BIT_IDENTIFIER];
134
133
  VALUE trace_endpoint;
135
134
  };
136
135
 
@@ -164,7 +163,6 @@ static int remove_if_dead_thread(st_data_t key_thread, st_data_t value_context,
164
163
  static VALUE _native_per_thread_context(VALUE self, VALUE collector_instance);
165
164
  static long update_time_since_previous_sample(long *time_at_previous_sample_ns, long current_time_ns, long gc_start_time_ns, bool is_wall_time);
166
165
  static long cpu_time_now_ns(struct per_thread_context *thread_context);
167
- static long wall_time_now_ns(bool raise_on_failure);
168
166
  static long thread_id_for(VALUE thread);
169
167
  static VALUE _native_stats(VALUE self, VALUE collector_instance);
170
168
  static void trace_identifiers_for(struct cpu_and_wall_time_collector_state *state, VALUE thread, struct trace_identifiers *trace_identifiers_result);
@@ -300,7 +298,7 @@ static VALUE _native_initialize(DDTRACE_UNUSED VALUE _self, VALUE collector_inst
300
298
  // This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTime behavior using RSpec.
301
299
  // It SHOULD NOT be used for other purposes.
302
300
  static VALUE _native_sample(DDTRACE_UNUSED VALUE _self, VALUE collector_instance) {
303
- cpu_and_wall_time_collector_sample(collector_instance);
301
+ cpu_and_wall_time_collector_sample(collector_instance, monotonic_wall_time_now_ns(RAISE_ON_FAILURE));
304
302
  return Qtrue;
305
303
  }
306
304
 
@@ -332,12 +330,11 @@ static VALUE _native_sample_after_gc(DDTRACE_UNUSED VALUE self, VALUE collector_
332
330
  // Assumption 3: This function IS NOT called from a signal handler. This function is not async-signal-safe.
333
331
  // Assumption 4: This function IS NOT called in a reentrant way.
334
332
  // Assumption 5: This function is called from the main Ractor (if Ruby has support for Ractors).
335
- VALUE cpu_and_wall_time_collector_sample(VALUE self_instance) {
333
+ void cpu_and_wall_time_collector_sample(VALUE self_instance, long current_monotonic_wall_time_ns) {
336
334
  struct cpu_and_wall_time_collector_state *state;
337
335
  TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_collector_state, &cpu_and_wall_time_collector_typed_data, state);
338
336
 
339
337
  VALUE threads = ddtrace_thread_list();
340
- long current_wall_time_ns = wall_time_now_ns(RAISE_ON_FAILURE);
341
338
 
342
339
  const long thread_count = RARRAY_LEN(threads);
343
340
  for (long i = 0; i < thread_count; i++) {
@@ -354,7 +351,7 @@ VALUE cpu_and_wall_time_collector_sample(VALUE self_instance) {
354
351
  );
355
352
  long wall_time_elapsed_ns = update_time_since_previous_sample(
356
353
  &thread_context->wall_time_at_previous_sample_ns,
357
- current_wall_time_ns,
354
+ current_monotonic_wall_time_ns,
358
355
  thread_context->gc_tracking.wall_time_at_start_ns,
359
356
  IS_WALL_TIME
360
357
  );
@@ -376,12 +373,9 @@ VALUE cpu_and_wall_time_collector_sample(VALUE self_instance) {
376
373
 
377
374
  state->sample_count++;
378
375
 
379
- // TODO: This seems somewhat overkill and inefficient to do often; right now we just doing every few samples
376
+ // TODO: This seems somewhat overkill and inefficient to do often; right now we just do it every few samples
380
377
  // but there's probably a better way to do this if we actually track when threads finish
381
378
  if (state->sample_count % 100 == 0) remove_context_for_dead_threads(state);
382
-
383
- // Return a VALUE to make it easier to call this function from Ruby APIs that expect a return value (such as rb_rescue2)
384
- return Qnil;
385
379
  }
386
380
 
387
381
  // This function gets called when Ruby is about to start running the Garbage Collector on the current thread.
@@ -425,7 +419,7 @@ void cpu_and_wall_time_collector_on_gc_start(VALUE self_instance) {
425
419
  thread_context->gc_tracking.wall_time_at_finish_ns != INVALID_TIME) return;
426
420
 
427
421
  // Here we record the wall-time first and in on_gc_finish we record it second to avoid having wall-time be slightly < cpu-time
428
- thread_context->gc_tracking.wall_time_at_start_ns = wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
422
+ thread_context->gc_tracking.wall_time_at_start_ns = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
429
423
  thread_context->gc_tracking.cpu_time_at_start_ns = cpu_time_now_ns(thread_context);
430
424
  }
431
425
 
@@ -461,7 +455,7 @@ void cpu_and_wall_time_collector_on_gc_finish(VALUE self_instance) {
461
455
 
462
456
  // Here we record the wall-time second and in on_gc_start we record it first to avoid having wall-time be slightly < cpu-time
463
457
  thread_context->gc_tracking.cpu_time_at_finish_ns = cpu_time_now_ns(thread_context);
464
- thread_context->gc_tracking.wall_time_at_finish_ns = wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
458
+ thread_context->gc_tracking.wall_time_at_finish_ns = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
465
459
  }
466
460
 
467
461
  // This function gets called shortly after Ruby has finished running the Garbage Collector.
@@ -583,7 +577,7 @@ static void trigger_sample_for_thread(
583
577
 
584
578
  if (trace_identifiers_result.valid) {
585
579
  labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("local root span id"), .str = trace_identifiers_result.local_root_span_id};
586
- labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("span id"), .str = trace_identifiers_result.span_id};
580
+ labels[label_pos++] = (ddog_Label) {.key = DDOG_CHARSLICE_C("span id"), .num = trace_identifiers_result.span_id};
587
581
 
588
582
  if (trace_identifiers_result.trace_endpoint != Qnil) {
589
583
  // The endpoint gets recorded in a different way because it is mutable in the tracer and can change during a
@@ -693,8 +687,6 @@ static VALUE per_thread_context_st_table_as_ruby_hash(struct cpu_and_wall_time_c
693
687
  return result;
694
688
  }
695
689
 
696
- #define VALUE_COUNT(array) (sizeof(array) / sizeof(VALUE))
697
-
698
690
  static int per_thread_context_as_ruby_hash(st_data_t key_thread, st_data_t value_context, st_data_t result_hash) {
699
691
  VALUE thread = (VALUE) key_thread;
700
692
  struct per_thread_context *thread_context = (struct per_thread_context*) value_context;
@@ -723,8 +715,8 @@ static VALUE stats_as_ruby_hash(struct cpu_and_wall_time_collector_state *state)
723
715
  // Update this when modifying state struct (stats inner struct)
724
716
  VALUE stats_as_hash = rb_hash_new();
725
717
  VALUE arguments[] = {
726
- ID2SYM(rb_intern("gc_samples")), /* => */ INT2NUM(state->stats.gc_samples),
727
- ID2SYM(rb_intern("gc_samples_missed_due_to_missing_context")), /* => */ INT2NUM(state->stats.gc_samples_missed_due_to_missing_context),
718
+ ID2SYM(rb_intern("gc_samples")), /* => */ UINT2NUM(state->stats.gc_samples),
719
+ ID2SYM(rb_intern("gc_samples_missed_due_to_missing_context")), /* => */ UINT2NUM(state->stats.gc_samples_missed_due_to_missing_context),
728
720
  };
729
721
  for (long unsigned int i = 0; i < VALUE_COUNT(arguments); i += 2) rb_hash_aset(stats_as_hash, arguments[i], arguments[i+1]);
730
722
  return stats_as_hash;
@@ -794,18 +786,6 @@ static long update_time_since_previous_sample(long *time_at_previous_sample_ns,
794
786
  return elapsed_time_ns;
795
787
  }
796
788
 
797
- // Safety: This function is assumed never to raise exceptions by callers when raise_on_failure == false
798
- static long wall_time_now_ns(bool raise_on_failure) {
799
- struct timespec current_monotonic;
800
-
801
- if (clock_gettime(CLOCK_MONOTONIC, &current_monotonic) != 0) {
802
- if (raise_on_failure) rb_sys_fail("Failed to read CLOCK_MONOTONIC");
803
- else return 0;
804
- }
805
-
806
- return current_monotonic.tv_nsec + (current_monotonic.tv_sec * 1000 * 1000 * 1000);
807
- }
808
-
809
789
  // Safety: This function is assumed never to raise exceptions by callers
810
790
  static long cpu_time_now_ns(struct per_thread_context *thread_context) {
811
791
  thread_cpu_time cpu_time = thread_cpu_time_for(thread_context->thread_cpu_time_id);
@@ -872,19 +852,13 @@ static void trace_identifiers_for(struct cpu_and_wall_time_collector_state *stat
872
852
  if (numeric_local_root_span_id == Qnil || numeric_span_id == Qnil) return;
873
853
 
874
854
  unsigned long long local_root_span_id = NUM2ULL(numeric_local_root_span_id);
875
- unsigned long long span_id = NUM2ULL(numeric_span_id);
876
-
877
855
  snprintf(trace_identifiers_result->local_root_span_id_buffer, MAXIMUM_LENGTH_64_BIT_IDENTIFIER, "%llu", local_root_span_id);
878
- snprintf(trace_identifiers_result->span_id_buffer, MAXIMUM_LENGTH_64_BIT_IDENTIFIER, "%llu", span_id);
879
856
 
880
857
  trace_identifiers_result->local_root_span_id = (ddog_CharSlice) {
881
858
  .ptr = trace_identifiers_result->local_root_span_id_buffer,
882
859
  .len = strlen(trace_identifiers_result->local_root_span_id_buffer)
883
860
  };
884
- trace_identifiers_result->span_id = (ddog_CharSlice) {
885
- .ptr = trace_identifiers_result->span_id_buffer,
886
- .len = strlen(trace_identifiers_result->span_id_buffer)
887
- };
861
+ trace_identifiers_result->span_id = NUM2ULL(numeric_span_id);
888
862
 
889
863
  trace_identifiers_result->valid = true;
890
864
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  #include <ruby.h>
4
4
 
5
- VALUE cpu_and_wall_time_collector_sample(VALUE self_instance);
5
+ void cpu_and_wall_time_collector_sample(VALUE self_instance, long current_monotonic_wall_time_ns);
6
6
  VALUE cpu_and_wall_time_collector_sample_after_gc(VALUE self_instance);
7
7
  void cpu_and_wall_time_collector_on_gc_start(VALUE self_instance);
8
8
  void cpu_and_wall_time_collector_on_gc_finish(VALUE self_instance);