Skip to content

Commit

Permalink
Implement
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Sep 11, 2024
1 parent 02a46e8 commit 6d6e114
Show file tree
Hide file tree
Showing 35 changed files with 143 additions and 152 deletions.
3 changes: 2 additions & 1 deletion lib/datadog/core/environment/cgroup.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'ext'
require_relative '../telemetry/logger'

module Datadog
module Core
Expand Down Expand Up @@ -33,10 +34,10 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Error while parsing cgroup')
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/datadog/core/environment/container.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'cgroup'
require_relative '../telemetry/logger'

module Datadog
module Core
Expand Down Expand Up @@ -35,6 +36,7 @@ def task_uid
descriptor.task_uid
end

# rubocop:disable Metrics/MethodLength
def descriptor
@descriptor ||= Descriptor.new.tap do |descriptor|
begin
Expand Down Expand Up @@ -78,14 +80,15 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Error while parsing container info')
end
end
end
# rubocop:enable Metrics/MethodLength
end
end
end
Expand Down
12 changes: 7 additions & 5 deletions lib/datadog/core/metrics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative '../utils/time'
require_relative '../utils/only_once'
require_relative '../telemetry/logger'
require_relative '../configuration/ext'

require_relative 'ext'
Expand Down Expand Up @@ -97,10 +98,10 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Failed to send count stat')
end

def distribution(stat, value = nil, options = nil, &block)
Expand All @@ -111,10 +112,10 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Failed to send distribution stat')
end

def increment(stat, options = nil)
Expand All @@ -124,10 +125,10 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Failed to send increment stat')
end

def gauge(stat, value = nil, options = nil, &block)
Expand All @@ -138,10 +139,10 @@ 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}"
)
Telemetry::Logger.report(e, description: 'Failed to send gauge stat')
end

def time(stat, options = nil)
Expand All @@ -157,10 +158,11 @@ def time(stat, options = nil)
distribution(stat, ((finished - start) * 1000), options)
end
rescue StandardError => e
# TODO: add telemetry logs
# TODO: Likely to be redundant, since `distribution` handles its own errors.
Datadog.logger.error(
"Failed to send time stat. Cause: #{e.class.name} #{e.message} Source: #{Array(e.backtrace).first}"
)
Telemetry::Logger.report(e, description: 'Failed to send time stat')
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/core/remote/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(settings, capabilities, agent_settings)
@client.sync
@healthy ||= true
rescue Client::SyncError => e
# Not sure
# PENDING: Not sure about sending telemetry log
Datadog.logger.error do
"remote worker client sync error: #{e.message} location: #{Array(e.backtrace).first}. skipping sync"
end
Expand All @@ -49,7 +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
# PENDING: Not sure about sending telemetry log
Datadog.logger.error do
"remote worker error: #{e.class.name} #{e.message} location: #{Array(e.backtrace).first}. "\
'reseting client state'
Expand Down
12 changes: 4 additions & 8 deletions lib/datadog/core/remote/negotiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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}" }
Datadog.logger.warn { "agent unreachable: cannot negotiate #{path}" }
@logged[:agent_unreachable] = true
end

Expand All @@ -30,8 +29,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}" }
Datadog.logger.warn { "agent reachable but has no /info endpoint: cannot negotiate #{path}" }
@logged[:no_info_endpoint] = true
end

Expand All @@ -41,8 +39,7 @@ 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}" }
Datadog.logger.warn { "agent reachable but unexpected response: cannot negotiate #{path}" }
@logged[:unexpected_response] = true
end

Expand All @@ -52,8 +49,7 @@ 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}" }
Datadog.logger.warn { "agent reachable but does not report #{path}" }
@logged[:no_config_endpoint] = true
end

Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/core/telemetry/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require_relative '../utils/forking'
require_relative '../utils/sequence'

module Datadog
module Core
module Telemetry
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/opentelemetry/sdk/propagator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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
# PENDING: 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 @@ -32,7 +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
# PENDING: 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: 8 additions & 13 deletions lib/datadog/tracing/contrib/action_cable/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ module Instrumentation
module ActionCableConnection
def on_open
Tracing.trace(Ext::SPAN_ON_OPEN) do |span, trace|
begin
span.resource = "#{self.class}#on_open"
span.type = Tracing::Metadata::Ext::AppTypes::TYPE_WEB
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
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error("Error preparing span for ActionCable::Connection: #{e}")
end
# Set the resource name of the trace
trace.resource = span.resource

super
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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 @@ -83,7 +82,6 @@ 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,6 +2,7 @@

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

module Datadog
module Tracing
Expand Down Expand Up @@ -73,11 +74,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 @@ -93,11 +94,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: 2 additions & 1 deletion lib/datadog/tracing/contrib/elasticsearch/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ 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 avoid calling `super` in the `ensure` block
# TODO: Refactor the code to streamline the execution without ensure
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: 0 additions & 5 deletions lib/datadog/tracing/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ 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 @@ -109,7 +108,6 @@ 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 @@ -154,7 +152,6 @@ 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 @@ -180,7 +177,6 @@ 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 @@ -220,7 +216,6 @@ 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: 3 additions & 6 deletions lib/datadog/tracing/contrib/httpclient/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../http'
require_relative '../analytics'
require_relative '../http_annotation_helper'
require_relative '../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -36,8 +37,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
# TODO: Report Telemetry logs
logger.error("error preparing span for httpclient request: #{e}, Source: #{e.backtrace}")
Datadog.logger.error("error preparing span for httpclient request: #{e}, Source: #{e.backtrace}")
Datadog::Core::Telemetry::Logger.report(e)
ensure
res = super
end
Expand Down Expand Up @@ -115,10 +116,6 @@ 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
Loading

0 comments on commit 6d6e114

Please sign in to comment.