From e979f1d74062b752f95947eaf90fdcb805906c29 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Fri, 21 Jan 2022 17:08:27 -0800 Subject: [PATCH 1/5] Namespacing: Profiling --- .rubocop.yml | 2 +- .rubocop_todo.yml | 70 +++++++++---------- Gemfile | 2 +- bin/ddtracerb | 10 +-- docs/ProfilingDevelopment.md | 8 +-- lib/datadog/core/configuration/components.rb | 2 +- lib/datadog/core/configuration/settings.rb | 10 +-- lib/{ddtrace => datadog}/profiling.rb | 26 +++---- .../profiling/backtrace_location.rb | 0 lib/{ddtrace => datadog}/profiling/buffer.rb | 0 .../profiling/collectors/code_provenance.rb | 0 .../profiling/collectors/stack.rb | 6 +- .../profiling/encoding/profile.rb | 4 +- lib/{ddtrace => datadog}/profiling/event.rb | 0 .../profiling/events/stack.rb | 2 +- .../profiling/exporter.rb | 2 +- .../profiling.rb => datadog/profiling/ext.rb} | 4 +- .../profiling/ext/forking.rb | 0 lib/{ddtrace => datadog}/profiling/flush.rb | 0 .../profiling/native_extension.rb | 0 .../profiling/pprof/builder.rb | 6 +- .../profiling/pprof/converter.rb | 4 +- .../profiling/pprof/message_set.rb | 0 .../profiling/pprof/payload.rb | 0 .../profiling/pprof/pprof.proto | 0 .../profiling/pprof/pprof_pb.rb | 2 +- .../profiling/pprof/stack_sample.rb | 26 +++---- .../profiling/pprof/string_table.rb | 0 .../profiling/pprof/template.rb | 10 +-- lib/datadog/profiling/preload.rb | 4 ++ .../profiling/profiler.rb | 0 .../profiling/recorder.rb | 4 +- .../profiling/scheduler.rb | 0 lib/datadog/profiling/tasks/exec.rb | 49 +++++++++++++ lib/datadog/profiling/tasks/help.rb | 17 +++++ .../profiling/tasks/setup.rb | 4 +- .../profiling/trace_identifiers/ddtrace.rb | 0 .../profiling/trace_identifiers/helper.rb | 2 +- .../profiling/transport/client.rb | 0 .../profiling/transport/http.rb | 8 +-- .../profiling/transport/http/api.rb | 8 +-- .../profiling/transport/http/api/endpoint.rb | 6 +- .../profiling/transport/http/api/instance.rb | 2 +- .../profiling/transport/http/api/spec.rb | 0 .../profiling/transport/http/builder.rb | 4 +- .../profiling/transport/http/client.rb | 2 +- .../profiling/transport/http/response.rb | 2 +- .../profiling/transport/io.rb | 4 +- .../profiling/transport/io/client.rb | 6 +- .../profiling/transport/io/response.rb | 2 +- .../profiling/transport/parcel.rb | 0 .../profiling/transport/request.rb | 2 +- .../profiling/transport/response.rb | 0 lib/ddtrace.rb | 2 +- lib/ddtrace/profiling/preload.rb | 6 +- lib/ddtrace/tasks/exec.rb | 47 ------------- lib/ddtrace/tasks/help.rb | 15 ---- .../core/configuration/settings_spec.rb | 16 ++--- .../profiling/backtrace_location_spec.rb | 2 +- .../profiling/buffer_spec.rb | 2 +- .../collectors/code_provenance_spec.rb | 2 +- .../profiling/collectors/stack_spec.rb | 8 +-- .../profiling/encoding/profile_spec.rb | 4 +- .../profiling/event_spec.rb | 2 +- .../profiling/events/stack_spec.rb | 2 +- .../profiling/exporter_spec.rb | 6 +- .../profiling/ext/forking_spec.rb | 12 ++-- .../profiling/flush_spec.rb | 0 .../profiling/integration_spec.rb | 36 +++++----- .../profiling/native_extension_spec.rb | 2 +- .../profiling/pprof/builder_spec.rb | 6 +- .../profiling/pprof/converter_spec.rb | 6 +- .../profiling/pprof/message_set_spec.rb | 2 +- .../profiling/pprof/payload_spec.rb | 2 +- .../profiling/pprof/stack_sample_spec.rb | 26 +++---- .../profiling/pprof/string_table_spec.rb | 2 +- .../profiling/pprof/template_spec.rb | 12 ++-- .../profiling/preload_spec.rb | 4 +- .../profiling/profiler_spec.rb | 4 +- .../profiling/recorder_spec.rb | 6 +- .../profiling/scheduler_spec.rb | 6 +- .../profiling/spec_helper.rb | 2 +- .../profiling}/tasks/exec_spec.rb | 6 +- .../profiling}/tasks/help_spec.rb | 4 +- .../profiling/tasks/setup_spec.rb | 8 +-- .../trace_identifiers/ddtrace_spec.rb | 2 +- .../trace_identifiers/helper_spec.rb | 4 +- .../profiling/transport/client_spec.rb | 4 +- .../http/adapters/net_integration_spec.rb | 8 +-- .../transport/http/api/endpoint_spec.rb | 12 ++-- .../transport/http/api/instance_spec.rb | 6 +- .../profiling/transport/http/api/spec_spec.rb | 6 +- .../profiling/transport/http/api_spec.rb | 2 +- .../profiling/transport/http/builder_spec.rb | 2 +- .../profiling/transport/http/client_spec.rb | 0 .../transport/http/integration_spec.rb | 4 +- .../profiling/transport/http/response_spec.rb | 2 +- .../profiling/transport/http_spec.rb | 8 +-- .../profiling/transport/io/client_spec.rb | 4 +- .../profiling/transport/io/response_spec.rb | 2 +- .../profiling/transport/io_spec.rb | 2 +- .../profiling/transport/parcel_spec.rb | 2 +- .../profiling/transport/request_spec.rb | 4 +- .../profiling/validate_benchmarks_spec.rb | 0 spec/ddtrace/profiling_spec.rb | 2 +- 105 files changed, 332 insertions(+), 326 deletions(-) rename lib/{ddtrace => datadog}/profiling.rb (93%) rename lib/{ddtrace => datadog}/profiling/backtrace_location.rb (100%) rename lib/{ddtrace => datadog}/profiling/buffer.rb (100%) rename lib/{ddtrace => datadog}/profiling/collectors/code_provenance.rb (100%) rename lib/{ddtrace => datadog}/profiling/collectors/stack.rb (98%) rename lib/{ddtrace => datadog}/profiling/encoding/profile.rb (94%) rename lib/{ddtrace => datadog}/profiling/event.rb (100%) rename lib/{ddtrace => datadog}/profiling/events/stack.rb (98%) rename lib/{ddtrace => datadog}/profiling/exporter.rb (90%) rename lib/{ddtrace/ext/profiling.rb => datadog/profiling/ext.rb} (98%) rename lib/{ddtrace => datadog}/profiling/ext/forking.rb (100%) rename lib/{ddtrace => datadog}/profiling/flush.rb (100%) rename lib/{ddtrace => datadog}/profiling/native_extension.rb (100%) rename lib/{ddtrace => datadog}/profiling/pprof/builder.rb (96%) rename lib/{ddtrace => datadog}/profiling/pprof/converter.rb (95%) rename lib/{ddtrace => datadog}/profiling/pprof/message_set.rb (100%) rename lib/{ddtrace => datadog}/profiling/pprof/payload.rb (100%) rename lib/{ddtrace => datadog}/profiling/pprof/pprof.proto (100%) rename lib/{ddtrace => datadog}/profiling/pprof/pprof_pb.rb (98%) rename lib/{ddtrace => datadog}/profiling/pprof/stack_sample.rb (82%) rename lib/{ddtrace => datadog}/profiling/pprof/string_table.rb (100%) rename lib/{ddtrace => datadog}/profiling/pprof/template.rb (94%) create mode 100644 lib/datadog/profiling/preload.rb rename lib/{ddtrace => datadog}/profiling/profiler.rb (100%) rename lib/{ddtrace => datadog}/profiling/recorder.rb (98%) rename lib/{ddtrace => datadog}/profiling/scheduler.rb (100%) create mode 100644 lib/datadog/profiling/tasks/exec.rb create mode 100644 lib/datadog/profiling/tasks/help.rb rename lib/{ddtrace => datadog}/profiling/tasks/setup.rb (97%) rename lib/{ddtrace => datadog}/profiling/trace_identifiers/ddtrace.rb (100%) rename lib/{ddtrace => datadog}/profiling/trace_identifiers/helper.rb (96%) rename lib/{ddtrace => datadog}/profiling/transport/client.rb (100%) rename lib/{ddtrace => datadog}/profiling/transport/http.rb (95%) rename lib/{ddtrace => datadog}/profiling/transport/http/api.rb (82%) rename lib/{ddtrace => datadog}/profiling/transport/http/api/endpoint.rb (96%) rename lib/{ddtrace => datadog}/profiling/transport/http/api/instance.rb (94%) rename lib/{ddtrace => datadog}/profiling/transport/http/api/spec.rb (100%) rename lib/{ddtrace => datadog}/profiling/transport/http/builder.rb (88%) rename lib/{ddtrace => datadog}/profiling/transport/http/client.rb (95%) rename lib/{ddtrace => datadog}/profiling/transport/http/response.rb (91%) rename lib/{ddtrace => datadog}/profiling/transport/io.rb (88%) rename lib/{ddtrace => datadog}/profiling/transport/io/client.rb (81%) rename lib/{ddtrace => datadog}/profiling/transport/io/response.rb (88%) rename lib/{ddtrace => datadog}/profiling/transport/parcel.rb (100%) rename lib/{ddtrace => datadog}/profiling/transport/request.rb (86%) rename lib/{ddtrace => datadog}/profiling/transport/response.rb (100%) delete mode 100644 lib/ddtrace/tasks/exec.rb delete mode 100644 lib/ddtrace/tasks/help.rb rename spec/{ddtrace => datadog}/profiling/backtrace_location_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/buffer_spec.rb (96%) rename spec/{ddtrace => datadog}/profiling/collectors/code_provenance_spec.rb (99%) rename spec/{ddtrace => datadog}/profiling/collectors/stack_spec.rb (99%) rename spec/{ddtrace => datadog}/profiling/encoding/profile_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/event_spec.rb (88%) rename spec/{ddtrace => datadog}/profiling/events/stack_spec.rb (98%) rename spec/{ddtrace => datadog}/profiling/exporter_spec.rb (91%) rename spec/{ddtrace => datadog}/profiling/ext/forking_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/flush_spec.rb (100%) rename spec/{ddtrace => datadog}/profiling/integration_spec.rb (92%) rename spec/{ddtrace => datadog}/profiling/native_extension_spec.rb (99%) rename spec/{ddtrace => datadog}/profiling/pprof/builder_spec.rb (98%) rename spec/{ddtrace => datadog}/profiling/pprof/converter_spec.rb (96%) rename spec/{ddtrace => datadog}/profiling/pprof/message_set_spec.rb (94%) rename spec/{ddtrace => datadog}/profiling/pprof/payload_spec.rb (91%) rename spec/{ddtrace => datadog}/profiling/pprof/stack_sample_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/pprof/string_table_spec.rb (82%) rename spec/{ddtrace => datadog}/profiling/pprof/template_spec.rb (93%) rename spec/{ddtrace => datadog}/profiling/preload_spec.rb (84%) rename spec/{ddtrace => datadog}/profiling/profiler_spec.rb (94%) rename spec/{ddtrace => datadog}/profiling/recorder_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/scheduler_spec.rb (98%) rename spec/{ddtrace => datadog}/profiling/spec_helper.rb (98%) rename spec/{ddtrace => datadog/profiling}/tasks/exec_spec.rb (95%) rename spec/{ddtrace => datadog/profiling}/tasks/help_spec.rb (76%) rename spec/{ddtrace => datadog}/profiling/tasks/setup_spec.rb (98%) rename spec/{ddtrace => datadog}/profiling/trace_identifiers/ddtrace_spec.rb (98%) rename spec/{ddtrace => datadog}/profiling/trace_identifiers/helper_spec.rb (96%) rename spec/{ddtrace => datadog}/profiling/transport/client_spec.rb (87%) rename spec/{ddtrace => datadog}/profiling/transport/http/adapters/net_integration_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/transport/http/api/endpoint_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/transport/http/api/instance_spec.rb (86%) rename spec/{ddtrace => datadog}/profiling/transport/http/api/spec_spec.rb (90%) rename spec/{ddtrace => datadog}/profiling/transport/http/api_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/transport/http/builder_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/transport/http/client_spec.rb (100%) rename spec/{ddtrace => datadog}/profiling/transport/http/integration_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/transport/http/response_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/transport/http_spec.rb (96%) rename spec/{ddtrace => datadog}/profiling/transport/io/client_spec.rb (95%) rename spec/{ddtrace => datadog}/profiling/transport/io/response_spec.rb (87%) rename spec/{ddtrace => datadog}/profiling/transport/io_spec.rb (97%) rename spec/{ddtrace => datadog}/profiling/transport/parcel_spec.rb (94%) rename spec/{ddtrace => datadog}/profiling/transport/request_spec.rb (85%) rename spec/{ddtrace => datadog}/profiling/validate_benchmarks_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index c1edc2a7b04..cbea0594804 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,7 +21,7 @@ AllCops: - 'lib/datadog/**/vendor/**/*.rb' - 'integration/apps/*/bin/*' - 'integration/apps/*/Gemfile' - - 'lib/ddtrace/profiling/pprof/pprof_pb.rb' + - 'lib/datadog/profiling/pprof/pprof_pb.rb' NewCops: disable # Don't allow new cops to be enabled implicitly. # 80 characters is a nice goal, but not worth currently changing in existing diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b51be3cdb9..0b6db3a7927 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,13 +90,13 @@ Lint/MissingSuper: - 'lib/ddtrace/opentracer/scope.rb' - 'lib/ddtrace/opentracer/span.rb' - 'lib/ddtrace/opentracer/span_context.rb' - - 'lib/ddtrace/profiling/collectors/stack.rb' - - 'lib/ddtrace/profiling/pprof/converter.rb' - - 'lib/ddtrace/profiling/pprof/template.rb' - - 'lib/ddtrace/profiling/recorder.rb' - - 'lib/ddtrace/profiling/scheduler.rb' - - 'lib/ddtrace/profiling/transport/http/api/instance.rb' - - 'lib/ddtrace/profiling/transport/http/api/spec.rb' + - 'lib/datadog/profiling/collectors/stack.rb' + - 'lib/datadog/profiling/pprof/converter.rb' + - 'lib/datadog/profiling/pprof/template.rb' + - 'lib/datadog/profiling/recorder.rb' + - 'lib/datadog/profiling/scheduler.rb' + - 'lib/datadog/profiling/transport/http/api/instance.rb' + - 'lib/datadog/profiling/transport/http/api/spec.rb' - 'lib/ddtrace/sampler.rb' - 'lib/ddtrace/sampling/matcher.rb' - 'lib/ddtrace/sampling/rate_limiter.rb' @@ -115,7 +115,7 @@ Lint/MissingSuper: # Offense count: 1 Lint/StructNewOverride: Exclude: - - 'lib/ddtrace/profiling/pprof/converter.rb' + - 'lib/datadog/profiling/pprof/converter.rb' # Offense count: 1 # Configuration parameters: AllowComments. @@ -164,10 +164,10 @@ Performance/MethodObjectAsBlock: - 'lib/datadog/ci/contrib/cucumber/formatter.rb' - 'lib/ddtrace/contrib/delayed_job/plugin.rb' - 'lib/ddtrace/pipeline.rb' - - 'lib/ddtrace/profiling/collectors/stack.rb' - - 'lib/ddtrace/profiling/pprof/builder.rb' - - 'lib/ddtrace/profiling/pprof/stack_sample.rb' - - 'lib/ddtrace/profiling/pprof/template.rb' + - 'lib/datadog/profiling/collectors/stack.rb' + - 'lib/datadog/profiling/pprof/builder.rb' + - 'lib/datadog/profiling/pprof/stack_sample.rb' + - 'lib/datadog/profiling/pprof/template.rb' - 'spec/datadog/ci/contrib/cucumber/patcher_spec.rb' # Offense count: 6 @@ -363,29 +363,29 @@ RSpec/VerifiedDoubles: - 'spec/ddtrace/opentracer/tracer_spec.rb' - 'spec/ddtrace/patcher_spec.rb' - 'spec/ddtrace/pin_spec.rb' - - 'spec/ddtrace/profiling/backtrace_location_spec.rb' - - 'spec/ddtrace/profiling/collectors/stack_spec.rb' - - 'spec/ddtrace/profiling/encoding/profile_spec.rb' - - 'spec/ddtrace/profiling/events/stack_spec.rb' - - 'spec/ddtrace/profiling/exporter_spec.rb' - - 'spec/ddtrace/profiling/ext/cthread_spec.rb' - - 'spec/ddtrace/profiling/ext/forking_spec.rb' - - 'spec/ddtrace/profiling/flush_spec.rb' - - 'spec/ddtrace/profiling/pprof/builder_spec.rb' - - 'spec/ddtrace/profiling/pprof/converter_spec.rb' - - 'spec/ddtrace/profiling/pprof/message_set_spec.rb' - - 'spec/ddtrace/profiling/pprof/payload_spec.rb' - - 'spec/ddtrace/profiling/pprof/template_spec.rb' - - 'spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb' - - 'spec/ddtrace/profiling/transport/http/api/instance_spec.rb' - - 'spec/ddtrace/profiling/transport/http/builder_spec.rb' - - 'spec/ddtrace/profiling/transport/http/client_spec.rb' - - 'spec/ddtrace/profiling/transport/http/response_spec.rb' - - 'spec/ddtrace/profiling/transport/http_spec.rb' - - 'spec/ddtrace/profiling/transport/io/client_spec.rb' - - 'spec/ddtrace/profiling/transport/io/response_spec.rb' - - 'spec/ddtrace/profiling/transport/io_spec.rb' - - 'spec/ddtrace/profiling/transport/parcel_spec.rb' + - 'spec/datadog/profiling/backtrace_location_spec.rb' + - 'spec/datadog/profiling/collectors/stack_spec.rb' + - 'spec/datadog/profiling/encoding/profile_spec.rb' + - 'spec/datadog/profiling/events/stack_spec.rb' + - 'spec/datadog/profiling/exporter_spec.rb' + - 'spec/datadog/profiling/ext/cthread_spec.rb' + - 'spec/datadog/profiling/ext/forking_spec.rb' + - 'spec/datadog/profiling/flush_spec.rb' + - 'spec/datadog/profiling/pprof/builder_spec.rb' + - 'spec/datadog/profiling/pprof/converter_spec.rb' + - 'spec/datadog/profiling/pprof/message_set_spec.rb' + - 'spec/datadog/profiling/pprof/payload_spec.rb' + - 'spec/datadog/profiling/pprof/template_spec.rb' + - 'spec/datadog/profiling/transport/http/api/endpoint_spec.rb' + - 'spec/datadog/profiling/transport/http/api/instance_spec.rb' + - 'spec/datadog/profiling/transport/http/builder_spec.rb' + - 'spec/datadog/profiling/transport/http/client_spec.rb' + - 'spec/datadog/profiling/transport/http/response_spec.rb' + - 'spec/datadog/profiling/transport/http_spec.rb' + - 'spec/datadog/profiling/transport/io/client_spec.rb' + - 'spec/datadog/profiling/transport/io/response_spec.rb' + - 'spec/datadog/profiling/transport/io_spec.rb' + - 'spec/datadog/profiling/transport/parcel_spec.rb' - 'spec/ddtrace/profiling_spec.rb' - 'spec/ddtrace/runtime/metrics_spec.rb' - 'spec/ddtrace/tasks/exec_spec.rb' diff --git a/Gemfile b/Gemfile index 0425aa6f658..d2da9768bf5 100644 --- a/Gemfile +++ b/Gemfile @@ -71,7 +71,7 @@ gem 'opentracing', '>= 0.4.1' # Profiler optional dependencies # NOTE: We're excluding versions 3.7.0 and 3.7.1 for the reasons documented in #1424 and the big comment in -# lib/ddtrace/profiling.rb: it breaks for some older rubies in CI without BUNDLE_FORCE_RUBY_PLATFORM=true. +# lib/datadog/profiling.rb: it breaks for some older rubies in CI without BUNDLE_FORCE_RUBY_PLATFORM=true. # Since most of our customers won't have BUNDLE_FORCE_RUBY_PLATFORM=true, it's not something we want to add # to our CI, so we just shortcut and exclude specific versions that were affecting our CI. if RUBY_PLATFORM != 'java' diff --git a/bin/ddtracerb b/bin/ddtracerb index 5d856d8a938..aa9e8d2402f 100755 --- a/bin/ddtracerb +++ b/bin/ddtracerb @@ -1,15 +1,15 @@ #!/usr/bin/env ruby -require 'ddtrace/tasks/exec' -require 'ddtrace/tasks/help' +require 'datadog/profiling/tasks/exec' +require 'datadog/profiling/tasks/help' command = ARGV.shift case command when 'exec' - Datadog::Tasks::Exec.new(ARGV).run + Datadog::Profiling::Tasks::Exec.new(ARGV).run when 'help', '--help' - Datadog::Tasks::Help.new.run + Datadog::Profiling::Tasks::Help.new.run else puts "Command '#{command}' is not valid for ddtrace." - Datadog::Tasks::Help.new.run + Datadog::Profiling::Tasks::Help.new.run end diff --git a/docs/ProfilingDevelopment.md b/docs/ProfilingDevelopment.md index 34570b7073c..49d2726a4e3 100644 --- a/docs/ProfilingDevelopment.md +++ b/docs/ProfilingDevelopment.md @@ -6,7 +6,7 @@ For a more practical view of getting started with development of `ddtrace`, see ## Profiling components high-level view -Components below live inside <../lib/ddtrace/profiling>: +Components below live inside <../lib/datadog/profiling>: * `Collectors::Stack`: Collects stack trace samples from Ruby threads for both CPU-time (if available) and wall-clock. Runs on its own background thread. @@ -15,9 +15,9 @@ Components below live inside <../lib/ddtrace/profiling>: * `Events::Stack`, `Events::StackSample`: Entity classes used to represent stacks. * `Ext::Forking`: Monkey patches `Kernel#fork`, adding a `Kernel#at_fork` callback mechanism which is used to restore profiling abilities after the VM forks (such as re-instrumenting the main thread, and restarting profiler threads). -* `Pprof::*` (in <../lib/ddtrace/profiling/pprof>): Converts samples captured in the `Recorder` into the pprof format. +* `Pprof::*` (in <../lib/datadog/profiling/pprof>): Converts samples captured in the `Recorder` into the pprof format. * `Tasks::Setup`: Takes care of loading our extensions/monkey patches to handle fork(). -* `Transport::*` (in <../lib/ddtrace/profiling/transport>): Implements transmission of profiling payloads to the Datadog agent +* `Transport::*` (in <../lib/datadog/profiling/transport>): Implements transmission of profiling payloads to the Datadog agent or backend. * `TraceIdentifiers::*`: Used to retrieve trace id and span id from tracers, to be used to connect traces to profiles. * `BacktraceLocation`: Entity class used to represent an entry in a stack trace. @@ -34,7 +34,7 @@ Components below live inside <../lib/ddtrace/profiling>: When started via `ddtracerb exec` (together with `DD_PROFILING_ENABLED=true`), initialization goes through the following flow: -1. <../lib/ddtrace/profiling/preload.rb> triggers the creation of the `Datadog.profiler` instance by calling the method +1. <../lib/datadog/profiling/preload.rb> triggers the creation of the `Datadog.profiler` instance by calling the method 2. `Datadog.profiler` is handled by `Datadog::Configuration`, which triggers the configuration of `ddtrace` components in `#build_components` 3. Inside `Datadog::Components`, the `build_profiler` method triggers the execution of the `Tasks::Setup` diff --git a/lib/datadog/core/configuration/components.rb b/lib/datadog/core/configuration/components.rb index ecf4705eeda..2e4c50ed174 100644 --- a/lib/datadog/core/configuration/components.rb +++ b/lib/datadog/core/configuration/components.rb @@ -2,7 +2,7 @@ require 'datadog/core/configuration/agent_settings_resolver' require 'datadog/core/diagnostics/health' require 'datadog/core/logger' -require 'ddtrace/profiling' +require 'datadog/profiling' require 'datadog/core/runtime/metrics' require 'ddtrace/tracer' require 'ddtrace/trace_flush' diff --git a/lib/datadog/core/configuration/settings.rb b/lib/datadog/core/configuration/settings.rb index 156a33a5d2d..c11c6863d6a 100644 --- a/lib/datadog/core/configuration/settings.rb +++ b/lib/datadog/core/configuration/settings.rb @@ -6,7 +6,7 @@ require 'ddtrace/ext/distributed' require 'datadog/core/environment/ext' require 'datadog/core/runtime/ext' -require 'ddtrace/ext/profiling' +require 'datadog/profiling/ext' require 'ddtrace/ext/sampling' require 'ddtrace/ext/test' @@ -251,7 +251,7 @@ def initialize(*_) # @default `DD_PROFILING_ENABLED` environment variable, otherwise `false` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Ext::Profiling::ENV_ENABLED, false) } + o.default { env_to_bool(Profiling::Ext::ENV_ENABLED, false) } o.lazy end @@ -270,7 +270,7 @@ def initialize(*_) # Controls the maximum number of frames for each thread sampled. Can be tuned to avoid omitted frames in the # produced profiles. Increasing this may increase the overhead of profiling. option :max_frames do |o| - o.default { env_to_int(Ext::Profiling::ENV_MAX_FRAMES, 400) } + o.default { env_to_int(Profiling::Ext::ENV_MAX_FRAMES, 400) } o.lazy end @@ -283,7 +283,7 @@ def initialize(*_) # @default `DD_PROFILING_ENDPOINT_COLLECTION_ENABLED` environment variable, otherwise `true` # @return [Boolean] option :enabled do |o| - o.default { env_to_bool(Ext::Profiling::ENV_ENDPOINT_COLLECTION_ENABLED, true) } + o.default { env_to_bool(Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED, true) } o.lazy end end @@ -298,7 +298,7 @@ def initialize(*_) settings :upload do option :timeout_seconds do |o| o.setter { |value| value.nil? ? 30.0 : value.to_f } - o.default { env_to_float(Ext::Profiling::ENV_UPLOAD_TIMEOUT, 30.0) } + o.default { env_to_float(Profiling::Ext::ENV_UPLOAD_TIMEOUT, 30.0) } o.lazy end end diff --git a/lib/ddtrace/profiling.rb b/lib/datadog/profiling.rb similarity index 93% rename from lib/ddtrace/profiling.rb rename to lib/datadog/profiling.rb index 28f1e49928c..ac3a3448a74 100644 --- a/lib/ddtrace/profiling.rb +++ b/lib/datadog/profiling.rb @@ -184,19 +184,19 @@ def self.configuration private_class_method def self.load_profiling return false unless supported? - require 'ddtrace/profiling/ext/forking' - require 'ddtrace/profiling/collectors/code_provenance' - require 'ddtrace/profiling/collectors/stack' - require 'ddtrace/profiling/exporter' - require 'ddtrace/profiling/recorder' - require 'ddtrace/profiling/scheduler' - require 'ddtrace/profiling/tasks/setup' - require 'ddtrace/profiling/transport/io' - require 'ddtrace/profiling/transport/http' - require 'ddtrace/profiling/profiler' - require 'ddtrace/profiling/native_extension' - require 'ddtrace/profiling/trace_identifiers/helper' - require 'ddtrace/profiling/pprof/pprof_pb' + require 'datadog/profiling/ext/forking' + require 'datadog/profiling/collectors/code_provenance' + require 'datadog/profiling/collectors/stack' + require 'datadog/profiling/exporter' + require 'datadog/profiling/recorder' + require 'datadog/profiling/scheduler' + require 'datadog/profiling/tasks/setup' + require 'datadog/profiling/transport/io' + require 'datadog/profiling/transport/http' + require 'datadog/profiling/profiler' + require 'datadog/profiling/native_extension' + require 'datadog/profiling/trace_identifiers/helper' + require 'datadog/profiling/pprof/pprof_pb' true end diff --git a/lib/ddtrace/profiling/backtrace_location.rb b/lib/datadog/profiling/backtrace_location.rb similarity index 100% rename from lib/ddtrace/profiling/backtrace_location.rb rename to lib/datadog/profiling/backtrace_location.rb diff --git a/lib/ddtrace/profiling/buffer.rb b/lib/datadog/profiling/buffer.rb similarity index 100% rename from lib/ddtrace/profiling/buffer.rb rename to lib/datadog/profiling/buffer.rb diff --git a/lib/ddtrace/profiling/collectors/code_provenance.rb b/lib/datadog/profiling/collectors/code_provenance.rb similarity index 100% rename from lib/ddtrace/profiling/collectors/code_provenance.rb rename to lib/datadog/profiling/collectors/code_provenance.rb diff --git a/lib/ddtrace/profiling/collectors/stack.rb b/lib/datadog/profiling/collectors/stack.rb similarity index 98% rename from lib/ddtrace/profiling/collectors/stack.rb rename to lib/datadog/profiling/collectors/stack.rb index eb66dcae62c..3c986b7c9cf 100644 --- a/lib/ddtrace/profiling/collectors/stack.rb +++ b/lib/datadog/profiling/collectors/stack.rb @@ -1,8 +1,8 @@ # typed: false -require 'ddtrace/profiling/native_extension' -require 'ddtrace/profiling/backtrace_location' -require 'ddtrace/profiling/events/stack' +require 'datadog/profiling/native_extension' +require 'datadog/profiling/backtrace_location' +require 'datadog/profiling/events/stack' require 'datadog/core/utils/only_once' require 'datadog/core/utils/time' require 'datadog/core/worker' diff --git a/lib/ddtrace/profiling/encoding/profile.rb b/lib/datadog/profiling/encoding/profile.rb similarity index 94% rename from lib/ddtrace/profiling/encoding/profile.rb rename to lib/datadog/profiling/encoding/profile.rb index 5acd2ae589e..150c0e81f76 100644 --- a/lib/ddtrace/profiling/encoding/profile.rb +++ b/lib/datadog/profiling/encoding/profile.rb @@ -2,8 +2,8 @@ require 'set' require 'time' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/pprof/template' +require 'datadog/profiling/flush' +require 'datadog/profiling/pprof/template' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/event.rb b/lib/datadog/profiling/event.rb similarity index 100% rename from lib/ddtrace/profiling/event.rb rename to lib/datadog/profiling/event.rb diff --git a/lib/ddtrace/profiling/events/stack.rb b/lib/datadog/profiling/events/stack.rb similarity index 98% rename from lib/ddtrace/profiling/events/stack.rb rename to lib/datadog/profiling/events/stack.rb index 0148473b86c..3a583a2810c 100644 --- a/lib/ddtrace/profiling/events/stack.rb +++ b/lib/datadog/profiling/events/stack.rb @@ -1,5 +1,5 @@ # typed: true -require 'ddtrace/profiling/event' +require 'datadog/profiling/event' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/exporter.rb b/lib/datadog/profiling/exporter.rb similarity index 90% rename from lib/ddtrace/profiling/exporter.rb rename to lib/datadog/profiling/exporter.rb index 872dc00dece..4ca9b107c7c 100644 --- a/lib/ddtrace/profiling/exporter.rb +++ b/lib/datadog/profiling/exporter.rb @@ -1,5 +1,5 @@ # typed: true -require 'ddtrace/profiling/transport/io/client' +require 'datadog/profiling/transport/io/client' module Datadog module Profiling diff --git a/lib/ddtrace/ext/profiling.rb b/lib/datadog/profiling/ext.rb similarity index 98% rename from lib/ddtrace/ext/profiling.rb rename to lib/datadog/profiling/ext.rb index 8c347ce29a2..722eff545ef 100644 --- a/lib/ddtrace/ext/profiling.rb +++ b/lib/datadog/profiling/ext.rb @@ -1,7 +1,7 @@ # typed: true module Datadog - module Ext - module Profiling + module Profiling + module Ext ENV_ENABLED = 'DD_PROFILING_ENABLED'.freeze ENV_UPLOAD_TIMEOUT = 'DD_PROFILING_UPLOAD_TIMEOUT'.freeze ENV_MAX_FRAMES = 'DD_PROFILING_MAX_FRAMES'.freeze diff --git a/lib/ddtrace/profiling/ext/forking.rb b/lib/datadog/profiling/ext/forking.rb similarity index 100% rename from lib/ddtrace/profiling/ext/forking.rb rename to lib/datadog/profiling/ext/forking.rb diff --git a/lib/ddtrace/profiling/flush.rb b/lib/datadog/profiling/flush.rb similarity index 100% rename from lib/ddtrace/profiling/flush.rb rename to lib/datadog/profiling/flush.rb diff --git a/lib/ddtrace/profiling/native_extension.rb b/lib/datadog/profiling/native_extension.rb similarity index 100% rename from lib/ddtrace/profiling/native_extension.rb rename to lib/datadog/profiling/native_extension.rb diff --git a/lib/ddtrace/profiling/pprof/builder.rb b/lib/datadog/profiling/pprof/builder.rb similarity index 96% rename from lib/ddtrace/profiling/pprof/builder.rb rename to lib/datadog/profiling/pprof/builder.rb index 3b384cce86c..2153c13ff26 100644 --- a/lib/ddtrace/profiling/pprof/builder.rb +++ b/lib/datadog/profiling/pprof/builder.rb @@ -1,9 +1,9 @@ # typed: true # frozen_string_literal: true -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/pprof/message_set' -require 'ddtrace/profiling/pprof/string_table' +require 'datadog/profiling/flush' +require 'datadog/profiling/pprof/message_set' +require 'datadog/profiling/pprof/string_table' require 'datadog/core/utils/time' module Datadog diff --git a/lib/ddtrace/profiling/pprof/converter.rb b/lib/datadog/profiling/pprof/converter.rb similarity index 95% rename from lib/ddtrace/profiling/pprof/converter.rb rename to lib/datadog/profiling/pprof/converter.rb index f52e573e1c6..e382170c8ad 100644 --- a/lib/ddtrace/profiling/pprof/converter.rb +++ b/lib/datadog/profiling/pprof/converter.rb @@ -1,5 +1,5 @@ # typed: true -require 'ddtrace/ext/profiling' +require 'datadog/profiling/ext' module Datadog module Profiling @@ -59,7 +59,7 @@ def sample_value_index(type) def build_event_values(event) # Build a value array that matches the length of the sample types # Populate all values with "no value" by default - Array.new(@sample_type_mappings.length, Datadog::Ext::Profiling::Pprof::SAMPLE_VALUE_NO_VALUE) + Array.new(@sample_type_mappings.length, Datadog::Profiling::Ext::Pprof::SAMPLE_VALUE_NO_VALUE) end def debug_statistics diff --git a/lib/ddtrace/profiling/pprof/message_set.rb b/lib/datadog/profiling/pprof/message_set.rb similarity index 100% rename from lib/ddtrace/profiling/pprof/message_set.rb rename to lib/datadog/profiling/pprof/message_set.rb diff --git a/lib/ddtrace/profiling/pprof/payload.rb b/lib/datadog/profiling/pprof/payload.rb similarity index 100% rename from lib/ddtrace/profiling/pprof/payload.rb rename to lib/datadog/profiling/pprof/payload.rb diff --git a/lib/ddtrace/profiling/pprof/pprof.proto b/lib/datadog/profiling/pprof/pprof.proto similarity index 100% rename from lib/ddtrace/profiling/pprof/pprof.proto rename to lib/datadog/profiling/pprof/pprof.proto diff --git a/lib/ddtrace/profiling/pprof/pprof_pb.rb b/lib/datadog/profiling/pprof/pprof_pb.rb similarity index 98% rename from lib/ddtrace/profiling/pprof/pprof_pb.rb rename to lib/datadog/profiling/pprof/pprof_pb.rb index f3dde79a422..8c728bb8d7e 100644 --- a/lib/ddtrace/profiling/pprof/pprof_pb.rb +++ b/lib/datadog/profiling/pprof/pprof_pb.rb @@ -1,6 +1,6 @@ # typed: false # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: lib/ddtrace/profiling/pprof/pprof.proto +# source: lib/datadog/profiling/pprof/pprof.proto require 'google/protobuf' diff --git a/lib/ddtrace/profiling/pprof/stack_sample.rb b/lib/datadog/profiling/pprof/stack_sample.rb similarity index 82% rename from lib/ddtrace/profiling/pprof/stack_sample.rb rename to lib/datadog/profiling/pprof/stack_sample.rb index 1942455897e..b9907756d1b 100644 --- a/lib/ddtrace/profiling/pprof/stack_sample.rb +++ b/lib/datadog/profiling/pprof/stack_sample.rb @@ -1,8 +1,8 @@ # typed: true -require 'ddtrace/ext/profiling' -require 'ddtrace/profiling/events/stack' -require 'ddtrace/profiling/pprof/builder' -require 'ddtrace/profiling/pprof/converter' +require 'datadog/profiling/ext' +require 'datadog/profiling/events/stack' +require 'datadog/profiling/pprof/builder' +require 'datadog/profiling/pprof/converter' module Datadog module Profiling @@ -14,12 +14,12 @@ module Pprof class StackSample < Converter SAMPLE_TYPES = { cpu_time_ns: [ - Datadog::Ext::Profiling::Pprof::VALUE_TYPE_CPU, - Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS + Datadog::Profiling::Ext::Pprof::VALUE_TYPE_CPU, + Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS ], wall_time_ns: [ - Datadog::Ext::Profiling::Pprof::VALUE_TYPE_WALL, - Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS + Datadog::Profiling::Ext::Pprof::VALUE_TYPE_WALL, + Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS ] }.freeze @@ -85,7 +85,7 @@ def build_sample(stack_sample, values) end def build_event_values(stack_sample) - no_value = Datadog::Ext::Profiling::Pprof::SAMPLE_VALUE_NO_VALUE + no_value = Datadog::Profiling::Ext::Pprof::SAMPLE_VALUE_NO_VALUE values = super(stack_sample) values[sample_value_index(:cpu_time_ns)] = stack_sample.cpu_time_interval_ns || no_value values[sample_value_index(:wall_time_ns)] = stack_sample.wall_time_interval_ns || no_value @@ -95,7 +95,7 @@ def build_event_values(stack_sample) def build_sample_labels(stack_sample) labels = [ Perftools::Profiles::Label.new( - key: builder.string_table.fetch(Datadog::Ext::Profiling::Pprof::LABEL_KEY_THREAD_ID), + key: builder.string_table.fetch(Datadog::Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID), str: builder.string_table.fetch(stack_sample.thread_id.to_s) ) ] @@ -107,12 +107,12 @@ def build_sample_labels(stack_sample) @processed_with_trace += 1 labels << Perftools::Profiles::Label.new( - key: builder.string_table.fetch(Datadog::Ext::Profiling::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), + key: builder.string_table.fetch(Datadog::Profiling::Ext::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), str: builder.string_table.fetch(root_span_id.to_s) ) labels << Perftools::Profiles::Label.new( - key: builder.string_table.fetch(Datadog::Ext::Profiling::Pprof::LABEL_KEY_SPAN_ID), + key: builder.string_table.fetch(Datadog::Profiling::Ext::Pprof::LABEL_KEY_SPAN_ID), str: builder.string_table.fetch(span_id.to_s) ) @@ -122,7 +122,7 @@ def build_sample_labels(stack_sample) if trace_resource && !trace_resource.empty? labels << Perftools::Profiles::Label.new( - key: builder.string_table.fetch(Datadog::Ext::Profiling::Pprof::LABEL_KEY_TRACE_ENDPOINT), + key: builder.string_table.fetch(Datadog::Profiling::Ext::Pprof::LABEL_KEY_TRACE_ENDPOINT), str: builder.string_table.fetch(trace_resource) ) end diff --git a/lib/ddtrace/profiling/pprof/string_table.rb b/lib/datadog/profiling/pprof/string_table.rb similarity index 100% rename from lib/ddtrace/profiling/pprof/string_table.rb rename to lib/datadog/profiling/pprof/string_table.rb diff --git a/lib/ddtrace/profiling/pprof/template.rb b/lib/datadog/profiling/pprof/template.rb similarity index 94% rename from lib/ddtrace/profiling/pprof/template.rb rename to lib/datadog/profiling/pprof/template.rb index 7ac50e7b6c2..23c9b347039 100644 --- a/lib/ddtrace/profiling/pprof/template.rb +++ b/lib/datadog/profiling/pprof/template.rb @@ -1,10 +1,10 @@ # typed: false -require 'ddtrace/profiling/pprof/payload' -require 'ddtrace/profiling/pprof/message_set' -require 'ddtrace/profiling/pprof/builder' +require 'datadog/profiling/pprof/payload' +require 'datadog/profiling/pprof/message_set' +require 'datadog/profiling/pprof/builder' -require 'ddtrace/profiling/events/stack' -require 'ddtrace/profiling/pprof/stack_sample' +require 'datadog/profiling/events/stack' +require 'datadog/profiling/pprof/stack_sample' module Datadog module Profiling diff --git a/lib/datadog/profiling/preload.rb b/lib/datadog/profiling/preload.rb new file mode 100644 index 00000000000..61cd81a7e6f --- /dev/null +++ b/lib/datadog/profiling/preload.rb @@ -0,0 +1,4 @@ +# typed: strict +require 'ddtrace' + +Datadog.profiler.start if Datadog.profiler diff --git a/lib/ddtrace/profiling/profiler.rb b/lib/datadog/profiling/profiler.rb similarity index 100% rename from lib/ddtrace/profiling/profiler.rb rename to lib/datadog/profiling/profiler.rb diff --git a/lib/ddtrace/profiling/recorder.rb b/lib/datadog/profiling/recorder.rb similarity index 98% rename from lib/ddtrace/profiling/recorder.rb rename to lib/datadog/profiling/recorder.rb index 6cefcdd23c4..c39f9dd96a8 100644 --- a/lib/ddtrace/profiling/recorder.rb +++ b/lib/datadog/profiling/recorder.rb @@ -1,6 +1,6 @@ # typed: true -require 'ddtrace/profiling/buffer' -require 'ddtrace/profiling/flush' +require 'datadog/profiling/buffer' +require 'datadog/profiling/flush' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/scheduler.rb b/lib/datadog/profiling/scheduler.rb similarity index 100% rename from lib/ddtrace/profiling/scheduler.rb rename to lib/datadog/profiling/scheduler.rb diff --git a/lib/datadog/profiling/tasks/exec.rb b/lib/datadog/profiling/tasks/exec.rb new file mode 100644 index 00000000000..94ba7b49f84 --- /dev/null +++ b/lib/datadog/profiling/tasks/exec.rb @@ -0,0 +1,49 @@ +# typed: true +module Datadog + module Profiling + module Tasks + # Wraps command with Datadog tracing + class Exec + attr_reader :args + + def initialize(args) + @args = args + end + + def run + set_rubyopt! + exec_with_error_handling(args) + end + + def rubyopts + [ + '-rdatadog/profiling/preload' + ] + end + + private + + def set_rubyopt! + existing_rubyopt = ENV['RUBYOPT'] + + ENV['RUBYOPT'] = existing_rubyopt ? "#{existing_rubyopt} #{rubyopts.join(' ')}" : rubyopts.join(' ') + end + + # If there's an error here, rather than throwing a cryptic stack trace, let's instead have clearer messages, and + # follow the same status codes as the shell uses + # See also: + # * https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html + # * https://github.com/rubygems/rubygems/blob/dd93966cac224532035deda533cba2685dfa30cc/bundler/lib/bundler/cli/exec.rb#L45 + def exec_with_error_handling(args) + Kernel.exec(*args) + rescue Errno::ENOENT => e + Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')" + Kernel.exit 127 + rescue Errno::EACCES, Errno::ENOEXEC => e + Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')" + Kernel.exit 126 + end + end + end + end +end diff --git a/lib/datadog/profiling/tasks/help.rb b/lib/datadog/profiling/tasks/help.rb new file mode 100644 index 00000000000..d418f65efb2 --- /dev/null +++ b/lib/datadog/profiling/tasks/help.rb @@ -0,0 +1,17 @@ +# typed: true +module Datadog + module Profiling + module Tasks + # Prints help message for usage of `ddtrace` + class Help + def run + puts %( + Usage: ddtrace [command] [arguments] + exec [command]: Executes command with tracing & profiling preloaded. + help: Prints this help message. + ) + end + end + end + end +end diff --git a/lib/ddtrace/profiling/tasks/setup.rb b/lib/datadog/profiling/tasks/setup.rb similarity index 97% rename from lib/ddtrace/profiling/tasks/setup.rb rename to lib/datadog/profiling/tasks/setup.rb index 299b249734f..be8379028ce 100644 --- a/lib/ddtrace/profiling/tasks/setup.rb +++ b/lib/datadog/profiling/tasks/setup.rb @@ -1,7 +1,7 @@ # typed: false require 'datadog/core/utils/only_once' -require 'ddtrace/profiling' -require 'ddtrace/profiling/ext/forking' +require 'datadog/profiling' +require 'datadog/profiling/ext/forking' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/trace_identifiers/ddtrace.rb b/lib/datadog/profiling/trace_identifiers/ddtrace.rb similarity index 100% rename from lib/ddtrace/profiling/trace_identifiers/ddtrace.rb rename to lib/datadog/profiling/trace_identifiers/ddtrace.rb diff --git a/lib/ddtrace/profiling/trace_identifiers/helper.rb b/lib/datadog/profiling/trace_identifiers/helper.rb similarity index 96% rename from lib/ddtrace/profiling/trace_identifiers/helper.rb rename to lib/datadog/profiling/trace_identifiers/helper.rb index 660a5edfdae..d8b406240ae 100644 --- a/lib/ddtrace/profiling/trace_identifiers/helper.rb +++ b/lib/datadog/profiling/trace_identifiers/helper.rb @@ -1,7 +1,7 @@ # typed: true # frozen_string_literal: true -require 'ddtrace/profiling/trace_identifiers/ddtrace' +require 'datadog/profiling/trace_identifiers/ddtrace' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/client.rb b/lib/datadog/profiling/transport/client.rb similarity index 100% rename from lib/ddtrace/profiling/transport/client.rb rename to lib/datadog/profiling/transport/client.rb diff --git a/lib/ddtrace/profiling/transport/http.rb b/lib/datadog/profiling/transport/http.rb similarity index 95% rename from lib/ddtrace/profiling/transport/http.rb rename to lib/datadog/profiling/transport/http.rb index 8ab194fd4ad..469304561db 100644 --- a/lib/ddtrace/profiling/transport/http.rb +++ b/lib/datadog/profiling/transport/http.rb @@ -5,8 +5,8 @@ require 'datadog/core/environment/container' require 'datadog/core/environment/variable_helpers' -require 'ddtrace/profiling/transport/http/builder' -require 'ddtrace/profiling/transport/http/api' +require 'datadog/profiling/transport/http/builder' +require 'datadog/profiling/transport/http/api' require 'ddtrace/transport/http/adapters/net' require 'ddtrace/transport/http/adapters/test' @@ -79,7 +79,7 @@ def self.default_headers private_class_method def self.configure_for_agentless(transport, profiling_upload_timeout_seconds:, site:, api_key:) apis = API.api_defaults - site_uri = URI(format(Datadog::Ext::Profiling::Transport::HTTP::URI_TEMPLATE_DD_API, site)) + site_uri = URI(format(Datadog::Profiling::Ext::Transport::HTTP::URI_TEMPLATE_DD_API, site)) hostname = site_uri.host port = site_uri.port @@ -95,7 +95,7 @@ def self.default_headers end private_class_method def self.agentless_allowed? - Datadog::Core::Environment::VariableHelpers.env_to_bool(Datadog::Ext::Profiling::ENV_AGENTLESS, false) + Datadog::Core::Environment::VariableHelpers.env_to_bool(Datadog::Profiling::Ext::ENV_AGENTLESS, false) end # Add adapters to registry diff --git a/lib/ddtrace/profiling/transport/http/api.rb b/lib/datadog/profiling/transport/http/api.rb similarity index 82% rename from lib/ddtrace/profiling/transport/http/api.rb rename to lib/datadog/profiling/transport/http/api.rb index a32fbee1a32..8e3462e5414 100644 --- a/lib/ddtrace/profiling/transport/http/api.rb +++ b/lib/datadog/profiling/transport/http/api.rb @@ -1,9 +1,9 @@ # typed: true require 'ddtrace/transport/http/api/map' -require 'ddtrace/profiling/encoding/profile' -require 'ddtrace/profiling/transport/http/api/spec' -require 'ddtrace/profiling/transport/http/api/instance' -require 'ddtrace/profiling/transport/http/api/endpoint' +require 'datadog/profiling/encoding/profile' +require 'datadog/profiling/transport/http/api/spec' +require 'datadog/profiling/transport/http/api/instance' +require 'datadog/profiling/transport/http/api/endpoint' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/http/api/endpoint.rb b/lib/datadog/profiling/transport/http/api/endpoint.rb similarity index 96% rename from lib/ddtrace/profiling/transport/http/api/endpoint.rb rename to lib/datadog/profiling/transport/http/api/endpoint.rb index beed3d2cefd..4fea4000d39 100644 --- a/lib/ddtrace/profiling/transport/http/api/endpoint.rb +++ b/lib/datadog/profiling/transport/http/api/endpoint.rb @@ -1,10 +1,10 @@ # typed: true require 'datadog/core/utils/compression' -require 'ddtrace/ext/profiling' +require 'datadog/profiling/ext' require 'datadog/core/vendor/multipart-post/multipart/post/composite_read_io' require 'ddtrace/transport/http/api/endpoint' -require 'ddtrace/profiling/transport/http/response' +require 'datadog/profiling/transport/http/response' module Datadog module Profiling @@ -13,7 +13,7 @@ module HTTP module API # Datadog API endpoint for profiling class Endpoint < Datadog::Transport::HTTP::API::Endpoint - include Datadog::Ext::Profiling::Transport::HTTP + include Datadog::Profiling::Ext::Transport::HTTP # These tags are read from the flush object (see below) directly and so we ignore any extra copies that # may come in the tags hash to avoid duplicates. diff --git a/lib/ddtrace/profiling/transport/http/api/instance.rb b/lib/datadog/profiling/transport/http/api/instance.rb similarity index 94% rename from lib/ddtrace/profiling/transport/http/api/instance.rb rename to lib/datadog/profiling/transport/http/api/instance.rb index d1fb4890bb4..0385e01c1e5 100644 --- a/lib/ddtrace/profiling/transport/http/api/instance.rb +++ b/lib/datadog/profiling/transport/http/api/instance.rb @@ -1,6 +1,6 @@ # typed: true require 'ddtrace/transport/http/api/instance' -require 'ddtrace/profiling/transport/http/api/spec' +require 'datadog/profiling/transport/http/api/spec' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/http/api/spec.rb b/lib/datadog/profiling/transport/http/api/spec.rb similarity index 100% rename from lib/ddtrace/profiling/transport/http/api/spec.rb rename to lib/datadog/profiling/transport/http/api/spec.rb diff --git a/lib/ddtrace/profiling/transport/http/builder.rb b/lib/datadog/profiling/transport/http/builder.rb similarity index 88% rename from lib/ddtrace/profiling/transport/http/builder.rb rename to lib/datadog/profiling/transport/http/builder.rb index 5fef59e10a3..b90721fbd37 100644 --- a/lib/ddtrace/profiling/transport/http/builder.rb +++ b/lib/datadog/profiling/transport/http/builder.rb @@ -1,8 +1,8 @@ # typed: true require 'ddtrace/transport/http/builder' -require 'ddtrace/profiling/transport/http/api' -require 'ddtrace/profiling/transport/http/client' +require 'datadog/profiling/transport/http/api' +require 'datadog/profiling/transport/http/client' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/http/client.rb b/lib/datadog/profiling/transport/http/client.rb similarity index 95% rename from lib/ddtrace/profiling/transport/http/client.rb rename to lib/datadog/profiling/transport/http/client.rb index 2168d796b9e..7004d1d4205 100644 --- a/lib/ddtrace/profiling/transport/http/client.rb +++ b/lib/datadog/profiling/transport/http/client.rb @@ -1,6 +1,6 @@ # typed: true require 'ddtrace/transport/http/client' -require 'ddtrace/profiling/transport/client' +require 'datadog/profiling/transport/client' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/http/response.rb b/lib/datadog/profiling/transport/http/response.rb similarity index 91% rename from lib/ddtrace/profiling/transport/http/response.rb rename to lib/datadog/profiling/transport/http/response.rb index f7ef7bf7041..2bb52ac0917 100644 --- a/lib/ddtrace/profiling/transport/http/response.rb +++ b/lib/datadog/profiling/transport/http/response.rb @@ -1,6 +1,6 @@ # typed: true require 'ddtrace/transport/http/response' -require 'ddtrace/profiling/transport/response' +require 'datadog/profiling/transport/response' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/io.rb b/lib/datadog/profiling/transport/io.rb similarity index 88% rename from lib/ddtrace/profiling/transport/io.rb rename to lib/datadog/profiling/transport/io.rb index f8d2dab6952..6f311bbfb37 100644 --- a/lib/ddtrace/profiling/transport/io.rb +++ b/lib/datadog/profiling/transport/io.rb @@ -1,6 +1,6 @@ # typed: true -require 'ddtrace/profiling/transport/io/client' -require 'ddtrace/profiling/encoding/profile' +require 'datadog/profiling/transport/io/client' +require 'datadog/profiling/encoding/profile' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/io/client.rb b/lib/datadog/profiling/transport/io/client.rb similarity index 81% rename from lib/ddtrace/profiling/transport/io/client.rb rename to lib/datadog/profiling/transport/io/client.rb index c817a1d93e8..bfb1e0c67ea 100644 --- a/lib/ddtrace/profiling/transport/io/client.rb +++ b/lib/datadog/profiling/transport/io/client.rb @@ -1,8 +1,8 @@ # typed: true require 'ddtrace/transport/io/client' -require 'ddtrace/profiling/transport/client' -require 'ddtrace/profiling/transport/request' -require 'ddtrace/profiling/transport/io/response' +require 'datadog/profiling/transport/client' +require 'datadog/profiling/transport/request' +require 'datadog/profiling/transport/io/response' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/io/response.rb b/lib/datadog/profiling/transport/io/response.rb similarity index 88% rename from lib/ddtrace/profiling/transport/io/response.rb rename to lib/datadog/profiling/transport/io/response.rb index db5aed45932..3bd35b6302e 100644 --- a/lib/ddtrace/profiling/transport/io/response.rb +++ b/lib/datadog/profiling/transport/io/response.rb @@ -1,6 +1,6 @@ # typed: strict require 'ddtrace/transport/io/response' -require 'ddtrace/profiling/transport/response' +require 'datadog/profiling/transport/response' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/parcel.rb b/lib/datadog/profiling/transport/parcel.rb similarity index 100% rename from lib/ddtrace/profiling/transport/parcel.rb rename to lib/datadog/profiling/transport/parcel.rb diff --git a/lib/ddtrace/profiling/transport/request.rb b/lib/datadog/profiling/transport/request.rb similarity index 86% rename from lib/ddtrace/profiling/transport/request.rb rename to lib/datadog/profiling/transport/request.rb index 1ef231c0329..0f41f8ebfe1 100644 --- a/lib/ddtrace/profiling/transport/request.rb +++ b/lib/datadog/profiling/transport/request.rb @@ -1,6 +1,6 @@ # typed: true require 'ddtrace/transport/request' -require 'ddtrace/profiling/transport/parcel' +require 'datadog/profiling/transport/parcel' module Datadog module Profiling diff --git a/lib/ddtrace/profiling/transport/response.rb b/lib/datadog/profiling/transport/response.rb similarity index 100% rename from lib/ddtrace/profiling/transport/response.rb rename to lib/datadog/profiling/transport/response.rb diff --git a/lib/ddtrace.rb b/lib/ddtrace.rb index 3844752b7f0..8c5d30b590d 100644 --- a/lib/ddtrace.rb +++ b/lib/ddtrace.rb @@ -35,5 +35,5 @@ module Datadog end # Load other products (must follow tracing) -require 'ddtrace/profiling' +require 'datadog/profiling' require 'datadog/ci' diff --git a/lib/ddtrace/profiling/preload.rb b/lib/ddtrace/profiling/preload.rb index 61cd81a7e6f..45dff003a6e 100644 --- a/lib/ddtrace/profiling/preload.rb +++ b/lib/ddtrace/profiling/preload.rb @@ -1,4 +1,2 @@ -# typed: strict -require 'ddtrace' - -Datadog.profiler.start if Datadog.profiler +# TODO: Warns users after 1.0 upgrade. Remove this file in 2.0. +raise LoadError, 'This file has been moved to `datadog/profiling/preload` in 1.0.0' diff --git a/lib/ddtrace/tasks/exec.rb b/lib/ddtrace/tasks/exec.rb deleted file mode 100644 index 1caf9ebfa94..00000000000 --- a/lib/ddtrace/tasks/exec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# typed: true -module Datadog - module Tasks - # Wraps command with Datadog tracing - class Exec - attr_reader :args - - def initialize(args) - @args = args - end - - def run - set_rubyopt! - exec_with_error_handling(args) - end - - def rubyopts - [ - '-rddtrace/profiling/preload' - ] - end - - private - - def set_rubyopt! - existing_rubyopt = ENV['RUBYOPT'] - - ENV['RUBYOPT'] = existing_rubyopt ? "#{existing_rubyopt} #{rubyopts.join(' ')}" : rubyopts.join(' ') - end - - # If there's an error here, rather than throwing a cryptic stack trace, let's instead have clearer messages, and - # follow the same status codes as the shell uses - # See also: - # * https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html - # * https://github.com/rubygems/rubygems/blob/dd93966cac224532035deda533cba2685dfa30cc/bundler/lib/bundler/cli/exec.rb#L45 - def exec_with_error_handling(args) - Kernel.exec(*args) - rescue Errno::ENOENT => e - Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')" - Kernel.exit 127 - rescue Errno::EACCES, Errno::ENOEXEC => e - Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')" - Kernel.exit 126 - end - end - end -end diff --git a/lib/ddtrace/tasks/help.rb b/lib/ddtrace/tasks/help.rb deleted file mode 100644 index ba1e273070e..00000000000 --- a/lib/ddtrace/tasks/help.rb +++ /dev/null @@ -1,15 +0,0 @@ -# typed: true -module Datadog - module Tasks - # Prints help message for usage of `ddtrace` - class Help - def run - puts %( -Usage: ddtrace [command] [arguments] - exec [command]: Executes command with tracing & profiling preloaded. - help: Prints this help message. - ) - end - end - end -end diff --git a/spec/datadog/core/configuration/settings_spec.rb b/spec/datadog/core/configuration/settings_spec.rb index a45de907f98..9c4dba2cd0d 100644 --- a/spec/datadog/core/configuration/settings_spec.rb +++ b/spec/datadog/core/configuration/settings_spec.rb @@ -398,9 +398,9 @@ describe '#enabled' do subject(:enabled) { settings.profiling.enabled } - context "when #{Datadog::Ext::Profiling::ENV_ENABLED}" do + context "when #{Datadog::Profiling::Ext::ENV_ENABLED}" do around do |example| - ClimateControl.modify(Datadog::Ext::Profiling::ENV_ENABLED => environment) do + ClimateControl.modify(Datadog::Profiling::Ext::ENV_ENABLED => environment) do example.run end end @@ -466,9 +466,9 @@ describe '#max_frames' do subject(:max_frames) { settings.profiling.advanced.max_frames } - context "when #{Datadog::Ext::Profiling::ENV_MAX_FRAMES}" do + context "when #{Datadog::Profiling::Ext::ENV_MAX_FRAMES}" do around do |example| - ClimateControl.modify(Datadog::Ext::Profiling::ENV_MAX_FRAMES => environment) do + ClimateControl.modify(Datadog::Profiling::Ext::ENV_MAX_FRAMES => environment) do example.run end end @@ -501,9 +501,9 @@ describe '#enabled' do subject(:enabled) { settings.profiling.advanced.endpoint.collection.enabled } - context "when #{Datadog::Ext::Profiling::ENV_ENDPOINT_COLLECTION_ENABLED}" do + context "when #{Datadog::Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED}" do around do |example| - ClimateControl.modify(Datadog::Ext::Profiling::ENV_ENDPOINT_COLLECTION_ENABLED => environment) do + ClimateControl.modify(Datadog::Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED => environment) do example.run end end @@ -555,9 +555,9 @@ describe '#timeout_seconds' do subject(:timeout_seconds) { settings.profiling.upload.timeout_seconds } - context "when #{Datadog::Ext::Profiling::ENV_UPLOAD_TIMEOUT}" do + context "when #{Datadog::Profiling::Ext::ENV_UPLOAD_TIMEOUT}" do around do |example| - ClimateControl.modify(Datadog::Ext::Profiling::ENV_UPLOAD_TIMEOUT => environment) do + ClimateControl.modify(Datadog::Profiling::Ext::ENV_UPLOAD_TIMEOUT => environment) do example.run end end diff --git a/spec/ddtrace/profiling/backtrace_location_spec.rb b/spec/datadog/profiling/backtrace_location_spec.rb similarity index 97% rename from spec/ddtrace/profiling/backtrace_location_spec.rb rename to spec/datadog/profiling/backtrace_location_spec.rb index eb083afb27a..d2300fc73c2 100644 --- a/spec/ddtrace/profiling/backtrace_location_spec.rb +++ b/spec/datadog/profiling/backtrace_location_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/backtrace_location' +require 'datadog/profiling/backtrace_location' RSpec.describe Datadog::Profiling::BacktraceLocation do subject(:backtrace_location) { new_backtrace_location(base_label, lineno, path) } diff --git a/spec/ddtrace/profiling/buffer_spec.rb b/spec/datadog/profiling/buffer_spec.rb similarity index 96% rename from spec/ddtrace/profiling/buffer_spec.rb rename to spec/datadog/profiling/buffer_spec.rb index be85ed91912..13972ecc733 100644 --- a/spec/ddtrace/profiling/buffer_spec.rb +++ b/spec/datadog/profiling/buffer_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/buffer' +require 'datadog/profiling/buffer' RSpec.describe Datadog::Profiling::Buffer do subject(:buffer) { described_class.new(max_size) } diff --git a/spec/ddtrace/profiling/collectors/code_provenance_spec.rb b/spec/datadog/profiling/collectors/code_provenance_spec.rb similarity index 99% rename from spec/ddtrace/profiling/collectors/code_provenance_spec.rb rename to spec/datadog/profiling/collectors/code_provenance_spec.rb index 73a164c73a6..fb17f51dafd 100644 --- a/spec/ddtrace/profiling/collectors/code_provenance_spec.rb +++ b/spec/datadog/profiling/collectors/code_provenance_spec.rb @@ -1,6 +1,6 @@ # typed: ignore -require 'ddtrace/profiling/collectors/code_provenance' +require 'datadog/profiling/collectors/code_provenance' require 'json-schema' RSpec.describe Datadog::Profiling::Collectors::CodeProvenance do diff --git a/spec/ddtrace/profiling/collectors/stack_spec.rb b/spec/datadog/profiling/collectors/stack_spec.rb similarity index 99% rename from spec/ddtrace/profiling/collectors/stack_spec.rb rename to spec/datadog/profiling/collectors/stack_spec.rb index 4ac04a9d0b1..1953bb52b7a 100644 --- a/spec/ddtrace/profiling/collectors/stack_spec.rb +++ b/spec/datadog/profiling/collectors/stack_spec.rb @@ -1,10 +1,10 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' -require 'ddtrace/profiling/collectors/stack' -require 'ddtrace/profiling/trace_identifiers/helper' -require 'ddtrace/profiling/recorder' +require 'datadog/profiling/collectors/stack' +require 'datadog/profiling/trace_identifiers/helper' +require 'datadog/profiling/recorder' require 'set' require 'timeout' diff --git a/spec/ddtrace/profiling/encoding/profile_spec.rb b/spec/datadog/profiling/encoding/profile_spec.rb similarity index 95% rename from spec/ddtrace/profiling/encoding/profile_spec.rb rename to spec/datadog/profiling/encoding/profile_spec.rb index b5f2308be42..8787d78c7d5 100644 --- a/spec/ddtrace/profiling/encoding/profile_spec.rb +++ b/spec/datadog/profiling/encoding/profile_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/encoding/profile' -require 'ddtrace/profiling/events/stack' +require 'datadog/profiling/encoding/profile' +require 'datadog/profiling/events/stack' RSpec.describe Datadog::Profiling::Encoding::Profile::Protobuf do describe '::encode' do diff --git a/spec/ddtrace/profiling/event_spec.rb b/spec/datadog/profiling/event_spec.rb similarity index 88% rename from spec/ddtrace/profiling/event_spec.rb rename to spec/datadog/profiling/event_spec.rb index 5716a074ef0..c3e4d996c46 100644 --- a/spec/ddtrace/profiling/event_spec.rb +++ b/spec/datadog/profiling/event_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/event' +require 'datadog/profiling/event' RSpec.describe Datadog::Profiling::Event do subject(:event) { described_class.new } diff --git a/spec/ddtrace/profiling/events/stack_spec.rb b/spec/datadog/profiling/events/stack_spec.rb similarity index 98% rename from spec/ddtrace/profiling/events/stack_spec.rb rename to spec/datadog/profiling/events/stack_spec.rb index 32a5f11ae2f..fc6da87e959 100644 --- a/spec/ddtrace/profiling/events/stack_spec.rb +++ b/spec/datadog/profiling/events/stack_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/events/stack' +require 'datadog/profiling/events/stack' RSpec.describe Datadog::Profiling::Events do describe Datadog::Profiling::Events::Stack do diff --git a/spec/ddtrace/profiling/exporter_spec.rb b/spec/datadog/profiling/exporter_spec.rb similarity index 91% rename from spec/ddtrace/profiling/exporter_spec.rb rename to spec/datadog/profiling/exporter_spec.rb index 11a6bfed87e..9d330f40853 100644 --- a/spec/ddtrace/profiling/exporter_spec.rb +++ b/spec/datadog/profiling/exporter_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/exporter' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/transport/io' +require 'datadog/profiling/exporter' +require 'datadog/profiling/flush' +require 'datadog/profiling/transport/io' RSpec.describe Datadog::Profiling::Exporter do subject(:exporter) { described_class.new(transport) } diff --git a/spec/ddtrace/profiling/ext/forking_spec.rb b/spec/datadog/profiling/ext/forking_spec.rb similarity index 97% rename from spec/ddtrace/profiling/ext/forking_spec.rb rename to spec/datadog/profiling/ext/forking_spec.rb index 58f82f630f5..606272e4965 100644 --- a/spec/ddtrace/profiling/ext/forking_spec.rb +++ b/spec/datadog/profiling/ext/forking_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/ext/forking' +require 'datadog/profiling' +require 'datadog/profiling/ext/forking' RSpec.describe Datadog::Profiling::Ext::Forking do describe '::apply!' do @@ -65,9 +65,9 @@ expect(::Kernel.ancestors).to include(described_class::Kernel) expect(toplevel_receiver.class.ancestors).to include(described_class::Kernel) - expect(::Process.method(:fork).source_location.first).to match(%r{.*ddtrace/profiling/ext/forking.rb}) - expect(::Kernel.method(:fork).source_location.first).to match(%r{.*ddtrace/profiling/ext/forking.rb}) - expect(toplevel_receiver.method(:fork).source_location.first).to match(%r{.*ddtrace/profiling/ext/forking.rb}) + expect(::Process.method(:fork).source_location.first).to match(%r{.*datadog/profiling/ext/forking.rb}) + expect(::Kernel.method(:fork).source_location.first).to match(%r{.*datadog/profiling/ext/forking.rb}) + expect(toplevel_receiver.method(:fork).source_location.first).to match(%r{.*datadog/profiling/ext/forking.rb}) end end diff --git a/spec/ddtrace/profiling/flush_spec.rb b/spec/datadog/profiling/flush_spec.rb similarity index 100% rename from spec/ddtrace/profiling/flush_spec.rb rename to spec/datadog/profiling/flush_spec.rb diff --git a/spec/ddtrace/profiling/integration_spec.rb b/spec/datadog/profiling/integration_spec.rb similarity index 92% rename from spec/ddtrace/profiling/integration_spec.rb rename to spec/datadog/profiling/integration_spec.rb index 16d649c663c..cd93a3a3966 100644 --- a/spec/ddtrace/profiling/integration_spec.rb +++ b/spec/datadog/profiling/integration_spec.rb @@ -1,16 +1,16 @@ # typed: ignore require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' require 'ddtrace' require 'datadog/core/utils/time' -require 'ddtrace/profiling' -require 'ddtrace/profiling/pprof/template' -require 'ddtrace/profiling/collectors/stack' -require 'ddtrace/profiling/recorder' -require 'ddtrace/profiling/scheduler' -require 'ddtrace/profiling/exporter' -require 'ddtrace/profiling/encoding/profile' +require 'datadog/profiling' +require 'datadog/profiling/pprof/template' +require 'datadog/profiling/collectors/stack' +require 'datadog/profiling/recorder' +require 'datadog/profiling/scheduler' +require 'datadog/profiling/exporter' +require 'datadog/profiling/encoding/profile' RSpec.describe 'profiling integration test' do before do @@ -239,13 +239,13 @@ def stack_frame_to_function_id(backtrace_location) is_expected.to have(2).items expect(sample_type[0]).to have_attributes( - type: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_TYPE_CPU), - unit: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS) + type: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_TYPE_CPU), + unit: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS) ) expect(sample_type[1]).to have_attributes( - type: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_TYPE_WALL), - unit: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS) + type: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_TYPE_WALL), + unit: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS) ) end end @@ -265,7 +265,7 @@ def stack_frame_to_function_id(backtrace_location) location_id: stack_sample.frames.collect { |f| stack_frame_to_location_id(f) }, value: [stack_sample.cpu_time_interval_ns, stack_sample.wall_time_interval_ns], label: [{ - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_THREAD_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID), str: string_id_for(stack_sample.thread_id.to_s), num: 0, num_unit: 0 @@ -282,7 +282,7 @@ def stack_frame_to_function_id(backtrace_location) ], label: [ { - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_THREAD_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID), str: string_id_for(stack_samples.last.thread_id.to_s), num: 0, num_unit: 0 @@ -305,25 +305,25 @@ def stack_frame_to_function_id(backtrace_location) ], label: [ { - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_THREAD_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID), str: string_id_for(stack_samples.last.thread_id.to_s), num: 0, num_unit: 0 }, { - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), str: string_id_for(root_span_id.to_s), num: 0, num_unit: 0 }, { - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_SPAN_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_SPAN_ID), str: string_id_for(span_id.to_s), num: 0, num_unit: 0 }, { - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_TRACE_ENDPOINT), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_TRACE_ENDPOINT), str: string_id_for('example trace resource'), num: 0, num_unit: 0 diff --git a/spec/ddtrace/profiling/native_extension_spec.rb b/spec/datadog/profiling/native_extension_spec.rb similarity index 99% rename from spec/ddtrace/profiling/native_extension_spec.rb rename to spec/datadog/profiling/native_extension_spec.rb index 21a1fd3d376..adc6dc940cb 100644 --- a/spec/ddtrace/profiling/native_extension_spec.rb +++ b/spec/datadog/profiling/native_extension_spec.rb @@ -1,5 +1,5 @@ # typed: false -require 'ddtrace/profiling/native_extension' +require 'datadog/profiling/native_extension' RSpec.describe Datadog::Profiling::NativeExtension do before do diff --git a/spec/ddtrace/profiling/pprof/builder_spec.rb b/spec/datadog/profiling/pprof/builder_spec.rb similarity index 98% rename from spec/ddtrace/profiling/pprof/builder_spec.rb rename to spec/datadog/profiling/pprof/builder_spec.rb index a57fb044e06..9cdfb079e07 100644 --- a/spec/ddtrace/profiling/pprof/builder_spec.rb +++ b/spec/datadog/profiling/pprof/builder_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/events/stack' -require 'ddtrace/profiling/pprof/builder' +require 'datadog/profiling' +require 'datadog/profiling/events/stack' +require 'datadog/profiling/pprof/builder' RSpec.describe Datadog::Profiling::Pprof::Builder do before do diff --git a/spec/ddtrace/profiling/pprof/converter_spec.rb b/spec/datadog/profiling/pprof/converter_spec.rb similarity index 96% rename from spec/ddtrace/profiling/pprof/converter_spec.rb rename to spec/datadog/profiling/pprof/converter_spec.rb index 82b6cd3d64f..3e91655c0e8 100644 --- a/spec/ddtrace/profiling/pprof/converter_spec.rb +++ b/spec/datadog/profiling/pprof/converter_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/pprof/builder' -require 'ddtrace/profiling/pprof/converter' +require 'datadog/profiling/pprof/builder' +require 'datadog/profiling/pprof/converter' RSpec.describe Datadog::Profiling::Pprof::Converter do subject(:converter) { described_class.new(builder, sample_type_mappings) } @@ -13,7 +13,7 @@ let(:default_sample_values) do Array.new( sample_type_mappings.length, - Datadog::Ext::Profiling::Pprof::SAMPLE_VALUE_NO_VALUE + Datadog::Profiling::Ext::Pprof::SAMPLE_VALUE_NO_VALUE ) end diff --git a/spec/ddtrace/profiling/pprof/message_set_spec.rb b/spec/datadog/profiling/pprof/message_set_spec.rb similarity index 94% rename from spec/ddtrace/profiling/pprof/message_set_spec.rb rename to spec/datadog/profiling/pprof/message_set_spec.rb index db8fe3d6c0e..69238289055 100644 --- a/spec/ddtrace/profiling/pprof/message_set_spec.rb +++ b/spec/datadog/profiling/pprof/message_set_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/pprof/message_set' +require 'datadog/profiling/pprof/message_set' RSpec.describe Datadog::Profiling::Pprof::MessageSet do subject(:message_set) { described_class.new } diff --git a/spec/ddtrace/profiling/pprof/payload_spec.rb b/spec/datadog/profiling/pprof/payload_spec.rb similarity index 91% rename from spec/ddtrace/profiling/pprof/payload_spec.rb rename to spec/datadog/profiling/pprof/payload_spec.rb index 750d9392d51..10a43963011 100644 --- a/spec/ddtrace/profiling/pprof/payload_spec.rb +++ b/spec/datadog/profiling/pprof/payload_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/pprof/payload' +require 'datadog/profiling/pprof/payload' RSpec.describe Datadog::Profiling::Pprof::Payload do subject(:payload) { described_class.new(data, types) } diff --git a/spec/ddtrace/profiling/pprof/stack_sample_spec.rb b/spec/datadog/profiling/pprof/stack_sample_spec.rb similarity index 95% rename from spec/ddtrace/profiling/pprof/stack_sample_spec.rb rename to spec/datadog/profiling/pprof/stack_sample_spec.rb index a3307ccd4b0..9fd11ddd455 100644 --- a/spec/ddtrace/profiling/pprof/stack_sample_spec.rb +++ b/spec/datadog/profiling/pprof/stack_sample_spec.rb @@ -1,10 +1,10 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/events/stack' -require 'ddtrace/profiling/pprof/stack_sample' +require 'datadog/profiling' +require 'datadog/profiling/events/stack' +require 'datadog/profiling/pprof/stack_sample' RSpec.describe Datadog::Profiling::Pprof::StackSample do before do @@ -43,8 +43,8 @@ def string_id_for(string) it do is_expected.to eq( [ - Datadog::Ext::Profiling::Pprof::VALUE_TYPE_CPU, - Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS + Datadog::Profiling::Ext::Pprof::VALUE_TYPE_CPU, + Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS ] ) end @@ -56,8 +56,8 @@ def string_id_for(string) it do is_expected.to eq( [ - Datadog::Ext::Profiling::Pprof::VALUE_TYPE_WALL, - Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS + Datadog::Profiling::Ext::Pprof::VALUE_TYPE_WALL, + Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS ] ) end @@ -364,7 +364,7 @@ def string_id_for(string) is_expected.to include(kind_of(Perftools::Profiles::Sample)) # Find key for trace resource label - trace_resource_label_key_id = builder.string_table.fetch(Datadog::Ext::Profiling::Pprof::LABEL_KEY_TRACE_ENDPOINT) + trace_resource_label_key_id = builder.string_table.fetch(Datadog::Profiling::Ext::Pprof::LABEL_KEY_TRACE_ENDPOINT) build_samples.each do |sample| # Find the trace resource label for this sample @@ -442,7 +442,7 @@ def string_id_for(string) it do is_expected.to have_attributes( - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_THREAD_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_THREAD_ID), str: string_id_for(stack_sample.thread_id.to_s) ) end @@ -455,7 +455,7 @@ def string_id_for(string) it do is_expected.to have_attributes( - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_LOCAL_ROOT_SPAN_ID), str: string_id_for(stack_sample.root_span_id.to_s) ) end @@ -468,7 +468,7 @@ def string_id_for(string) it do is_expected.to have_attributes( - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_SPAN_ID), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_SPAN_ID), str: string_id_for(stack_sample.span_id.to_s) ) end @@ -481,7 +481,7 @@ def string_id_for(string) it do is_expected.to have_attributes( - key: string_id_for(Datadog::Ext::Profiling::Pprof::LABEL_KEY_TRACE_ENDPOINT), + key: string_id_for(Datadog::Profiling::Ext::Pprof::LABEL_KEY_TRACE_ENDPOINT), str: string_id_for(trace_endpoint) ) end diff --git a/spec/ddtrace/profiling/pprof/string_table_spec.rb b/spec/datadog/profiling/pprof/string_table_spec.rb similarity index 82% rename from spec/ddtrace/profiling/pprof/string_table_spec.rb rename to spec/datadog/profiling/pprof/string_table_spec.rb index a292168767c..14d80ca59d5 100644 --- a/spec/ddtrace/profiling/pprof/string_table_spec.rb +++ b/spec/datadog/profiling/pprof/string_table_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/pprof/string_table' +require 'datadog/profiling/pprof/string_table' RSpec.describe Datadog::Profiling::Pprof::StringTable do subject(:string_table) { described_class.new } diff --git a/spec/ddtrace/profiling/pprof/template_spec.rb b/spec/datadog/profiling/pprof/template_spec.rb similarity index 93% rename from spec/ddtrace/profiling/pprof/template_spec.rb rename to spec/datadog/profiling/pprof/template_spec.rb index 94cee11dbb6..bd247720f1b 100644 --- a/spec/ddtrace/profiling/pprof/template_spec.rb +++ b/spec/datadog/profiling/pprof/template_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/pprof/template' +require 'datadog/profiling' +require 'datadog/profiling/pprof/template' RSpec.describe Datadog::Profiling::Pprof::Template do before do @@ -86,12 +86,12 @@ def string_id_for(string) is_expected.to eq( [ { - type: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_TYPE_CPU), - unit: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS) + type: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_TYPE_CPU), + unit: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS) }, { - type: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_TYPE_WALL), - unit: string_id_for(Datadog::Ext::Profiling::Pprof::VALUE_UNIT_NANOSECONDS) + type: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_TYPE_WALL), + unit: string_id_for(Datadog::Profiling::Ext::Pprof::VALUE_UNIT_NANOSECONDS) } ] ) diff --git a/spec/ddtrace/profiling/preload_spec.rb b/spec/datadog/profiling/preload_spec.rb similarity index 84% rename from spec/ddtrace/profiling/preload_spec.rb rename to spec/datadog/profiling/preload_spec.rb index 406ad2d54d2..689f967a967 100644 --- a/spec/ddtrace/profiling/preload_spec.rb +++ b/spec/datadog/profiling/preload_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling' +require 'datadog/profiling' RSpec.describe 'Profiling preloading' do - subject(:preload) { load 'ddtrace/profiling/preload.rb' } + subject(:preload) { load 'datadog/profiling/preload.rb' } it 'starts the profiler' do profiler = instance_double(Datadog::Profiler) diff --git a/spec/ddtrace/profiling/profiler_spec.rb b/spec/datadog/profiling/profiler_spec.rb similarity index 94% rename from spec/ddtrace/profiling/profiler_spec.rb rename to spec/datadog/profiling/profiler_spec.rb index 0369498114b..94eaaeddf25 100644 --- a/spec/ddtrace/profiling/profiler_spec.rb +++ b/spec/datadog/profiling/profiler_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/profiler' +require 'datadog/profiling' +require 'datadog/profiling/profiler' RSpec.describe Datadog::Profiler do subject(:profiler) { described_class.new(collectors, scheduler) } diff --git a/spec/ddtrace/profiling/recorder_spec.rb b/spec/datadog/profiling/recorder_spec.rb similarity index 97% rename from spec/ddtrace/profiling/recorder_spec.rb rename to spec/datadog/profiling/recorder_spec.rb index 25d3cbd9478..c4ecb3024fc 100644 --- a/spec/ddtrace/profiling/recorder_spec.rb +++ b/spec/datadog/profiling/recorder_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/recorder' -require 'ddtrace/profiling/event' -require 'ddtrace/profiling/collectors/code_provenance' +require 'datadog/profiling/recorder' +require 'datadog/profiling/event' +require 'datadog/profiling/collectors/code_provenance' RSpec.describe Datadog::Profiling::Recorder do subject(:recorder) do diff --git a/spec/ddtrace/profiling/scheduler_spec.rb b/spec/datadog/profiling/scheduler_spec.rb similarity index 98% rename from spec/ddtrace/profiling/scheduler_spec.rb rename to spec/datadog/profiling/scheduler_spec.rb index 6e5e4506e35..43ddb717975 100644 --- a/spec/ddtrace/profiling/scheduler_spec.rb +++ b/spec/datadog/profiling/scheduler_spec.rb @@ -1,9 +1,9 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/exporter' -require 'ddtrace/profiling/recorder' -require 'ddtrace/profiling/scheduler' +require 'datadog/profiling/exporter' +require 'datadog/profiling/recorder' +require 'datadog/profiling/scheduler' RSpec.describe Datadog::Profiling::Scheduler do subject(:scheduler) { described_class.new(recorder, exporters, **options) } diff --git a/spec/ddtrace/profiling/spec_helper.rb b/spec/datadog/profiling/spec_helper.rb similarity index 98% rename from spec/ddtrace/profiling/spec_helper.rb rename to spec/datadog/profiling/spec_helper.rb index 21d0254b63d..e70e7d77f9f 100644 --- a/spec/ddtrace/profiling/spec_helper.rb +++ b/spec/datadog/profiling/spec_helper.rb @@ -1,5 +1,5 @@ # typed: false -require 'ddtrace/profiling' +require 'datadog/profiling' module ProfileHelpers include Kernel diff --git a/spec/ddtrace/tasks/exec_spec.rb b/spec/datadog/profiling/tasks/exec_spec.rb similarity index 95% rename from spec/ddtrace/tasks/exec_spec.rb rename to spec/datadog/profiling/tasks/exec_spec.rb index 9ce3f7c9446..575c72cb779 100644 --- a/spec/ddtrace/tasks/exec_spec.rb +++ b/spec/datadog/profiling/tasks/exec_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/tasks/exec' +require 'datadog/profiling/tasks/exec' -RSpec.describe Datadog::Tasks::Exec do +RSpec.describe Datadog::Profiling::Tasks::Exec do subject(:task) { described_class.new(args) } let(:args) { ['ruby', '-e', '"RUBY_VERSION"'] } @@ -121,6 +121,6 @@ describe '#rubyopts' do subject(:rubyopts) { task.rubyopts } - it { is_expected.to eq(['-rddtrace/profiling/preload']) } + it { is_expected.to eq(['-rdatadog/profiling/preload']) } end end diff --git a/spec/ddtrace/tasks/help_spec.rb b/spec/datadog/profiling/tasks/help_spec.rb similarity index 76% rename from spec/ddtrace/tasks/help_spec.rb rename to spec/datadog/profiling/tasks/help_spec.rb index 4e39f1d364a..50902abdb87 100644 --- a/spec/ddtrace/tasks/help_spec.rb +++ b/spec/datadog/profiling/tasks/help_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/tasks/help' +require 'datadog/profiling/tasks/help' -RSpec.describe Datadog::Tasks::Help do +RSpec.describe Datadog::Profiling::Tasks::Help do subject(:task) { described_class.new } describe '#run' do diff --git a/spec/ddtrace/profiling/tasks/setup_spec.rb b/spec/datadog/profiling/tasks/setup_spec.rb similarity index 98% rename from spec/ddtrace/profiling/tasks/setup_spec.rb rename to spec/datadog/profiling/tasks/setup_spec.rb index c796e38f6b3..b5b757f4623 100644 --- a/spec/ddtrace/profiling/tasks/setup_spec.rb +++ b/spec/datadog/profiling/tasks/setup_spec.rb @@ -1,10 +1,10 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' -require 'ddtrace/profiling' -require 'ddtrace/profiling/tasks/setup' -require 'ddtrace/profiling/ext/forking' +require 'datadog/profiling' +require 'datadog/profiling/tasks/setup' +require 'datadog/profiling/ext/forking' RSpec.describe Datadog::Profiling::Tasks::Setup do subject(:task) { described_class.new } diff --git a/spec/ddtrace/profiling/trace_identifiers/ddtrace_spec.rb b/spec/datadog/profiling/trace_identifiers/ddtrace_spec.rb similarity index 98% rename from spec/ddtrace/profiling/trace_identifiers/ddtrace_spec.rb rename to spec/datadog/profiling/trace_identifiers/ddtrace_spec.rb index 394471b5baa..449aff6483e 100644 --- a/spec/ddtrace/profiling/trace_identifiers/ddtrace_spec.rb +++ b/spec/datadog/profiling/trace_identifiers/ddtrace_spec.rb @@ -1,5 +1,5 @@ # typed: false -require 'ddtrace/profiling/trace_identifiers/ddtrace' +require 'datadog/profiling/trace_identifiers/ddtrace' require 'ddtrace/tracer' require 'ddtrace/context' diff --git a/spec/ddtrace/profiling/trace_identifiers/helper_spec.rb b/spec/datadog/profiling/trace_identifiers/helper_spec.rb similarity index 96% rename from spec/ddtrace/profiling/trace_identifiers/helper_spec.rb rename to spec/datadog/profiling/trace_identifiers/helper_spec.rb index 18f977b48d4..e51ac5883a2 100644 --- a/spec/ddtrace/profiling/trace_identifiers/helper_spec.rb +++ b/spec/datadog/profiling/trace_identifiers/helper_spec.rb @@ -1,6 +1,6 @@ # typed: false -require 'ddtrace/profiling/trace_identifiers/helper' -require 'ddtrace/profiling/trace_identifiers/ddtrace' +require 'datadog/profiling/trace_identifiers/helper' +require 'datadog/profiling/trace_identifiers/ddtrace' RSpec.describe Datadog::Profiling::TraceIdentifiers::Helper do let(:thread) { instance_double(Thread) } diff --git a/spec/ddtrace/profiling/transport/client_spec.rb b/spec/datadog/profiling/transport/client_spec.rb similarity index 87% rename from spec/ddtrace/profiling/transport/client_spec.rb rename to spec/datadog/profiling/transport/client_spec.rb index 99e4d3d95ce..d0584ee398d 100644 --- a/spec/ddtrace/profiling/transport/client_spec.rb +++ b/spec/datadog/profiling/transport/client_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/transport/client' +require 'datadog/profiling/flush' +require 'datadog/profiling/transport/client' RSpec.describe Datadog::Profiling::Transport::Client do context 'when implemented in a Class' do diff --git a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb b/spec/datadog/profiling/transport/http/adapters/net_integration_spec.rb similarity index 97% rename from spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb rename to spec/datadog/profiling/transport/http/adapters/net_integration_spec.rb index 19ade526391..0eb52160097 100644 --- a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb +++ b/spec/datadog/profiling/transport/http/adapters/net_integration_spec.rb @@ -1,14 +1,14 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' require 'stringio' require 'securerandom' require 'webrick' require 'ddtrace/transport/http' -require 'ddtrace/profiling' -require 'ddtrace/profiling/transport/http' +require 'datadog/profiling' +require 'datadog/profiling/transport/http' require 'ddtrace/transport/http/adapters/net' RSpec.describe 'Adapters::Net profiling integration tests' do @@ -177,7 +177,7 @@ context 'via agentless' do before do - stub_const('Datadog::Ext::Profiling::Transport::HTTP::URI_TEMPLATE_DD_API', "http://%s:#{port}/") + stub_const('Datadog::Profiling::Ext::Transport::HTTP::URI_TEMPLATE_DD_API', "http://%s:#{port}/") end let(:api_key) { SecureRandom.uuid } diff --git a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb b/spec/datadog/profiling/transport/http/api/endpoint_spec.rb similarity index 95% rename from spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb rename to spec/datadog/profiling/transport/http/api/endpoint_spec.rb index 50fc95fd3df..782c3690672 100644 --- a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb +++ b/spec/datadog/profiling/transport/http/api/endpoint_spec.rb @@ -1,12 +1,12 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' -require 'ddtrace/profiling/encoding/profile' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/transport/http/api/endpoint' -require 'ddtrace/profiling/transport/http/response' -require 'ddtrace/profiling/transport/request' +require 'datadog/profiling/encoding/profile' +require 'datadog/profiling/flush' +require 'datadog/profiling/transport/http/api/endpoint' +require 'datadog/profiling/transport/http/response' +require 'datadog/profiling/transport/request' require 'ddtrace/transport/http/env' RSpec.describe Datadog::Profiling::Transport::HTTP::API::Endpoint do diff --git a/spec/ddtrace/profiling/transport/http/api/instance_spec.rb b/spec/datadog/profiling/transport/http/api/instance_spec.rb similarity index 86% rename from spec/ddtrace/profiling/transport/http/api/instance_spec.rb rename to spec/datadog/profiling/transport/http/api/instance_spec.rb index 91df344ba88..d36d09a5aac 100644 --- a/spec/ddtrace/profiling/transport/http/api/instance_spec.rb +++ b/spec/datadog/profiling/transport/http/api/instance_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' require 'ddtrace/transport/http/env' -require 'ddtrace/profiling/transport/http/api/instance' -require 'ddtrace/profiling/transport/http/api/spec' -require 'ddtrace/profiling/transport/http/response' +require 'datadog/profiling/transport/http/api/instance' +require 'datadog/profiling/transport/http/api/spec' +require 'datadog/profiling/transport/http/response' RSpec.describe Datadog::Profiling::Transport::HTTP::API::Instance do subject(:instance) { described_class.new(spec, adapter) } diff --git a/spec/ddtrace/profiling/transport/http/api/spec_spec.rb b/spec/datadog/profiling/transport/http/api/spec_spec.rb similarity index 90% rename from spec/ddtrace/profiling/transport/http/api/spec_spec.rb rename to spec/datadog/profiling/transport/http/api/spec_spec.rb index 7f660498233..193fba623e9 100644 --- a/spec/ddtrace/profiling/transport/http/api/spec_spec.rb +++ b/spec/datadog/profiling/transport/http/api/spec_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' require 'ddtrace/transport/http/env' -require 'ddtrace/profiling/transport/http/api/endpoint' -require 'ddtrace/profiling/transport/http/api/spec' -require 'ddtrace/profiling/transport/http/response' +require 'datadog/profiling/transport/http/api/endpoint' +require 'datadog/profiling/transport/http/api/spec' +require 'datadog/profiling/transport/http/response' RSpec.describe Datadog::Profiling::Transport::HTTP::API::Spec do subject(:spec) { described_class.new } diff --git a/spec/ddtrace/profiling/transport/http/api_spec.rb b/spec/datadog/profiling/transport/http/api_spec.rb similarity index 97% rename from spec/ddtrace/profiling/transport/http/api_spec.rb rename to spec/datadog/profiling/transport/http/api_spec.rb index 5b122fa4733..ce2cce71b5d 100644 --- a/spec/ddtrace/profiling/transport/http/api_spec.rb +++ b/spec/datadog/profiling/transport/http/api_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/http/api' +require 'datadog/profiling/transport/http/api' RSpec.describe Datadog::Profiling::Transport::HTTP::API do describe '::agent_defaults' do diff --git a/spec/ddtrace/profiling/transport/http/builder_spec.rb b/spec/datadog/profiling/transport/http/builder_spec.rb similarity index 97% rename from spec/ddtrace/profiling/transport/http/builder_spec.rb rename to spec/datadog/profiling/transport/http/builder_spec.rb index e75f1e0e53f..2c2bd384db0 100644 --- a/spec/ddtrace/profiling/transport/http/builder_spec.rb +++ b/spec/datadog/profiling/transport/http/builder_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/http/builder' +require 'datadog/profiling/transport/http/builder' RSpec.describe Datadog::Profiling::Transport::HTTP::Builder do subject(:builder) { described_class.new } diff --git a/spec/ddtrace/profiling/transport/http/client_spec.rb b/spec/datadog/profiling/transport/http/client_spec.rb similarity index 100% rename from spec/ddtrace/profiling/transport/http/client_spec.rb rename to spec/datadog/profiling/transport/http/client_spec.rb diff --git a/spec/ddtrace/profiling/transport/http/integration_spec.rb b/spec/datadog/profiling/transport/http/integration_spec.rb similarity index 95% rename from spec/ddtrace/profiling/transport/http/integration_spec.rb rename to spec/datadog/profiling/transport/http/integration_spec.rb index 122ebd89bd5..5691e78ddfa 100644 --- a/spec/ddtrace/profiling/transport/http/integration_spec.rb +++ b/spec/datadog/profiling/transport/http/integration_spec.rb @@ -1,9 +1,9 @@ # typed: ignore require 'spec_helper' -require 'ddtrace/profiling/spec_helper' +require 'datadog/profiling/spec_helper' require 'ddtrace' -require 'ddtrace/profiling/transport/http' +require 'datadog/profiling/transport/http' RSpec.describe 'Datadog::Profiling::Transport::HTTP integration tests' do before do diff --git a/spec/ddtrace/profiling/transport/http/response_spec.rb b/spec/datadog/profiling/transport/http/response_spec.rb similarity index 95% rename from spec/ddtrace/profiling/transport/http/response_spec.rb rename to spec/datadog/profiling/transport/http/response_spec.rb index 89c718266c0..3716fb49bf9 100644 --- a/spec/ddtrace/profiling/transport/http/response_spec.rb +++ b/spec/datadog/profiling/transport/http/response_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/http/response' +require 'datadog/profiling/transport/http/response' RSpec.describe Datadog::Profiling::Transport::HTTP::Response do subject(:response) { described_class.new(http_response) } diff --git a/spec/ddtrace/profiling/transport/http_spec.rb b/spec/datadog/profiling/transport/http_spec.rb similarity index 96% rename from spec/ddtrace/profiling/transport/http_spec.rb rename to spec/datadog/profiling/transport/http_spec.rb index dd6160af46f..5fbf9ef3fcb 100644 --- a/spec/ddtrace/profiling/transport/http_spec.rb +++ b/spec/datadog/profiling/transport/http_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' require 'securerandom' -require 'ddtrace/profiling/transport/http' -require 'ddtrace/profiling/transport/http/client' +require 'datadog/profiling/transport/http' +require 'datadog/profiling/transport/http/client' RSpec.describe Datadog::Profiling::Transport::HTTP do describe '::new' do @@ -92,7 +92,7 @@ end it 'returns a transport configured for agentless' do - expected_host = URI(format(Datadog::Ext::Profiling::Transport::HTTP::URI_TEMPLATE_DD_API, site)).host + expected_host = URI(format(Datadog::Profiling::Ext::Transport::HTTP::URI_TEMPLATE_DD_API, site)).host expect(default.api.adapter).to be_a_kind_of(Datadog::Transport::HTTP::Adapters::Net) expect(default.api.adapter.hostname).to eq(expected_host) expect(default.api.adapter.port).to eq(443) @@ -107,7 +107,7 @@ let(:options) { { **super(), agentless_allowed: true } } it 'returns a transport configured for agentless' do - expected_host = URI(format(Datadog::Ext::Profiling::Transport::HTTP::URI_TEMPLATE_DD_API, site)).host + expected_host = URI(format(Datadog::Profiling::Ext::Transport::HTTP::URI_TEMPLATE_DD_API, site)).host expect(default.api.adapter).to be_a_kind_of(Datadog::Transport::HTTP::Adapters::Net) expect(default.api.adapter.hostname).to eq(expected_host) expect(default.api.adapter.port).to eq(443) diff --git a/spec/ddtrace/profiling/transport/io/client_spec.rb b/spec/datadog/profiling/transport/io/client_spec.rb similarity index 95% rename from spec/ddtrace/profiling/transport/io/client_spec.rb rename to spec/datadog/profiling/transport/io/client_spec.rb index 15258d7a21d..9b553da5060 100644 --- a/spec/ddtrace/profiling/transport/io/client_spec.rb +++ b/spec/datadog/profiling/transport/io/client_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/transport/io/client' +require 'datadog/profiling/flush' +require 'datadog/profiling/transport/io/client' RSpec.describe Datadog::Profiling::Transport::IO::Client do subject(:client) { described_class.new(out, encoder) } diff --git a/spec/ddtrace/profiling/transport/io/response_spec.rb b/spec/datadog/profiling/transport/io/response_spec.rb similarity index 87% rename from spec/ddtrace/profiling/transport/io/response_spec.rb rename to spec/datadog/profiling/transport/io/response_spec.rb index a0070ee132e..f7976b3c684 100644 --- a/spec/ddtrace/profiling/transport/io/response_spec.rb +++ b/spec/datadog/profiling/transport/io/response_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/io/response' +require 'datadog/profiling/transport/io/response' RSpec.describe Datadog::Profiling::Transport::IO::Response do subject(:response) { described_class.new(result) } diff --git a/spec/ddtrace/profiling/transport/io_spec.rb b/spec/datadog/profiling/transport/io_spec.rb similarity index 97% rename from spec/ddtrace/profiling/transport/io_spec.rb rename to spec/datadog/profiling/transport/io_spec.rb index 8195c3479f1..18db283344f 100644 --- a/spec/ddtrace/profiling/transport/io_spec.rb +++ b/spec/datadog/profiling/transport/io_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/io' +require 'datadog/profiling/transport/io' RSpec.describe Datadog::Profiling::Transport::IO do describe '.new' do diff --git a/spec/ddtrace/profiling/transport/parcel_spec.rb b/spec/datadog/profiling/transport/parcel_spec.rb similarity index 94% rename from spec/ddtrace/profiling/transport/parcel_spec.rb rename to spec/datadog/profiling/transport/parcel_spec.rb index 0a955727686..e9162402e09 100644 --- a/spec/ddtrace/profiling/transport/parcel_spec.rb +++ b/spec/datadog/profiling/transport/parcel_spec.rb @@ -1,7 +1,7 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/transport/parcel' +require 'datadog/profiling/transport/parcel' RSpec.describe Datadog::Profiling::Transport::Parcel do subject(:parcel) { described_class.new(data) } diff --git a/spec/ddtrace/profiling/transport/request_spec.rb b/spec/datadog/profiling/transport/request_spec.rb similarity index 85% rename from spec/ddtrace/profiling/transport/request_spec.rb rename to spec/datadog/profiling/transport/request_spec.rb index 687dd156ef4..044b9f40a8f 100644 --- a/spec/ddtrace/profiling/transport/request_spec.rb +++ b/spec/datadog/profiling/transport/request_spec.rb @@ -1,8 +1,8 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling/flush' -require 'ddtrace/profiling/transport/request' +require 'datadog/profiling/flush' +require 'datadog/profiling/transport/request' RSpec.describe Datadog::Profiling::Transport::Request do subject(:request) { described_class.new(flush) } diff --git a/spec/ddtrace/profiling/validate_benchmarks_spec.rb b/spec/datadog/profiling/validate_benchmarks_spec.rb similarity index 100% rename from spec/ddtrace/profiling/validate_benchmarks_spec.rb rename to spec/datadog/profiling/validate_benchmarks_spec.rb diff --git a/spec/ddtrace/profiling_spec.rb b/spec/ddtrace/profiling_spec.rb index 27678a932a1..63e842eaecf 100644 --- a/spec/ddtrace/profiling_spec.rb +++ b/spec/ddtrace/profiling_spec.rb @@ -1,6 +1,6 @@ # typed: false require 'spec_helper' -require 'ddtrace/profiling' +require 'datadog/profiling' RSpec.describe Datadog::Profiling do extend ConfigurationHelpers From 97ba05641600bdd48c5e1937932c8fc787d918e5 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Tue, 25 Jan 2022 14:02:38 -0800 Subject: [PATCH 2/5] Namespace the Profiler class --- lib/datadog/core/configuration/components.rb | 2 +- lib/datadog/profiling/profiler.rb | 44 ++++++++++--------- .../core/configuration/components_spec.rb | 4 +- spec/datadog/core/configuration_spec.rb | 2 +- spec/datadog/profiling/preload_spec.rb | 2 +- spec/datadog/profiling/profiler_spec.rb | 2 +- spec/datadog/profiling/tasks/setup_spec.rb | 2 +- spec/ddtrace/auto_instrument_spec.rb | 2 +- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/datadog/core/configuration/components.rb b/lib/datadog/core/configuration/components.rb index 2e4c50ed174..fe0270519c8 100644 --- a/lib/datadog/core/configuration/components.rb +++ b/lib/datadog/core/configuration/components.rb @@ -225,7 +225,7 @@ def build_profiler(settings, agent_settings, tracer) exporters = build_profiler_exporters(settings, agent_settings) scheduler = build_profiler_scheduler(settings, recorder, exporters) - Datadog::Profiler.new(collectors, scheduler) + Datadog::Profiling::Profiler.new(collectors, scheduler) end private diff --git a/lib/datadog/profiling/profiler.rb b/lib/datadog/profiling/profiler.rb index ff79f294ccb..37752926c84 100644 --- a/lib/datadog/profiling/profiler.rb +++ b/lib/datadog/profiling/profiler.rb @@ -1,31 +1,33 @@ # typed: true module Datadog - # Profiling entry point, which coordinates collectors and a scheduler - class Profiler - attr_reader \ - :collectors, - :scheduler + module Profiling + # Profiling entry point, which coordinates collectors and a scheduler + class Profiler + attr_reader \ + :collectors, + :scheduler - def initialize(collectors, scheduler) - @collectors = collectors - @scheduler = scheduler - end + def initialize(collectors, scheduler) + @collectors = collectors + @scheduler = scheduler + end - def start - collectors.each(&:start) - scheduler.start - end + def start + collectors.each(&:start) + scheduler.start + end - def shutdown! - Datadog.logger.debug('Shutting down profiler') + def shutdown! + Datadog.logger.debug('Shutting down profiler') - collectors.each do |collector| - collector.enabled = false - collector.stop(true) - end + collectors.each do |collector| + collector.enabled = false + collector.stop(true) + end - scheduler.enabled = false - scheduler.stop(true) + scheduler.enabled = false + scheduler.stop(true) + end end end end diff --git a/spec/datadog/core/configuration/components_spec.rb b/spec/datadog/core/configuration/components_spec.rb index c903dee4417..7cf64f59c55 100644 --- a/spec/datadog/core/configuration/components_spec.rb +++ b/spec/datadog/core/configuration/components_spec.rb @@ -22,7 +22,7 @@ describe '::new' do let(:logger) { instance_double(Datadog::Core::Logger) } let(:tracer) { instance_double(Datadog::Tracer) } - let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiler) : nil } + let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiling::Profiler) : nil } let(:runtime_metrics) { instance_double(Datadog::Core::Workers::RuntimeMetrics) } let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics) } @@ -1126,7 +1126,7 @@ shared_context 'replacement' do let(:replacement) { instance_double(described_class) } let(:tracer) { instance_double(Datadog::Tracer) } - let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiler) : nil } + let(:profiler) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiling::Profiler) : nil } let(:runtime_metrics_worker) { instance_double(Datadog::Core::Workers::RuntimeMetrics, metrics: runtime_metrics) } let(:runtime_metrics) { instance_double(Datadog::Core::Runtime::Metrics, statsd: statsd) } let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics, statsd: statsd) } diff --git a/spec/datadog/core/configuration_spec.rb b/spec/datadog/core/configuration_spec.rb index e161148183f..6a48e374233 100644 --- a/spec/datadog/core/configuration_spec.rb +++ b/spec/datadog/core/configuration_spec.rb @@ -317,7 +317,7 @@ .to receive(:enabled) .and_return(true) - allow_any_instance_of(Datadog::Profiler) + allow_any_instance_of(Datadog::Profiling::Profiler) .to receive(:start) allow_any_instance_of(Datadog::Profiling::Tasks::Setup) .to receive(:run) diff --git a/spec/datadog/profiling/preload_spec.rb b/spec/datadog/profiling/preload_spec.rb index 689f967a967..d84448a1f43 100644 --- a/spec/datadog/profiling/preload_spec.rb +++ b/spec/datadog/profiling/preload_spec.rb @@ -6,7 +6,7 @@ subject(:preload) { load 'datadog/profiling/preload.rb' } it 'starts the profiler' do - profiler = instance_double(Datadog::Profiler) + profiler = instance_double(Datadog::Profiling::Profiler) expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) expect(profiler).to receive(:start) diff --git a/spec/datadog/profiling/profiler_spec.rb b/spec/datadog/profiling/profiler_spec.rb index 94eaaeddf25..d3c8edb7544 100644 --- a/spec/datadog/profiling/profiler_spec.rb +++ b/spec/datadog/profiling/profiler_spec.rb @@ -4,7 +4,7 @@ require 'datadog/profiling' require 'datadog/profiling/profiler' -RSpec.describe Datadog::Profiler do +RSpec.describe Datadog::Profiling::Profiler do subject(:profiler) { described_class.new(collectors, scheduler) } let(:collectors) { Array.new(2) { instance_double(Datadog::Profiling::Collectors::Stack) } } diff --git a/spec/datadog/profiling/tasks/setup_spec.rb b/spec/datadog/profiling/tasks/setup_spec.rb index b5b757f4623..4e34b99b803 100644 --- a/spec/datadog/profiling/tasks/setup_spec.rb +++ b/spec/datadog/profiling/tasks/setup_spec.rb @@ -173,7 +173,7 @@ end it 'sets up an at_fork hook that restarts the profiler' do - profiler = instance_double(Datadog::Profiler) + profiler = instance_double(Datadog::Profiling::Profiler) expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) expect(profiler).to receive(:start) diff --git a/spec/ddtrace/auto_instrument_spec.rb b/spec/ddtrace/auto_instrument_spec.rb index 3791012bcfb..5089084614b 100644 --- a/spec/ddtrace/auto_instrument_spec.rb +++ b/spec/ddtrace/auto_instrument_spec.rb @@ -115,7 +115,7 @@ def migrate_db skip 'Profiling is not supported on JRuby' if PlatformHelpers.jruby? skip 'Profiling is not supported on TruffleRuby' if PlatformHelpers.truffleruby? - profiler = instance_double('Datadog::Profiler') + profiler = instance_double('Datadog::Profiling::Profiler') expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) expect(profiler).to receive(:start) From a9485980a5e8c031cb46f87feb06b82d3508a43c Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 26 Jan 2022 16:35:07 -0800 Subject: [PATCH 3/5] Update lib/datadog/profiling/tasks/help.rb Co-authored-by: Ivo Anjo --- lib/datadog/profiling/tasks/help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/profiling/tasks/help.rb b/lib/datadog/profiling/tasks/help.rb index d418f65efb2..59eadb0368e 100644 --- a/lib/datadog/profiling/tasks/help.rb +++ b/lib/datadog/profiling/tasks/help.rb @@ -6,7 +6,7 @@ module Tasks class Help def run puts %( - Usage: ddtrace [command] [arguments] + Usage: ddtracerb [command] [arguments] exec [command]: Executes command with tracing & profiling preloaded. help: Prints this help message. ) From 8f6708ad61f9880627d195d5d9ca371ad68f6926 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 26 Jan 2022 16:53:58 -0800 Subject: [PATCH 4/5] Hide public profiler instance --- benchmarks/profiler_sample_loop.rb | 4 +- benchmarks/profiler_submission.rb | 4 +- docs/ProfilingDevelopment.md | 4 +- integration/apps/rack/app/acme.rb | 2 +- .../apps/rack/app/resque_background_job.rb | 2 +- .../apps/rack/app/sidekiq_background_job.rb | 2 +- .../app/controllers/health_controller.rb | 2 +- lib/datadog/core/configuration.rb | 3 +- lib/datadog/profiling.rb | 12 ++++ lib/datadog/profiling/preload.rb | 2 +- lib/datadog/profiling/tasks/setup.rb | 2 +- lib/ddtrace/auto_instrument.rb | 2 +- spec/datadog/core/configuration_spec.rb | 2 +- spec/datadog/profiling/preload_spec.rb | 13 +---- spec/datadog/profiling/tasks/setup_spec.rb | 9 +-- spec/{ddtrace => datadog}/profiling_spec.rb | 58 +++++++++++++++++++ spec/ddtrace/auto_instrument_spec.rb | 17 +----- 17 files changed, 90 insertions(+), 50 deletions(-) rename spec/{ddtrace => datadog}/profiling_spec.rb (81%) diff --git a/benchmarks/profiler_sample_loop.rb b/benchmarks/profiler_sample_loop.rb index 2d722ded5c8..261ff1b96bb 100644 --- a/benchmarks/profiler_sample_loop.rb +++ b/benchmarks/profiler_sample_loop.rb @@ -23,10 +23,10 @@ def create_profiler end # Stop background threads - Datadog.profiler.shutdown! + Datadog.shutdown! # Call collection directly - @stack_collector = Datadog.profiler.collectors.first + @stack_collector = Datadog.send(:components).profiler.collectors.first @recorder = @stack_collector.recorder end diff --git a/benchmarks/profiler_submission.rb b/benchmarks/profiler_submission.rb index e9e6e7842d1..7e09aaa04c9 100644 --- a/benchmarks/profiler_submission.rb +++ b/benchmarks/profiler_submission.rb @@ -37,10 +37,10 @@ def create_profiler end # Stop background threads - Datadog.profiler.shutdown! + Datadog.shutdown! # Call exporter directly - @exporter = Datadog.profiler.scheduler.exporters.first + @exporter = Datadog.send(:components).profiler.scheduler.exporters.first @flush = Marshal.load( Zlib::GzipReader.new(File.open(ENV['FLUSH_DUMP_FILE'] || 'benchmarks/data/profiler-submission-marshal.gz')) ) diff --git a/docs/ProfilingDevelopment.md b/docs/ProfilingDevelopment.md index 49d2726a4e3..a9fda86912c 100644 --- a/docs/ProfilingDevelopment.md +++ b/docs/ProfilingDevelopment.md @@ -34,8 +34,8 @@ Components below live inside <../lib/datadog/profiling>: When started via `ddtracerb exec` (together with `DD_PROFILING_ENABLED=true`), initialization goes through the following flow: -1. <../lib/datadog/profiling/preload.rb> triggers the creation of the `Datadog.profiler` instance by calling the method -2. `Datadog.profiler` is handled by `Datadog::Configuration`, which triggers the configuration of `ddtrace` components +1. <../lib/datadog/profiling/preload.rb> triggers the creation of the profiler instance by calling the method `Datadog::Profiling.start_if_enabled` +2. The profiler instance is handled by `Datadog::Configuration`, which triggers the configuration of `ddtrace` components in `#build_components` 3. Inside `Datadog::Components`, the `build_profiler` method triggers the execution of the `Tasks::Setup` 4. The `Setup` task activates our extensions diff --git a/integration/apps/rack/app/acme.rb b/integration/apps/rack/app/acme.rb index 87e45650320..4ef92f89d4f 100644 --- a/integration/apps/rack/app/acme.rb +++ b/integration/apps/rack/app/acme.rb @@ -89,7 +89,7 @@ def check(request) def detailed_check(request) ['200', { 'Content-Type' => 'application/json'}, [JSON.pretty_generate( webserver_process: $PROGRAM_NAME, - profiler_available: !!Datadog.profiler, + profiler_available: Datadog::Profiling.start_if_enabled, # NOTE: Threads can't be named on Ruby 2.1 and 2.2 profiler_threads: ((Thread.list.map(&:name).select { |it| it && it.include?('Profiling') }) unless RUBY_VERSION < '2.3') )], "\n"] diff --git a/integration/apps/rack/app/resque_background_job.rb b/integration/apps/rack/app/resque_background_job.rb index 4cde247a236..6af61c61cb8 100644 --- a/integration/apps/rack/app/resque_background_job.rb +++ b/integration/apps/rack/app/resque_background_job.rb @@ -28,7 +28,7 @@ def self.perform(key, value) key: key, value: value, resque_process: $PROGRAM_NAME, - profiler_available: !!Datadog.profiler, + profiler_available: Datadog::Profiling.start_if_enabled, # NOTE: Threads can't be named on Ruby 2.1 and 2.2 profiler_threads: ((Thread.list.map(&:name).select { |it| it && it.include?('Profiling') }) unless RUBY_VERSION < '2.3') )) diff --git a/integration/apps/rack/app/sidekiq_background_job.rb b/integration/apps/rack/app/sidekiq_background_job.rb index 03c3a59903d..84a2699d182 100644 --- a/integration/apps/rack/app/sidekiq_background_job.rb +++ b/integration/apps/rack/app/sidekiq_background_job.rb @@ -26,7 +26,7 @@ def perform(key, value) key: key, value: value, sidekiq_process: $PROGRAM_NAME, - profiler_available: !!Datadog.profiler, + profiler_available: Datadog::Profiling.start_if_enabled, # NOTE: Threads can't be named on Ruby 2.1 and 2.2 profiler_threads: ((Thread.list.map(&:name).select { |it| it && it.include?('Profiling') }) unless RUBY_VERSION < '2.3') )) diff --git a/integration/apps/rails-five/app/controllers/health_controller.rb b/integration/apps/rails-five/app/controllers/health_controller.rb index 07d7c7dc869..2c55f15cc4b 100644 --- a/integration/apps/rails-five/app/controllers/health_controller.rb +++ b/integration/apps/rails-five/app/controllers/health_controller.rb @@ -12,7 +12,7 @@ def check def detailed_check render json: { webserver_process: $PROGRAM_NAME, - profiler_available: !!Datadog.profiler, + profiler_available: Datadog::Profiling.start_if_enabled, profiler_threads: Thread.list.map(&:name).select { |it| it && it.include?('Profiling') } } end diff --git a/lib/datadog/core/configuration.rb b/lib/datadog/core/configuration.rb index a5a676c9798..be1db7b69ca 100644 --- a/lib/datadog/core/configuration.rb +++ b/lib/datadog/core/configuration.rb @@ -153,8 +153,7 @@ def configuration_for(target, option = nil) def_delegators \ :components, - :health_metrics, - :profiler + :health_metrics def logger # avoid initializing components if they didn't already exist diff --git a/lib/datadog/profiling.rb b/lib/datadog/profiling.rb index ac3a3448a74..6b3c22911ef 100644 --- a/lib/datadog/profiling.rb +++ b/lib/datadog/profiling.rb @@ -82,6 +82,18 @@ def self.configuration ) end + # Starts the profiler, if the profiler is supported by in + # this runtime environment and if the profiler has been enabled + # in configuration. + # + # @return [Boolean] `true` if the profiler has successfully started, otherwise `false`. + # @public_api + def self.start_if_enabled + # Getting the profiler instance triggers start as a side-effect; + # otherwise we get nil + !!Datadog.send(:components).profiler + end + private_class_method def self.ruby_engine_unsupported? 'JRuby is not supported' if RUBY_ENGINE == 'jruby' end diff --git a/lib/datadog/profiling/preload.rb b/lib/datadog/profiling/preload.rb index 61cd81a7e6f..99dbbfefdf8 100644 --- a/lib/datadog/profiling/preload.rb +++ b/lib/datadog/profiling/preload.rb @@ -1,4 +1,4 @@ # typed: strict require 'ddtrace' -Datadog.profiler.start if Datadog.profiler +Datadog::Profiling.start_if_enabled diff --git a/lib/datadog/profiling/tasks/setup.rb b/lib/datadog/profiling/tasks/setup.rb index be8379028ce..72ac7802900 100644 --- a/lib/datadog/profiling/tasks/setup.rb +++ b/lib/datadog/profiling/tasks/setup.rb @@ -61,7 +61,7 @@ def setup_at_fork_hooks Thread.current.send(:update_native_ids) if Thread.current.respond_to?(:update_native_ids, true) # Restart profiler, if enabled - Datadog.profiler.start if Datadog.profiler + Datadog::Profiling.start_if_enabled rescue StandardError => e Datadog.logger.warn do "Error during post-fork hooks. Cause: #{e.message} Location: #{Array(e.backtrace).first}" diff --git a/lib/ddtrace/auto_instrument.rb b/lib/ddtrace/auto_instrument.rb index 09d1374dacd..3731c58c6c1 100644 --- a/lib/ddtrace/auto_instrument.rb +++ b/lib/ddtrace/auto_instrument.rb @@ -5,4 +5,4 @@ require 'ddtrace' Datadog.add_auto_instrument -Datadog.profiler.start if Datadog.profiler +Datadog::Profiling.start_if_enabled diff --git a/spec/datadog/core/configuration_spec.rb b/spec/datadog/core/configuration_spec.rb index 6a48e374233..ec963d8d981 100644 --- a/spec/datadog/core/configuration_spec.rb +++ b/spec/datadog/core/configuration_spec.rb @@ -325,7 +325,7 @@ it 'starts the profiler' do configure - expect(test_class.profiler).to have_received(:start) + expect(test_class.send(:components).profiler).to have_received(:start) end end end diff --git a/spec/datadog/profiling/preload_spec.rb b/spec/datadog/profiling/preload_spec.rb index d84448a1f43..9759bcb26c9 100644 --- a/spec/datadog/profiling/preload_spec.rb +++ b/spec/datadog/profiling/preload_spec.rb @@ -6,19 +6,8 @@ subject(:preload) { load 'datadog/profiling/preload.rb' } it 'starts the profiler' do - profiler = instance_double(Datadog::Profiling::Profiler) - - expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) - expect(profiler).to receive(:start) + expect(Datadog::Profiling).to receive(:start_if_enabled) preload end - - context 'when the profiler is not available' do - it 'does not raise any error' do - expect(Datadog).to receive(:profiler).and_return(nil) - - preload - end - end end diff --git a/spec/datadog/profiling/tasks/setup_spec.rb b/spec/datadog/profiling/tasks/setup_spec.rb index 4e34b99b803..0c0b228162e 100644 --- a/spec/datadog/profiling/tasks/setup_spec.rb +++ b/spec/datadog/profiling/tasks/setup_spec.rb @@ -151,7 +151,7 @@ context 'when Process#at_fork is available' do before do allow(Process).to receive(:respond_to?).with(:at_fork).and_return(true) - allow(Datadog).to receive(:profiler) + allow(Datadog::Profiling).to receive(:start_if_enabled) without_partial_double_verification do allow(Process).to receive(:at_fork) @@ -173,17 +173,14 @@ end it 'sets up an at_fork hook that restarts the profiler' do - profiler = instance_double(Datadog::Profiling::Profiler) - - expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) - expect(profiler).to receive(:start) + expect(Datadog::Profiling).to receive(:start_if_enabled) at_fork_hook.call end context 'when there is an issue starting the profiler' do before do - expect(Datadog).to receive(:profiler).and_raise('Dummy exception') + expect(Datadog::Profiling).to receive(:start_if_enabled).and_raise('Dummy exception') allow(Datadog.logger).to receive(:warn) # Silence logging during tests end diff --git a/spec/ddtrace/profiling_spec.rb b/spec/datadog/profiling_spec.rb similarity index 81% rename from spec/ddtrace/profiling_spec.rb rename to spec/datadog/profiling_spec.rb index 63e842eaecf..80c5427899a 100644 --- a/spec/ddtrace/profiling_spec.rb +++ b/spec/datadog/profiling_spec.rb @@ -5,6 +5,64 @@ RSpec.describe Datadog::Profiling do extend ConfigurationHelpers + describe '.configure' do + subject(:configure) { described_class.configure(&block) } + let(:block) { proc {} } + + it 'delegates to the global configuration' do + expect(Datadog).to receive(:internal_configure) { |&b| expect(b).to be_a_kind_of(Proc) } + configure + end + + context 'validation' do + it 'wraps the configuration object with a proxy' do + described_class.configure do |c| + expect(c).to be_a_kind_of(Datadog::Core::Configuration::ValidationProxy::Profiling) + end + end + + it 'allows profiling options' do + described_class.configure do |c| + expect(c).to respond_to(:profiling) + end + end + + it 'raises errors for non-profiling options' do + described_class.configure do |c| + expect(c).to_not respond_to(:tracer) + end + end + end + end + + describe '.configuration' do + subject(:configuration) { described_class.configuration } + it 'returns the global configuration' do + expect(configuration) + .to be_a_kind_of(Datadog::Core::Configuration::ValidationProxy::Profiling) + + expect(configuration.send(:settings)).to eq(Datadog.send(:internal_configuration)) + end + end + + describe '.start_if_enabled' do + subject(:start_if_enabled) { described_class.start_if_enabled } + + before do + allow(Datadog.send(:components)).to receive(:profiler).and_return(result) + end + + context 'with the profiler instance available' do + let(:result) { double } + it { is_expected.to be(true) } + end + + context 'with the profiler instance not available' do + let(:result) { nil } + it { is_expected.to be(false) } + end + end + describe '::supported?' do subject(:supported?) { described_class.supported? } diff --git a/spec/ddtrace/auto_instrument_spec.rb b/spec/ddtrace/auto_instrument_spec.rb index 5089084614b..f51d5dcbef4 100644 --- a/spec/ddtrace/auto_instrument_spec.rb +++ b/spec/ddtrace/auto_instrument_spec.rb @@ -112,22 +112,7 @@ def migrate_db end it 'starts the profiler' do - skip 'Profiling is not supported on JRuby' if PlatformHelpers.jruby? - skip 'Profiling is not supported on TruffleRuby' if PlatformHelpers.truffleruby? - - profiler = instance_double('Datadog::Profiling::Profiler') - - expect(Datadog).to receive(:profiler).and_return(profiler).at_least(:once) - expect(profiler).to receive(:start) - + expect(Datadog::Profiling).to receive(:start_if_enabled) auto_instrument end - - context 'when the profiler is not available' do - it 'does not raise any error' do - expect(Datadog).to receive(:profiler).and_return(nil) - - auto_instrument - end - end end From 01aa3784161725c3ef60417748acd7669c76971a Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Thu, 27 Jan 2022 12:09:13 -0800 Subject: [PATCH 5/5] Start profiler in start_if_enabled --- lib/datadog/profiling.rb | 8 ++++++-- spec/datadog/profiling_spec.rb | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/datadog/profiling.rb b/lib/datadog/profiling.rb index 6b3c22911ef..72f4a3c53ef 100644 --- a/lib/datadog/profiling.rb +++ b/lib/datadog/profiling.rb @@ -89,9 +89,13 @@ def self.configuration # @return [Boolean] `true` if the profiler has successfully started, otherwise `false`. # @public_api def self.start_if_enabled - # Getting the profiler instance triggers start as a side-effect; + # If the profiler was not previously touched, getting the profiler instance triggers start as a side-effect # otherwise we get nil - !!Datadog.send(:components).profiler + profiler = Datadog.send(:components).profiler + # ...but we still try to start it BECAUSE if the process forks, the profiler will exist but may + # not yet have been started in the fork + profiler.start if profiler + !!profiler end private_class_method def self.ruby_engine_unsupported? diff --git a/spec/datadog/profiling_spec.rb b/spec/datadog/profiling_spec.rb index 80c5427899a..67a1b7c1024 100644 --- a/spec/datadog/profiling_spec.rb +++ b/spec/datadog/profiling_spec.rb @@ -53,8 +53,11 @@ end context 'with the profiler instance available' do - let(:result) { double } - it { is_expected.to be(true) } + let(:result) { instance_double(Datadog::Profiling::Profiler) } + it 'starts the profiler instance' do + expect(result).to receive(:start) + is_expected.to be(true) + end end context 'with the profiler instance not available' do