Skip to content
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

Move Tracing diagnostic code from Core to Tracing #2453

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/datadog/core/configuration/ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# typed: true

module Datadog
module Core
module Configuration
module Ext
# @public_api
module Diagnostics
ENV_DEBUG_ENABLED = 'DD_TRACE_DEBUG'.freeze
ENV_HEALTH_METRICS_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze
ENV_STARTUP_LOGS_ENABLED = 'DD_TRACE_STARTUP_LOGS'.freeze
end
end
end
end
end
10 changes: 5 additions & 5 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'logger'

require_relative 'base'
require_relative 'ext'
require_relative '../environment/ext'
require_relative '../runtime/ext'
require_relative '../telemetry/ext'
Expand Down Expand Up @@ -99,7 +100,7 @@ def initialize(*_)
# @default `DD_TRACE_DEBUG` environment variable, otherwise `false`
# @return [Boolean]
option :debug do |o|
o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG, false) }
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) }
o.lazy
o.on_set do |enabled|
# Enable rich debug print statements.
Expand All @@ -110,15 +111,14 @@ def initialize(*_)

# Internal {Datadog::Statsd} metrics collection.
#
# The list of metrics collected can be found in {Datadog::Core::Diagnostics::Ext::Health::Metrics}.
# @public_api
settings :health_metrics do
# Enable health metrics collection.
#
# @default `DD_HEALTH_METRICS_ENABLED` environment variable, otherwise `false`
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED, false) }
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) }
o.lazy
end

Expand All @@ -144,7 +144,7 @@ def initialize(*_)
# @return [Boolean,nil]
option :enabled do |o|
# Defaults to nil as we want to know when the default value is being used
o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_STARTUP_LOGS, nil) }
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) }
o.lazy
end
end
Expand Down Expand Up @@ -490,7 +490,7 @@ def initialize(*_)
# @default `DD_TRACE_ENABLED` environment variable, otherwise `true`
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED, true) }
o.default { env_to_bool(Tracing::Configuration::Ext::ENV_ENABLED, true) }
o.lazy
end

Expand Down
26 changes: 4 additions & 22 deletions lib/datadog/core/diagnostics/health.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: strict
# typed: ignore

require_relative 'ext'
require_relative '../metrics/client'
require_relative '../../tracing/diagnostics/health'

module Datadog
module Core
Expand All @@ -10,26 +10,8 @@ module Diagnostics
module Health
# Health metrics for diagnostics
class Metrics < Core::Metrics::Client
count :api_errors, Ext::Health::Metrics::METRIC_API_ERRORS
count :api_requests, Ext::Health::Metrics::METRIC_API_REQUESTS
count :api_responses, Ext::Health::Metrics::METRIC_API_RESPONSES
count :error_context_overflow, Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
count :error_instrumentation_patch, Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
count :error_span_finish, Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
count :error_unfinished_spans, Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
count :instrumentation_patched, Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
count :queue_accepted, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
count :queue_accepted_lengths, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
count :queue_dropped, Ext::Health::Metrics::METRIC_QUEUE_DROPPED
count :traces_filtered, Ext::Health::Metrics::METRIC_TRACES_FILTERED
count :transport_trace_too_large, Ext::Health::Metrics::METRIC_TRANSPORT_TRACE_TOO_LARGE
count :transport_chunked, Ext::Health::Metrics::METRIC_TRANSPORT_CHUNKED
count :writer_cpu_time, Ext::Health::Metrics::METRIC_WRITER_CPU_TIME

gauge :queue_length, Ext::Health::Metrics::METRIC_QUEUE_LENGTH
gauge :queue_max_length, Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
gauge :queue_spans, Ext::Health::Metrics::METRIC_QUEUE_SPANS
gauge :sampling_service_cache_length, Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
# TODO: Don't reference this. Have tracing add its metrics behavior.
extend Tracing::Diagnostics::Health::Metrics
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/tracing/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Datadog
module Tracing
module Configuration
module Ext
ENV_ENABLED = 'DD_TRACE_ENABLED'.freeze

# @public_api
module Analytics
ENV_TRACE_ANALYTICS_ENABLED = 'DD_TRACE_ANALYTICS_ENABLED'.freeze
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# typed: true

module Datadog
module Core
module Tracing
module Diagnostics
# @public_api
module Ext
DD_TRACE_STARTUP_LOGS = 'DD_TRACE_STARTUP_LOGS'.freeze
DD_TRACE_DEBUG = 'DD_TRACE_DEBUG'.freeze
DD_TRACE_ENABLED = 'DD_TRACE_ENABLED'.freeze
# Health
module Health
# Metrics
module Metrics
ENV_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze

METRIC_API_ERRORS = 'datadog.tracer.api.errors'.freeze
METRIC_API_REQUESTS = 'datadog.tracer.api.requests'.freeze
METRIC_API_RESPONSES = 'datadog.tracer.api.responses'.freeze
Expand Down
40 changes: 40 additions & 0 deletions lib/datadog/tracing/diagnostics/health.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# typed: ignore

require_relative 'ext'

module Datadog
module Tracing
module Diagnostics
# Health-related diagnostics
module Health
# Health metrics for diagnostics
module Metrics
def self.extended(base)
base.class_eval do
count :api_errors, Ext::Health::Metrics::METRIC_API_ERRORS
count :api_requests, Ext::Health::Metrics::METRIC_API_REQUESTS
count :api_responses, Ext::Health::Metrics::METRIC_API_RESPONSES
count :error_context_overflow, Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
count :error_instrumentation_patch, Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
count :error_span_finish, Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
count :error_unfinished_spans, Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
count :instrumentation_patched, Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
count :queue_accepted, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
count :queue_accepted_lengths, Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
count :queue_dropped, Ext::Health::Metrics::METRIC_QUEUE_DROPPED
count :traces_filtered, Ext::Health::Metrics::METRIC_TRACES_FILTERED
count :transport_trace_too_large, Ext::Health::Metrics::METRIC_TRANSPORT_TRACE_TOO_LARGE
count :transport_chunked, Ext::Health::Metrics::METRIC_TRANSPORT_CHUNKED
count :writer_cpu_time, Ext::Health::Metrics::METRIC_WRITER_CPU_TIME

gauge :queue_length, Ext::Health::Metrics::METRIC_QUEUE_LENGTH
gauge :queue_max_length, Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
gauge :queue_spans, Ext::Health::Metrics::METRIC_QUEUE_SPANS
gauge :sampling_service_cache_length, Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
end
end
end
end
end
end
end
15 changes: 8 additions & 7 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require 'logger'

require 'datadog/core/configuration/settings'
require 'datadog/core/diagnostics/ext'
require 'datadog/core/environment/ext'
require 'datadog/core/runtime/ext'
require 'datadog/core/utils/time'
Expand Down Expand Up @@ -64,9 +63,9 @@

it { is_expected.to be false }

context "when #{Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG}" do
context "when #{Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::DD_TRACE_DEBUG => environment) do
ClimateControl.modify(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED => environment) do
example.run
end
end
Expand Down Expand Up @@ -121,9 +120,11 @@
describe '#enabled' do
subject(:enabled) { settings.diagnostics.health_metrics.enabled }

context "when #{Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED}" do
context "when #{Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::Health::Metrics::ENV_ENABLED => environment) do
ClimateControl.modify(
Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED => environment
) do
example.run
end
end
Expand Down Expand Up @@ -1074,9 +1075,9 @@

it { is_expected.to be true }

context "when #{Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED}" do
context "when #{Datadog::Tracing::Configuration::Ext::ENV_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::Core::Diagnostics::Ext::DD_TRACE_ENABLED => enable) do
ClimateControl.modify(Datadog::Tracing::Configuration::Ext::ENV_ENABLED => enable) do
example.run
end
end
Expand Down
46 changes: 0 additions & 46 deletions spec/datadog/core/diagnostics/health_spec.rb

This file was deleted.

50 changes: 50 additions & 0 deletions spec/datadog/tracing/diagnostics/health_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# typed: ignore

require 'spec_helper'
require 'ddtrace'
require 'datadog/core/diagnostics/health'
require 'datadog/tracing/diagnostics/health'

RSpec.describe Datadog::Tracing::Diagnostics::Health::Metrics do
# TODO: Core::Health::Metrics directly extends Tracing::Health::Metrics
# In the future, have tracing add this behavior itself. For now,
# just use the core metrics class to drive the tests.
subject(:health_metrics) { Datadog::Core::Diagnostics::Health::Metrics.new }

shared_examples_for 'a health metric' do |type, name, stat|
subject(:health_metric) { health_metrics.send(name, *args, &block) }

let(:args) { [1] }
let(:block) { proc {} }

it 'sends a measurement of the designated type' do
expect(health_metrics).to receive(type) do |*received_args, &received_block|
expect(received_args).to eq([stat, *args])
expect(received_block).to be block
end

health_metric
end
end

# rubocop:disable Layout/LineLength
it_behaves_like 'a health metric', :count, :api_errors, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_API_ERRORS
it_behaves_like 'a health metric', :count, :api_requests, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_API_REQUESTS
it_behaves_like 'a health metric', :count, :api_responses, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_API_RESPONSES
it_behaves_like 'a health metric', :count, :error_context_overflow, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_CONTEXT_OVERFLOW
it_behaves_like 'a health metric', :count, :error_instrumentation_patch, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_INSTRUMENTATION_PATCH
it_behaves_like 'a health metric', :count, :error_span_finish, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_SPAN_FINISH
it_behaves_like 'a health metric', :count, :error_unfinished_spans, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_ERROR_UNFINISHED_SPANS
it_behaves_like 'a health metric', :count, :instrumentation_patched, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_INSTRUMENTATION_PATCHED
it_behaves_like 'a health metric', :count, :queue_accepted, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED
it_behaves_like 'a health metric', :count, :queue_accepted_lengths, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_ACCEPTED_LENGTHS
it_behaves_like 'a health metric', :count, :queue_dropped, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_DROPPED
it_behaves_like 'a health metric', :count, :traces_filtered, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_TRACES_FILTERED
it_behaves_like 'a health metric', :count, :writer_cpu_time, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_WRITER_CPU_TIME

it_behaves_like 'a health metric', :gauge, :queue_length, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_max_length, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_MAX_LENGTH
it_behaves_like 'a health metric', :gauge, :queue_spans, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_QUEUE_SPANS
it_behaves_like 'a health metric', :gauge, :sampling_service_cache_length, Datadog::Tracing::Diagnostics::Ext::Health::Metrics::METRIC_SAMPLING_SERVICE_CACHE_LENGTH
# rubocop:enable Layout/LineLength
end
Loading