Skip to content

Commit

Permalink
Add comments for TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Sep 13, 2024
1 parent 3860fa7 commit d9aa760
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/datadog/core/environment/cgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def descriptors(process = 'self')
end
end
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
)
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/core/environment/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def descriptor
break
end
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Error while parsing container info. Cause: #{e.class.name} #{e.message} " \
"Location: #{Array(e.backtrace).first}"
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/core/metrics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def count(stat, value = nil, options = nil, &block)

statsd.count(stat, value, metric_options(options))
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Failed to send count stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Expand All @@ -110,6 +111,7 @@ def distribution(stat, value = nil, options = nil, &block)

statsd.distribution(stat, value, metric_options(options))
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Failed to send distribution stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Expand All @@ -122,6 +124,7 @@ def increment(stat, options = nil)

statsd.increment(stat, metric_options(options))
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Failed to send increment stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Expand All @@ -135,6 +138,7 @@ def gauge(stat, value = nil, options = nil, &block)

statsd.gauge(stat, value, metric_options(options))
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Failed to send gauge stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Expand All @@ -153,6 +157,7 @@ def time(stat, options = nil)
distribution(stat, ((finished - start) * 1000), options)
end
rescue StandardError => e
# TODO: add telemetry logs
Datadog.logger.error(
"Failed to send time stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/remote/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def initialize(settings, capabilities, agent_settings)
@client.sync
@healthy ||= true
rescue Client::SyncError => e
# Not sure
Datadog.logger.error do
"remote worker client sync error: #{e.message} location: #{Array(e.backtrace).first}. skipping sync"
end
Expand All @@ -48,6 +49,7 @@ def initialize(settings, capabilities, agent_settings)
# negotiation object stores error logging state that should be reset.
negotiation = Negotiation.new(settings, agent_settings)

# Not sure
Datadog.logger.error do
"remote worker error: #{e.class.name} #{e.message} location: #{Array(e.backtrace).first}. "\
'reseting client state'
Expand Down
6 changes: 6 additions & 0 deletions lib/datadog/core/remote/negotiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def endpoint?(path)

if res.internal_error? && network_error?(res.error)
unless @logged[:agent_unreachable]
# TODO: change to warning
Datadog.logger.error { "agent unreachable: cannot negotiate #{path}" }
@logged[:agent_unreachable] = true
end
Expand All @@ -29,6 +30,7 @@ def endpoint?(path)

if res.not_found?
unless @logged[:no_info_endpoint]
# TODO: change to warning
Datadog.logger.error { "agent reachable but has no /info endpoint: cannot negotiate #{path}" }
@logged[:no_info_endpoint] = true
end
Expand All @@ -38,6 +40,8 @@ def endpoint?(path)

unless res.ok?
unless @logged[:unexpected_response]
# TODO: Report telemetry logs
# TODO: change to warning
Datadog.logger.error { "agent reachable but unexpected response: cannot negotiate #{path}" }
@logged[:unexpected_response] = true
end
Expand All @@ -47,6 +51,8 @@ def endpoint?(path)

unless res.endpoints.include?(path)
unless @logged[:no_config_endpoint]
# TODO: Report telemetry logs
# TODO: change to warning
Datadog.logger.error { "agent reachable but does not report #{path}" }
@logged[:no_config_endpoint] = true
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/runtime/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def gc_metrics
def try_flush
yield
rescue StandardError => e
# TODO: Report telemetry logs
# TODO: change to warning
Datadog.logger.error("Error while sending runtime metric. Cause: #{e.class.name} #{e.message}")
end

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/opentelemetry/sdk/propagator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def inject(
setter: ::OpenTelemetry::Context::Propagation.text_map_setter
)
unless setter == ::OpenTelemetry::Context::Propagation.text_map_setter
# Not to report telemetry logs for now
Datadog.logger.error(
'Custom setter is not supported. Please inform the `datadog` team at ' \
' https://github.com/DataDog/dd-trace-rb of your use case so we can best support you. Using the default ' \
Expand All @@ -31,6 +32,7 @@ def extract(
)
if getter != ::OpenTelemetry::Context::Propagation.text_map_getter &&
getter != ::OpenTelemetry::Common::Propagation.rack_env_getter
# Not to report telemetry logs for now
Datadog.logger.error(
"Custom getter #{getter} is not supported. Please inform the `datadog` team at " \
' https://github.com/DataDog/dd-trace-rb of your use case so we can best support you. Using the default ' \
Expand Down
21 changes: 13 additions & 8 deletions lib/datadog/tracing/contrib/action_cable/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ module Instrumentation
module ActionCableConnection
def on_open
Tracing.trace(Ext::SPAN_ON_OPEN) do |span, trace|
span.resource = "#{self.class}#on_open"
span.type = Tracing::Metadata::Ext::AppTypes::TYPE_WEB
begin
span.resource = "#{self.class}#on_open"
span.type = Tracing::Metadata::Ext::AppTypes::TYPE_WEB

span.set_tag(Ext::TAG_ACTION, 'on_open')
span.set_tag(Ext::TAG_CONNECTION, self.class.to_s)
span.set_tag(Ext::TAG_ACTION, 'on_open')
span.set_tag(Ext::TAG_CONNECTION, self.class.to_s)

span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ON_OPEN)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ON_OPEN)

# Set the resource name of the trace
trace.resource = span.resource
# Set the resource name of the trace
trace.resource = span.resource
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error("Error preparing span for ActionCable::Connection: #{e}")
end

super
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def start_processing(payload)
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_CONTROLLER)
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down Expand Up @@ -82,6 +83,7 @@ def finish_processing(payload)
span.finish
end
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative '../../configuration/resolver'
require_relative 'makara_resolver'
require_relative '../../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -74,11 +73,11 @@ def resolve(db_config)
# `db_config` input may contain sensitive information such as passwords,
# hence provide a succinct summary for the error logging.
#
# TODO: Report Telemetry logs
Datadog.logger.error(
'Failed to resolve ActiveRecord database configuration. '\
"Cause: #{e.class.name} Source: #{Array(e.backtrace).first}"
)
Core::Telemetry::Logger.report(e, description: 'Failed to resolve ActiveRecord database configuration')

nil
end
Expand All @@ -94,11 +93,11 @@ def parse_matcher(matcher)

normalized
rescue => e
# TODO: Report Telemetry logs
Datadog.logger.error(
"Failed to resolve key #{matcher.inspect}. " \
"Cause: #{e.class.name} Source: #{Array(e.backtrace).first}"
)
Core::Telemetry::Logger.report(e, description: 'Failed to resolve key')

nil
end
Expand Down
3 changes: 1 addition & 2 deletions lib/datadog/tracing/contrib/elasticsearch/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ def perform_request(*args)
span.resource = "#{method} #{quantized_url}"
Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
# TODO: Refactor the code to streamline the execution without ensure
# TODO: Refactor the code to avoid calling `super` in the `ensure` block
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
ensure
# the call is still executed
response = super

if response && response.respond_to?(:status)
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, response.status)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/tracing/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def endpoint_start_process(_name, _start, _finish, _id, payload)

Thread.current[KEY_RUN] = true
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down Expand Up @@ -108,6 +109,7 @@ def endpoint_run(name, start, finish, id, payload)
span.finish(finish)
end
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down Expand Up @@ -152,6 +154,7 @@ def endpoint_start_render(*)

Thread.current[KEY_RENDER] = true
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand All @@ -177,6 +180,7 @@ def endpoint_render(name, start, finish, id, payload)
span.finish(finish)
end
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down Expand Up @@ -216,6 +220,7 @@ def endpoint_run_filters(name, start, finish, id, payload)
span.finish(finish)
end
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
Expand Down
9 changes: 6 additions & 3 deletions lib/datadog/tracing/contrib/httpclient/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require_relative '../http'
require_relative '../analytics'
require_relative '../http_annotation_helper'
require_relative '../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -37,8 +36,8 @@ def do_get_block(req, proxy, conn, &block)
# Add additional request specific tags to the span.
annotate_span_with_request!(span, req, request_options)
rescue StandardError => e
Datadog.logger.error("error preparing span for httpclient request: #{e}, Source: #{e.backtrace}")
Datadog::Core::Telemetry::Logger.report(e)
# TODO: Report Telemetry logs
logger.error("error preparing span for httpclient request: #{e}, Source: #{e.backtrace}")
ensure
res = super
end
Expand Down Expand Up @@ -116,6 +115,10 @@ def analytics_enabled?(request_options)
Contrib::Analytics.enabled?(request_options[:analytics_enabled])
end

def logger
Datadog.logger
end

def should_skip_distributed_tracing?(client_config)
return !client_config[:distributed_tracing] if client_config && client_config.key?(:distributed_tracing)

Expand Down
16 changes: 15 additions & 1 deletion lib/datadog/tracing/contrib/httpclient/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ module Httpclient
module Patcher
include Contrib::Patcher

PATCH_ONLY_ONCE = Core::Utils::OnlyOnce.new

module_function

def patched?
PATCH_ONLY_ONCE.ran?
end

def target_version
Integration.version
end

# patch applies our patch
def patch
::HTTPClient.include(Instrumentation)
# TODO: Refactor to remove redundancy
PATCH_ONLY_ONCE.run do
begin
::HTTPClient.include(Instrumentation)
rescue StandardError => e
Datadog.logger.error("Unable to apply httpclient integration: #{e}")
end
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/httprb/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def perform(req, options)
# Add additional request specific tags to the span.
annotate_span_with_request!(span, req, request_options)
rescue StandardError => e
# TODO: Report Telemetry logs
logger.error("error preparing span for http.rb request: #{e}, Source: #{e.backtrace}")
Datadog::Core::Telemetry::Logger.report(e)
ensure
Expand Down
16 changes: 15 additions & 1 deletion lib/datadog/tracing/contrib/httprb/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ module Httprb
module Patcher
include Contrib::Patcher

PATCH_ONLY_ONCE = Core::Utils::OnlyOnce.new

module_function

def patched?
PATCH_ONLY_ONCE.ran?
end

def target_version
Integration.version
end

# patch applies our patch
def patch
::HTTP::Client.include(Instrumentation)
# TODO: Refactor to remove redundancy
PATCH_ONLY_ONCE.run do
begin
::HTTP::Client.include(Instrumentation)
rescue StandardError => e
Datadog.logger.error("Unable to apply httprb integration: #{e}")
end
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/tracing/contrib/lograge/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def patch
if defined?(::ActiveSupport::TaggedLogging::Formatter) &&
::Lograge::LogSubscribers::ActionController
.logger&.formatter.is_a?(::ActiveSupport::TaggedLogging::Formatter)
Datadog.logger.warn(
# TODO: Change to warn
Datadog.logger.error(
'Lograge and ActiveSupport::TaggedLogging (the default Rails log formatter) are not compatible: ' \
'Lograge does not account for Rails log tags, creating polluted logs and breaking log formatting. ' \
'Traces and Logs correlation may not work. ' \
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/tracing/contrib/opensearch/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def perform_request(method, path, params = {}, body = nil, headers = nil)
span.resource = "#{method} #{quantized_url}"
Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
# TODO: Refactor the code to streamline the execution without ensure
Expand Down
Loading

0 comments on commit d9aa760

Please sign in to comment.