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 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/datadog/di.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def component
#
# If DI is enabled programmatically, the application can (and must,
# for line probes to work) activate tracking in an initializer.
# We seem to have Datadog.logger here already
Datadog.logger.debug("di: activating code tracking")
Datadog::DI.activate_tracking
end

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/di/contrib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module DI
module Contrib
module_function def load_now_or_later
if Datadog::Core::Contrib::Rails::Utils.railtie_supported?
Datadog.logger.debug('di: loading contrib/railtie')
require_relative 'contrib/railtie'
else
load_now
Expand All @@ -18,6 +19,7 @@ module Contrib
# dependencies are loaded (or potentially loaded).
module_function def load_now
if defined?(ActiveRecord::Base)
Datadog.logger.debug('di: loading contrib/active_record')
require_relative 'contrib/active_record'
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/di/probe_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ def add_probe(probe)
# Always remove from pending list here because it makes the
# API smaller and shouldn't cause any actual problems.
@pending_probes.delete(probe.id)
logger.debug { "di: installed #{probe.type} probe at #{probe.location}" }
true
rescue Error::DITargetNotDefined
@pending_probes[probe.id] = probe
logger.debug { "di: could not install #{probe.type} probe at #{probe.location} because its target is not defined, adding it to pending list" }
false
end
rescue => exc
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/di/probe_notifier_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module DI
# The loop inside the worker rescues all exceptions to prevent termination
# due to unhandled exceptions raised by any downstream code.
# This includes communication and protocol errors when sending the
# payloads to the agent.
# events to the agent.
#
# The worker groups the data to send into batches. The goal is to perform
# no more than one network operation per event type per second.
Expand Down Expand Up @@ -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

@thread = Thread.new do
loop do
# TODO If stop is requested, we stop immediately without
Expand Down Expand Up @@ -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")
wake.signal
if thread
unless thread.join(timeout)
Expand Down Expand Up @@ -234,6 +236,7 @@ def set_sleep_remaining
end
if batch.any? # steep:ignore
begin
logger.debug { "di: sending #{batch.length} #{event_type} events to agent" }
transport.public_send("send_#{event_type}", batch)
time = Core::Utils::Time.get_time
@lock.synchronize do
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/di/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def receivers(telemetry)
payload = probe_notification_builder.build_received(probe)
probe_notifier_worker = component.probe_notifier_worker
probe_notifier_worker.add_status(payload)
component.logger.debug { "di: received probe from RC: #{probe.type} #{probe.location}" }
component.logger.debug { "di: received probe from RC: #{probe.type} at #{probe.location}" }

begin
# TODO test exception capture
Expand Down
Loading