-
Notifications
You must be signed in to change notification settings - Fork 373
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
DEBUG-3210 DI: change logging to be appropriate for customer inspection #4230
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,7 @@ | ||||||
# frozen_string_literal: true | ||||||
|
||||||
require_relative 'logging' | ||||||
|
||||||
module Datadog | ||||||
module DI | ||||||
# Component for dynamic instrumentation. | ||||||
|
@@ -13,12 +15,14 @@ module DI | |||||
# intalled tracepoints and so on. Component will clean up all | ||||||
# resources and installed tracepoints upon shutdown. | ||||||
class Component | ||||||
include Logging | ||||||
|
||||||
class << self | ||||||
def build(settings, agent_settings, telemetry: nil) | ||||||
return unless settings.respond_to?(:dynamic_instrumentation) && settings.dynamic_instrumentation.enabled | ||||||
|
||||||
unless settings.respond_to?(:remote) && settings.remote.enabled | ||||||
Datadog.logger.debug("Dynamic Instrumentation could not be enabled because Remote Configuration Management is not available. To enable Remote Configuration, see https://docs.datadoghq.com/agent/remote_config") | ||||||
Datadog.logger.warn("Dynamic Instrumentation could not be enabled because Remote Configuration Management is not available. To enable Remote Configuration, see https://docs.datadoghq.com/agent/remote_config") | ||||||
return | ||||||
end | ||||||
|
||||||
|
@@ -53,12 +57,12 @@ def environment_supported?(settings) | |||||
# TODO add tests? | ||||||
unless settings.dynamic_instrumentation.internal.development | ||||||
if Datadog::Core::Environment::Execution.development? | ||||||
Datadog.logger.debug("Not enabling dynamic instrumentation because we are in development environment") | ||||||
Datadog.logger.warn("Not enabling dynamic instrumentation because we are in development environment") | ||||||
return false | ||||||
end | ||||||
end | ||||||
if RUBY_ENGINE != 'ruby' || RUBY_VERSION < '2.6' | ||||||
Datadog.logger.debug("Not enabling dynamic instrumentation because of unsupported Ruby version") | ||||||
Datadog.logger.warn("Not enabling dynamic instrumentation because of unsupported Ruby version") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this one, I suggest being a bit more actionable, e.g.
Suggested change
|
||||||
return false | ||||||
end | ||||||
true | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# rubocop:disable Lint/AssignmentInCondition | ||
|
||
require 'benchmark' | ||
require_relative 'logging' | ||
|
||
module Datadog | ||
module DI | ||
|
@@ -54,6 +55,8 @@ module DI | |
# | ||
# @api private | ||
class Instrumenter | ||
include Logging | ||
|
||
def initialize(settings, serializer, logger, code_tracker: nil, telemetry: nil) | ||
@settings = settings | ||
@serializer = serializer | ||
|
@@ -305,13 +308,13 @@ def hook_line(probe, &block) | |
end | ||
rescue => exc | ||
raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions | ||
logger.warn("Unhandled exception in line trace point: #{exc.class}: #{exc}") | ||
log_warn_internal("Unhandled exception in line trace point: #{exc.class}: #{exc}") | ||
telemetry&.report(exc, description: "Unhandled exception in line trace point") | ||
# TODO test this path | ||
end | ||
rescue => exc | ||
raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions | ||
logger.warn("Unhandled exception in line trace point: #{exc.class}: #{exc}") | ||
log_warn_internal("Unhandled exception in line trace point: #{exc.class}: #{exc}") | ||
telemetry&.report(exc, description: "Unhandled exception in line trace point") | ||
Comment on lines
310
to
318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to expose a block-based version of these methods. E.g. right now the whole string is built, even if the logger is going to throw it away. In other parts of the codebase we often do |
||
# TODO test this path | ||
end | ||
|
@@ -357,7 +360,7 @@ def hook(probe, &block) | |
hook_line(probe, &block) | ||
else | ||
# TODO add test coverage for this path | ||
logger.warn("Unknown probe type to hook: #{probe}") | ||
log_warn_internal("Unknown probe type to hook: #{probe}") | ||
end | ||
end | ||
|
||
|
@@ -368,7 +371,7 @@ def unhook(probe) | |
unhook_line(probe) | ||
else | ||
# TODO add test coverage for this path | ||
logger.warn("Unknown probe type to unhook: #{probe}") | ||
log_warn_internal("Unknown probe type to unhook: #{probe}") | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module DI | ||
# Logging for DI | ||
module Logging | ||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Since every class that uses This would also solve the potential (small) sharp edge of "oops I included Logging but this class doesn't already have a |
||
# Logs an internal warning message. | ||
# When verbose logging is enabled, the logging happens at warn level. | ||
# When verbose logging is disabled, the logging happens at debug level | ||
# (which is how the rest of the library is reporting its internal | ||
# warnings/errors). | ||
def log_warn_internal(msg) | ||
if settings.dynamic_instrumentation.internal.verbose_logging | ||
logger.warn(msg) | ||
else | ||
logger.debug(msg) | ||
end | ||
end | ||
|
||
# Logs an internal informational message. | ||
# When verbose logging is enabled, the logging happens at info level. | ||
# When verbose logging is disabled, nothing is logged. | ||
def log_info_internal(msg) | ||
if settings.dynamic_instrumentation.internal.verbose_logging | ||
logger.info(msg) | ||
end | ||
end | ||
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: This is a bit unexpected to me; why not log it at debug level as well? E.g. it seems weird that if I enable debug logging with |
||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Since this is a customer-visible string, I'd suggest not using the "we" since it's a bit confusing. Here's a potential alternative