Skip to content

Commit

Permalink
Implement
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Aug 23, 2024
1 parent 55b082b commit 906fa14
Show file tree
Hide file tree
Showing 42 changed files with 229 additions and 204 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/logging'

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::Logging.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/logging'

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::Logging.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/logging'
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::Logging.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::Logging.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::Logging.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::Logging.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::Logging.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
2 changes: 1 addition & 1 deletion lib/datadog/core/telemetry/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Telemetry
module Logging
extend self

def report(exception, level:, description: nil)
def report(exception, level: :error, description: nil)
# Annoymous exceptions to be logged as <Class:0x00007f8b1c0b3b40>
message = +''
message << (exception.class.name || exception.class.inspect)
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 @@ -7,6 +7,7 @@
require_relative '../utils'
require_relative '../../rack/middlewares'
require_relative '../../analytics'
require_relative '../../../../core/telemetry/logging'

module Datadog
module Tracing
Expand Down Expand Up @@ -42,8 +43,8 @@ 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::Logging.report(e)
end

def finish_processing(payload)
Expand Down Expand Up @@ -81,8 +82,8 @@ def finish_processing(payload)
span.finish
end
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logging.report(e)
end

# Instrumentation for ActionController::Metal
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/logging'

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::Logging.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::Logging.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,8 +93,9 @@ def perform_request(*args)
span.resource = "#{method} #{quantized_url}"
Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
# TODO: Not to report telemetry logs now, refactor the code to avoid calling `super` in the `ensure` block
# TODO: Refactor the code to avoid calling `super` in the `ensure` block
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logging.report(e)
ensure
# the call is still executed
response = super
Expand Down
11 changes: 6 additions & 5 deletions lib/datadog/tracing/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative '../../../core'
require_relative '../../../core/telemetry/logging'
require_relative '../../metadata/ext'
require_relative '../analytics'
require_relative '../rack/ext'
Expand Down Expand Up @@ -63,8 +64,8 @@ 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::Logging.report(e)
end

def endpoint_run(name, start, finish, id, payload)
Expand Down Expand Up @@ -107,8 +108,8 @@ 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::Logging.report(e)
end

# Status code resolution is tied to the exception handling
Expand Down Expand Up @@ -151,8 +152,8 @@ def endpoint_start_render(*)

Thread.current[KEY_RENDER] = true
rescue StandardError => e
# TODO: Report Telelemetry log
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logging.report(e)
end

def endpoint_render(name, start, finish, id, payload)
Expand All @@ -176,8 +177,8 @@ 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::Logging.report(e)
end

def endpoint_run_filters(name, start, finish, id, payload)
Expand Down Expand Up @@ -215,8 +216,8 @@ 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::Logging.report(e)
end

private
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/tracing/contrib/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require_relative '../analytics'
require_relative '../http_annotation_helper'
require_relative '../utils/quantization/http'
require_relative '../../../core/telemetry/logging'

module Datadog
module Tracing
Expand Down Expand Up @@ -42,8 +43,8 @@ def request(req, body = nil, &block)
# Add additional request specific tags to the span.
annotate_span_with_request!(span, req, request_options)
rescue StandardError => e
# TODO: Report Telemetry logs
Datadog.logger.error("error preparing span for http request: #{e}")
Datadog::Core::Telemetry::Logging.report(e)
ensure
response = super(req, body, &block)
end
Expand Down
Loading

0 comments on commit 906fa14

Please sign in to comment.