Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI progress logs #4283

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

DI progress logs #4283

wants to merge 9 commits into from

Conversation

p-datadog
Copy link
Member

What does this PR do?

Motivation:

Change log entry

Additional Notes:

How to test the change?

Copy link

github-actions bot commented Jan 13, 2025

👋 Hey @p-datadog, please fill "Change log entry" section in the pull request description.

If changes need to be present in CHANGELOG.md you can state it this way

**Change log entry**

Yes. A brief summary to be placed into the CHANGELOG.md

(possible answers Yes/Yep/Yeah)

Or you can opt out like that

**Change log entry**

None.

(possible answers No/Nope/None)

Visited at: 2025-01-14 16:40:36 UTC

@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented Jan 13, 2025

Datadog Report

Branch report: di-progress-logs
Commit report: baa571f
Test service: dd-trace-rb

❌ 37 Failed (0 Known Flaky), 21910 Passed, 1476 Skipped, 6m 0.48s Total Time

❌ Failed Tests (37)

This report shows up to 5 failed tests.

  • Datadog::DI::ProbeManager#add_probe log probe when instrumentation target is missing returns false and adds probe to the pending probe list - rspec - Details

    Expand for error
     ./lib/datadog/di/probe_manager.rb:118:in 'block in Datadog::DI::ProbeManager#add_probe'
     ./lib/datadog/di/probe_manager.rb:96:in 'Monitor#synchronize'
     ./lib/datadog/di/probe_manager.rb:96:in 'Datadog::DI::ProbeManager#add_probe'
     ./spec/datadog/di/probe_manager_spec.rb:88:in 'block (5 levels) in <top (required)>'
     ./spec/spec_helper.rb:238:in 'block (2 levels) in <top (required)>'
     ./spec/spec_helper.rb:123:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/webmock-3.24.0/lib/webmock/rspec.rb:39:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/rspec-wait-0.0.10/lib/rspec/wait.rb:47:in 'block (2 levels) in <top (required)>'
     ------------------
     --- Caused by: ---
     ...
    
  • Datadog::DI::ProbeManager#add_probe log probe when probe is installed successfully returns true and adds probe to the installed probe list - rspec - Details

    Expand for error
     ./lib/datadog/di/probe_manager.rb:114:in 'block in Datadog::DI::ProbeManager#add_probe'
     ./lib/datadog/di/probe_manager.rb:96:in 'Monitor#synchronize'
     ./lib/datadog/di/probe_manager.rb:96:in 'Datadog::DI::ProbeManager#add_probe'
     ./spec/datadog/di/probe_manager_spec.rb:68:in 'block (5 levels) in <top (required)>'
     ./spec/spec_helper.rb:238:in 'block (2 levels) in <top (required)>'
     ./spec/spec_helper.rb:123:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/webmock-3.24.0/lib/webmock/rspec.rb:39:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/rspec-wait-0.0.10/lib/rspec/wait.rb:47:in 'block (2 levels) in <top (required)>'
    
  • Datadog::DI::ProbeNotifierWorker started #add_snapshot sends the snapshot - rspec - Details

    Expand for error
     ./lib/datadog/di/probe_notifier_worker.rb:237:in 'block (2 levels) in <class:ProbeNotifierWorker>'
     ./lib/datadog/di/probe_notifier_worker.rb:267:in 'Datadog::DI::ProbeNotifierWorker#maybe_send'
     ./lib/datadog/di/probe_notifier_worker.rb:76:in 'block (2 levels) in Datadog::DI::ProbeNotifierWorker#start'
     ./lib/datadog/di/probe_notifier_worker.rb:49:in 'block in Datadog::DI::ProbeNotifierWorker#start'
     ./spec/spec_helper.rb:254:in 'block in DatadogThreadDebugger#initialize'
    
  • Datadog::DI::ProbeNotifierWorker started #add_snapshot when three snapshots are added in quick succession sends two batches - rspec - Details

    Expand for error
     RSpec::Core::MultipleExceptionError
    
  • DI integration from remote config method probe received matching a loaded class and target method is invoked notifies about execution - rspec - Details

    Expand for error
     expected "di: installed log probe 11" to match /received probe from RC:/
     Diff:
     @@ -1 +1 @@
     -/received probe from RC:/
     +"di: installed log probe 11"
     
     Failure/Error: expect(block.call).to match(expected_msg)
     
       expected "di: installed log probe 11" to match /received probe from RC:/
       Diff:
     ...
    

@pr-commenter
Copy link

pr-commenter bot commented Jan 13, 2025

Benchmarks

Benchmark execution time: 2025-02-03 21:56:07

Comparing candidate commit 607ad2b in PR branch di-progress-logs with baseline commit 310b842 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 31 metrics, 2 unstable metrics.

@p-datadog p-datadog changed the base branch from master to di-railtie January 14, 2025 16:40
Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current draft looks reasonable, left a small note

Comment on lines 61 to 64
if %w'1 true debug'.include?(ENV['DD_TRACE_DEBUG'])
# We seem to have Datadog.logger here already
Datadog.logger.debug("di: activating code tracking")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the DD_TRACE_DEBUG check is needed -- the logger initialization is already supposed to be looking at this setting? https://github.com/DataDog/dd-trace-rb/blob/master/lib/datadog/core/configuration.rb#L279 and https://github.com/DataDog/dd-trace-rb/blob/master/lib/datadog/core/configuration/components.rb#L37 should take care of it.

Base automatically changed from di-railtie to master January 14, 2025 20:07
@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented Jan 27, 2025

Datadog Report

Branch report: di-progress-logs
Commit report: 607ad2b
Test service: dd-trace-rb

❌ 49 Failed (0 Known Flaky), 22012 Passed, 1476 Skipped, 7m 30.98s Total Time

❌ Failed Tests (49)

This report shows up to 5 failed tests.

  • Datadog::Core::Configuration::Components::new @environment_logger_extra DI is enabled JRuby reports DI as disabled - rspec - Details

    Expand for error
         expected: 1 time with arguments: (/cannot enable dynamic instrumentation/)
         received: 0 times
     
     
           expected: 1 time with arguments: (/cannot enable dynamic instrumentation/)
           received: 0 times
     ./spec/datadog/core/configuration/components_spec.rb:146:in \`block in <main>'
     ./spec/datadog/core/configuration/components_spec.rb:54:in \`block in <main>'
     /usr/local/bundle/gems/climate_control-0.2.0/lib/climate_control/modifier.rb:31:in \`run_block'
     /usr/local/bundle/gems/climate_control-0.2.0/lib/climate_control/modifier.rb:13:in \`block in process'
     ...
    
  • Datadog::DI::Component.build when dynamic instrumentation is enabled when remote config is disabled returns nil - rspec

  • Datadog::DI::ProbeManager#add_probe log probe when instrumentation target is missing returns false and adds probe to the pending probe list - rspec - Details

    Expand for error
     ./lib/datadog/di/probe_manager.rb:118:in 'block in Datadog::DI::ProbeManager#add_probe'
     ./lib/datadog/di/probe_manager.rb:96:in 'Monitor#synchronize'
     ./lib/datadog/di/probe_manager.rb:96:in 'Datadog::DI::ProbeManager#add_probe'
     ./spec/datadog/di/probe_manager_spec.rb:88:in 'block (5 levels) in <top (required)>'
     ./spec/spec_helper.rb:238:in 'block (2 levels) in <top (required)>'
     ./spec/spec_helper.rb:123:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/webmock-3.24.0/lib/webmock/rspec.rb:39:in 'block (2 levels) in <top (required)>'
     /usr/local/bundle/gems/rspec-wait-0.0.10/lib/rspec/wait.rb:47:in 'block (2 levels) in <top (required)>'
     ------------------
     --- Caused by: ---
     ...
    
  • Datadog::DI::ProbeManager#add_probe log probe when probe is installed successfully returns true and adds probe to the installed probe list - rspec

  • Datadog::DI::ProbeManager#remove_other_probes when there are installed probes when there is an exception during de-instrumentation logs warning and keeps probe in installed list - rspec

@@ -45,6 +45,7 @@ def initialize(settings, transport, logger, telemetry: nil)

def start
return if @thread
logger.debug("di: starting probe notifier: pid #{$$}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Avoid using cryptic PERL names. Consider importing English and using $PROCESS_ID instead. (...read more)

The rule 'Avoid using Perl-style special variables' is important for improving the readability and maintainability of your code. Perl-style special variables, such as $0, $1, and $_, while powerful, can make your code less readable and harder to understand, especially for developers unfamiliar with Perl or its influence on Ruby. They can also introduce subtle bugs due to their global nature and the special behavior associated with them.

To avoid violating this rule, you can use the more descriptive aliases provided by the English library. This library, which is part of Ruby's standard library, provides human-readable names for Perl-style special variables. For example, instead of using $& to get the string matched by the last successful pattern match, you can use $MATCH.

Here's a compliant code example: Instead of $_, you can use $LAST_READ_LINE. Instead of $!, use $ERROR_INFO. This makes your code more self-explanatory and reduces the potential for confusion. Example:

require 'English'
puts $LAST_READ_LINE
puts $ERROR_INFO

This practice significantly enhances the readability of your code and makes it more accessible to developers who are not familiar with Perl-style variables.

View in Datadog  Leave us feedback  Documentation

@@ -17,6 +17,9 @@ module DI
class Component
class << self
def build(settings, agent_settings, logger, telemetry: nil)
logger = Logger.new(STDERR, progname: "\033[7mdatadog/di\e[0m")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
logger = Logger.new(STDERR, progname: "\033[7mdatadog/di\e[0m")
logger = Logger.new($stderr, progname: "\033[7mdatadog/di\e[0m")
Consider using a $stderr (...read more)

The rule "Avoid standard constants" is important in Ruby development as it encourages the use of global variables over standard constants. In Ruby, standard constants like STDOUT and STDERR are not as flexible as their global counterparts $stdout and $stderr.

The main reason for avoiding standard constants is that they are not interchangeable in the same way that global variables are. This means they are less suited to situations where you might need to redirect output or error streams. For instance, in testing scenarios, you might want to redirect $stdout or $stderr to a different output stream.

Fortunately, Ruby provides an easy way to avoid this issue. Instead of using standard constants, you should use global variables. For example, replace STDOUT with $stdout and STDERR with $stderr. This allows for greater flexibility in your code and makes it more adaptable to different situations.

View in Datadog  Leave us feedback  Documentation

@@ -94,6 +95,7 @@ def start
# to killing the thread using Thread#kill.
def stop(timeout = 1)
@stop_requested = true
logger.debug("di: stopping probe notifier: pid #{$$}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Avoid using cryptic PERL names. Consider importing English and using $PROCESS_ID instead. (...read more)

The rule 'Avoid using Perl-style special variables' is important for improving the readability and maintainability of your code. Perl-style special variables, such as $0, $1, and $_, while powerful, can make your code less readable and harder to understand, especially for developers unfamiliar with Perl or its influence on Ruby. They can also introduce subtle bugs due to their global nature and the special behavior associated with them.

To avoid violating this rule, you can use the more descriptive aliases provided by the English library. This library, which is part of Ruby's standard library, provides human-readable names for Perl-style special variables. For example, instead of using $& to get the string matched by the last successful pattern match, you can use $MATCH.

Here's a compliant code example: Instead of $_, you can use $LAST_READ_LINE. Instead of $!, use $ERROR_INFO. This makes your code more self-explanatory and reduces the potential for confusion. Example:

require 'English'
puts $LAST_READ_LINE
puts $ERROR_INFO

This practice significantly enhances the readability of your code and makes it more accessible to developers who are not familiar with Perl-style variables.

View in Datadog  Leave us feedback  Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants