Skip to content

Commit

Permalink
Merge branch 'master' into tonycthsu/remove-obsolete-test
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu authored Sep 26, 2024
2 parents 1e95090 + 7cfcefb commit 4466958
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-memory-leaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: latest
cache-version: v1 # bump this to invalidate cache
- run: sudo apt update && sudo apt install -y valgrind && valgrind --version
- run: sudo apt-get update && (sudo apt-get install -y valgrind || sleep 5 && sudo apt-get install -y valgrind) && valgrind --version
- run: bundle exec rake compile spec:profiling:memcheck
test-asan:
# Temporarily disabled on 2024-09-17 until ruby-asan builds are available again on
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ end

group :check do
if RUBY_VERSION >= '3.0.0' && RUBY_PLATFORM != 'java'
gem 'rbs', '~> 3.2.0', require: false
gem 'steep', '~> 1.6.0', require: false
gem 'rbs', '~> 3.5.0', require: false
gem 'steep', '~> 1.7.0', require: false
end
gem 'ruby_memcheck', '>= 3' if RUBY_VERSION >= '3.4.0' && RUBY_PLATFORM != 'java'
gem 'standard', require: false
Expand Down
4 changes: 4 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ target :datadog do

ignore 'lib/datadog/appsec.rb'
ignore 'lib/datadog/appsec/component.rb'
# Excluded due to https://github.com/soutaro/steep/issues/1232
ignore 'lib/datadog/appsec/configuration/settings.rb'
ignore 'lib/datadog/appsec/contrib/'
ignore 'lib/datadog/appsec/contrib/auto_instrument.rb'
ignore 'lib/datadog/appsec/contrib/integration.rb'
Expand Down Expand Up @@ -69,6 +71,8 @@ target :datadog do
ignore 'lib/datadog/core/metrics/options.rb'
ignore 'lib/datadog/core/pin.rb'
ignore 'lib/datadog/core/rate_limiter.rb'
# steep fails in this file due to https://github.com/soutaro/steep/issues/1231
ignore 'lib/datadog/core/remote/tie.rb'
ignore 'lib/datadog/core/runtime/ext.rb'
ignore 'lib/datadog/core/runtime/metrics.rb'
ignore 'lib/datadog/core/transport/ext.rb'
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/jruby_9.2_elasticsearch_latest.gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gemfiles/jruby_9.2_opensearch_latest.gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gemfiles/ruby_2.5_elasticsearch_latest.gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gemfiles/ruby_2.5_opensearch_latest.gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,33 @@ def initialize(*_)
end
end

# The monotonic clock time provider used by Datadog. This option is internal and is used by `datadog-ci`
# gem to avoid traces' durations being skewed by timecop.
#
# It must respect the interface of [Datadog::Core::Utils::Time#get_time] method.
#
# For [Timecop](https://rubygems.org/gems/timecop), for example,
# `->(unit = :float_second) { ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }`
# allows Datadog features to use the real monotonic time when time is frozen with
# `Timecop.mock_process_clock = true`.
#
# @default `->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit)}`
# @return [Proc<Numeric>]
option :get_time_provider do |o|
o.default_proc { |unit = :float_second| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }
o.type :proc

o.after_set do |get_time_provider|
Core::Utils::Time.get_time_provider = get_time_provider
end

o.resetter do |_value|
->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }.tap do |default|
Core::Utils::Time.get_time_provider = default
end
end
end

# The `version` tag in Datadog. Use it to enable [Deployment Tracking](https://docs.datadoghq.com/tracing/deployment_tracking/).
# @see https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
# @default `DD_VERSION` environment variable, otherwise `nils`
Expand Down
10 changes: 5 additions & 5 deletions lib/datadog/core/environment/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def development?
# 2. Checking if `Net::HTTP` is referring to the original one
# => ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP)
def webmock_enabled?
defined?(::WebMock::HttpLibAdapters::NetHttpAdapter) &&
!!(defined?(::WebMock::HttpLibAdapters::NetHttpAdapter) &&
defined?(::Net::HTTP) &&
::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP)))
end

private
Expand Down Expand Up @@ -68,7 +68,7 @@ def minitest?

# Check if we are running from `bin/cucumber` or `cucumber/rake/task`.
def cucumber?
defined?(::Cucumber::Cli)
!!defined?(::Cucumber::Cli)
end

# If this is a Rails application, use different heuristics to detect
Expand All @@ -80,7 +80,7 @@ def rails_development?
# detecting its presence is enough to deduct if this is a development environment.
#
# @see https://github.com/rails/spring/blob/48b299348ace2188444489a0c216a6f3e9687281/README.md?plain=1#L204-L207
defined?(::Spring) || rails_env_development?
!!defined?(::Spring) || rails_env_development?
end

RAILS_ENV_DEVELOPMENT = Set['development', 'test'].freeze
Expand All @@ -94,7 +94,7 @@ def rails_development?
# it's common to have a custom "staging" environment, and such environment normally want to run as close
# to production as possible.
def rails_env_development?
defined?(::Rails.env) && RAILS_ENV_DEVELOPMENT.include?(::Rails.env)
!!defined?(::Rails.env) && RAILS_ENV_DEVELOPMENT.include?(::Rails.env)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/remote/tie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def self.boot
barrier = Datadog::Core::Remote.active_remote.barrier(:once)
end

# steep does not permit the next line due to
# https://github.com/soutaro/steep/issues/1231
Boot.new(barrier, t)
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/datadog/core/utils/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def now_provider=(block)
define_singleton_method(:now, &block)
end

# Overrides the implementation of `#get_time
# with the provided callable.
#
# Overriding the method `#get_time` instead of
# indirectly calling `block` removes
# one level of method call overhead.
#
# @param block [Proc] block that accepts unit and returns timestamp in the requested unit
def get_time_provider=(block)
define_singleton_method(:get_time, &block)
end

def measure(unit = :float_second)
before = get_time(unit)
yield
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../../analytics'
require_relative '../ext'
require_relative '../event'
require_relative '../../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -48,7 +49,8 @@ def on_start(span, event, _id, payload)
span.set_tag(Ext::TAG_INSTANTIATION_CLASS_NAME, payload.fetch(:class_name))
span.set_tag(Ext::TAG_INSTANTIATION_RECORD_COUNT, payload.fetch(:record_count))
rescue StandardError => e
Datadog.logger.debug(e.message)
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/tracing/contrib/active_record/events/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require_relative '../ext'
require_relative '../../analytics'
require_relative '../../utils/database'
require_relative '../../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -68,7 +69,8 @@ def on_start(span, event, _id, payload)
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, config[:host]) if config[:host]
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, config[:port]) if config[:port]
rescue StandardError => e
Datadog.logger.debug(e.message)
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative '../../ext'
require_relative '../event'
require_relative '../../../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -64,7 +65,7 @@ def on_start(span, event, _id, payload)
key = payload[:key]
store = payload[:store]

mapping = MAPPING[event]
mapping = MAPPING.fetch(event)

span.service = configuration[:cache_service]
span.resource = mapping[:resource]
Expand All @@ -81,6 +82,9 @@ def on_start(span, event, _id, payload)
span.set_tag('EVENT', event)

set_cache_key(span, key, mapping[:multi_key])
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end

def set_cache_key(span, key, multi_key)
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/tracing/contrib/aws/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call(context)
private

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def annotate!(span, context)
span.service = configuration[:service_name]
span.type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
Expand Down Expand Up @@ -76,7 +77,11 @@ def annotate!(span, context)
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, context.safely(:status_code))

Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

def configuration
Expand Down
9 changes: 9 additions & 0 deletions lib/datadog/tracing/contrib/faraday/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_relative '../analytics'
require_relative 'ext'
require_relative '../http_annotation_helper'
require_relative '../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -37,6 +38,7 @@ def call(env)

attr_reader :app

# rubocop:disable Metrics/AbcSize
def annotate!(span, env, options)
span.resource = resource_name(env)
span.service = service_name(env[:url].host, options)
Expand Down Expand Up @@ -75,7 +77,11 @@ def annotate!(span, env, options)
)

Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end
# rubocop:enable Metrics/AbcSize

def handle_response(span, env, options)
span.set_error(["Error #{env[:status]}", env[:body]]) if options[:error_status_codes].include? env[:status]
Expand All @@ -85,6 +91,9 @@ def handle_response(span, env, options)
span.set_tags(
Datadog.configuration.tracing.header_tags.response_tags(env[:response_headers])
)
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end

def propagate!(trace, span, env)
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/tracing/contrib/httpclient/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def annotate_span_with_response!(span, response, request_options)
span.set_tags(
Datadog.configuration.tracing.header_tags.response_tags(response.header)
)
rescue StandardError => e
Datadog.logger.error("error preparing span from httpclient response: #{e}, Source: #{e.backtrace}")
Datadog::Core::Telemetry::Logger.report(e)
end

def annotate_span_with_error!(span, error)
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/tracing/contrib/httprb/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def annotate_span_with_response!(span, response, request_options)
span.set_tags(
Datadog.configuration.tracing.header_tags.response_tags(response.headers)
)
rescue StandardError => e
logger.error("error preparing span from http.rb response: #{e}, Source: #{e.backtrace}")
Datadog::Core::Telemetry::Logger.report(e)
end

def annotate_span_with_error!(span, error)
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/tracing/contrib/mongodb/subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def started(event)

# set the resource with the quantized query
span.resource = serialized_query
rescue StandardError => e
Datadog.logger.debug("error when handling MongoDB 'started' event: #{e}")
end
# rubocop:enable Metrics/AbcSize

Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/tracing/contrib/redis/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../analytics'
require_relative 'ext'
require_relative '../ext'
require_relative '../../../core/telemetry/logger'

module Datadog
module Tracing
Expand Down Expand Up @@ -45,6 +46,9 @@ def set_common_tags(client, span, raw_command)
span.set_tag Ext::TAG_RAW_COMMAND, raw_command

Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
end

private
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/core/remote/tie.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module Datadog
module Core
module Remote
module Tie
class Boot < ::Struct[untyped]
class Boot < ::Struct[[Component::Barrier, Numeric]]
def initialize: (Component::Barrier? barrier, Numeric? time) -> void

attr_reader barrier: Component::Barrier
attr_reader time: Numeric
end

def self.boot: () -> (nil | Boot)
def self.boot: () -> Boot?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/core/telemetry/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Datadog

def agent_transport: (untyped config) -> String

def conf_value: (String name, Object value, Integer seq_id, ?String origin) -> Hash[Symbol, untyped]
def conf_value: (String name, untyped value, Integer seq_id, ?String origin) -> Hash[Symbol, untyped]

def to_value: (Object value) -> Object

Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core/utils/time.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Datadog
def self?.get_time: (?::Symbol unit) -> ::Numeric
def self?.now: () -> ::Time
def self?.now_provider=: (^() -> ::Time block) -> void
def self?.get_time_provider=: (^(?::Symbol unit) -> ::Numeric block) -> void
def self?.measure: (?::Symbol unit) { () -> void } -> ::Numeric
def self?.as_utc_epoch_ns: (::Time time) -> ::Integer
end
Expand Down
Loading

0 comments on commit 4466958

Please sign in to comment.