From 35bdeb2220d737895bfd3d08d387483615b8fbed Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Thu, 4 Jan 2024 15:04:21 +0100 Subject: [PATCH 01/12] Add `on_error` for grape --- .../contrib/grape/configuration/settings.rb | 18 +++- lib/datadog/tracing/contrib/grape/endpoint.rb | 32 +++--- lib/datadog/tracing/contrib/grape/ext.rb | 1 + .../grape/configuration/settings_spec.rb | 7 ++ .../tracing/contrib/grape/tracer_spec.rb | 101 +++--------------- 5 files changed, 56 insertions(+), 103 deletions(-) create mode 100644 spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb diff --git a/lib/datadog/tracing/contrib/grape/configuration/settings.rb b/lib/datadog/tracing/contrib/grape/configuration/settings.rb index a571896a797..22ef8ed8d2e 100644 --- a/lib/datadog/tracing/contrib/grape/configuration/settings.rb +++ b/lib/datadog/tracing/contrib/grape/configuration/settings.rb @@ -2,7 +2,8 @@ require_relative '../../configuration/settings' require_relative '../ext' -require_relative '../../status_code_matcher' +require_relative '../../status_range_matcher' +require_relative '../../status_range_env_parser' module Datadog module Tracing @@ -31,9 +32,18 @@ class Settings < Contrib::Configuration::Settings option :service_name - option :error_statuses, default: nil do |o| - o.setter do |new_value, _old_value| - Contrib::StatusCodeMatcher.new(new_value) unless new_value.nil? + option :on_error do |o| + o.type :proc, nilable: true + end + + option :error_status_codes do |o| + o.env Ext::ENV_ERROR_STATUS_CODES + o.default 500...600 + o.setter do |v| + Tracing::Contrib::StatusRangeMatcher.new(v) if v + end + o.env_parser do |v| + Tracing::Contrib::StatusRangeEnvParser.call(v) if v end end end diff --git a/lib/datadog/tracing/contrib/grape/endpoint.rb b/lib/datadog/tracing/contrib/grape/endpoint.rb index 3231b853074..523b7c772f4 100644 --- a/lib/datadog/tracing/contrib/grape/endpoint.rb +++ b/lib/datadog/tracing/contrib/grape/endpoint.rb @@ -91,8 +91,7 @@ def endpoint_run(name, start, finish, id, payload) Contrib::Analytics.set_measured(span) # catch thrown exceptions - - span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object]) + handle_error(span, payload[:exception_object]) if payload[:exception_object] # override the current span with this notification values span.set_tag(Ext::TAG_ROUTE_ENDPOINT, api_view) unless api_view.nil? @@ -143,7 +142,7 @@ def endpoint_render(name, start, finish, id, payload) # Measure service stats Contrib::Analytics.set_measured(span) - span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object]) + handle_error(span, payload[:exception_object]) if payload[:exception_object] ensure span.start(start) span.finish(finish) @@ -179,7 +178,7 @@ def endpoint_run_filters(name, start, finish, id, payload) Contrib::Analytics.set_measured(span) # catch thrown exceptions - span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object]) + handle_error(span, payload[:exception_object]) if payload[:exception_object] span.set_tag(Ext::TAG_FILTER_TYPE, type.to_s) ensure @@ -192,6 +191,22 @@ def endpoint_run_filters(name, start, finish, id, payload) private + def handle_error(span, exception) + if exception.respond_to?('status') + span.set_error(exception) if error_status_codes.include?(exception.status) + else + on_error.call(span, exception) + end + end + + def error_status_codes + datadog_configuration[:error_status_codes] + end + + def on_error + datadog_configuration[:on_error] || Tracing::SpanOperation::Events::DEFAULT_ON_ERROR + end + def api_view(api) # If the API inherits from Grape::API in version >= 1.2.0 # then the API will be an instance and the name must be derived from the base. @@ -223,15 +238,6 @@ def analytics_sample_rate datadog_configuration[:analytics_sample_rate] end - def exception_is_error?(exception) - matcher = datadog_configuration[:error_statuses] - return false unless exception - return true unless matcher - return true unless exception.respond_to?('status') - - matcher.include?(exception.status) - end - def enabled? Datadog.configuration.tracing.enabled && \ datadog_configuration[:enabled] == true diff --git a/lib/datadog/tracing/contrib/grape/ext.rb b/lib/datadog/tracing/contrib/grape/ext.rb index 9b40352e890..e15d624e4b5 100644 --- a/lib/datadog/tracing/contrib/grape/ext.rb +++ b/lib/datadog/tracing/contrib/grape/ext.rb @@ -10,6 +10,7 @@ module Ext ENV_ENABLED = 'DD_TRACE_GRAPE_ENABLED' ENV_ANALYTICS_ENABLED = 'DD_TRACE_GRAPE_ANALYTICS_ENABLED' ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_GRAPE_ANALYTICS_SAMPLE_RATE' + ENV_ERROR_STATUS_CODES = 'DD_TRACE_GRAPE_ERROR_STATUS_CODES' SPAN_ENDPOINT_RENDER = 'grape.endpoint_render' SPAN_ENDPOINT_RUN = 'grape.endpoint_run' SPAN_ENDPOINT_RUN_FILTERS = 'grape.endpoint_run_filters' diff --git a/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb new file mode 100644 index 00000000000..fb7a40eecb7 --- /dev/null +++ b/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb @@ -0,0 +1,7 @@ +require 'datadog/tracing/contrib/grape/configuration/settings' +require 'datadog/tracing/contrib/shared_settings_examples' + +RSpec.describe Datadog::Tracing::Contrib::Grape::Configuration::Settings do + # it_behaves_like 'with on_error setting' + # it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_GRAPE_ERROR_STATUS_CODES' +end diff --git a/spec/datadog/tracing/contrib/grape/tracer_spec.rb b/spec/datadog/tracing/contrib/grape/tracer_spec.rb index 27752dbd3f5..f6530bc80f6 100644 --- a/spec/datadog/tracing/contrib/grape/tracer_spec.rb +++ b/spec/datadog/tracing/contrib/grape/tracer_spec.rb @@ -259,92 +259,24 @@ it 'handles exceptions' do expect(response.body).to eq('405 Not Allowed') - expect(spans.length).to eq(1) - expect(spans[0].name).to eq('grape.endpoint_run') - expect(spans[0].status).to eq(1) - expect(spans[0].get_tag('error.stack')).to_not be_nil - expect(spans[0].get_tag('error.type')).to_not be_nil - expect(spans[0].get_tag('error.message')).to_not be_nil, - "DEV: 🚧 Flaky test! Please send the maintainers a link for this CI failure. Thank you! 🚧\n" \ - "response=#{response.inspect}\n" \ - "spans=#{spans.inspect}\n" - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) + expect(span.name).to eq('grape.endpoint_run') + expect(span).to_not have_error + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq('endpoint_run') end context 'and error_responses' do subject(:response) { post '/base/hard_failure' } - let(:configuration_options) { { error_statuses: '300-399,,xxx-xxx,1111,400-499' } } + let(:configuration_options) { { error_status_codes: [400...600] } } it 'handles exceptions' do expect(response.body).to eq('405 Not Allowed') - expect(spans.length).to eq(1) - expect(spans[0].name).to eq('grape.endpoint_run') - expect(spans[0].status).to eq(1) - expect(spans[0].get_tag('error.stack')).to_not be_nil - expect(spans[0].get_tag('error.type')).to_not be_nil - expect(spans[0].get_tag('error.message')).to_not be_nil - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) - .to eq('endpoint_run') - end - end - - context 'and error_responses with arrays' do - subject(:response) { post '/base/hard_failure' } - - let(:configuration_options) { { error_statuses: ['300-399', 'xxx-xxx', 1111, 405] } } - - it 'handles exceptions' do - expect(response.body).to eq('405 Not Allowed') - expect(spans.length).to eq(1) - expect(spans[0].name).to eq('grape.endpoint_run') - expect(spans[0].status).to eq(1) - expect(spans[0].get_tag('error.stack')).to_not be_nil - expect(spans[0].get_tag('error.type')).to_not be_nil - expect(spans[0].get_tag('error.message')).to_not be_nil - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) - .to eq('endpoint_run') - end - end - - context 'and error_responses with arrays that dont contain exception status' do - subject(:response) { post '/base/hard_failure' } - - let(:configuration_options) { { error_statuses: ['300-399', 'xxx-xxx', 1111, 406] } } - - it 'handles exceptions' do - expect(response.body).to eq('405 Not Allowed') - expect(spans.length).to eq(1) - expect(spans[0].name).to eq('grape.endpoint_run') - expect(spans[0]).to_not have_error - expect(spans[0].get_tag('error.stack')).to be_nil - expect(spans[0].get_tag('error.type')).to be_nil - expect(spans[0].get_tag('error.message')).to be_nil - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) - .to eq('endpoint_run') - end - end - - context 'defaults to >=500 when provided invalid config' do - subject(:response) { post '/base/hard_failure' } - - let(:configuration_options) { { error_statuses: 'xxx-499' } } - - it 'handles exceptions' do - expect(response.body).to eq('405 Not Allowed') - expect(spans.length).to eq(1) - expect(spans[0].name).to eq('grape.endpoint_run') - expect(spans[0].status).to eq(0) - expect(spans[0].get_tag('error.stack')).to be_nil - expect(spans[0].get_tag('error.type')).to be_nil - expect(spans[0].get_tag('error.message')).to be_nil - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') - expect(spans[0].get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) + expect(span.name).to eq('grape.endpoint_run') + expect(span).to have_error + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT)).to eq('grape') + expect(span.get_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION)) .to eq('endpoint_run') end end @@ -753,16 +685,13 @@ it 'does not impact the Rack integration that must work as usual' do expect(subject.status).to eq(404) - expect(spans.length).to eq(1) - rack_span = spans[0] - - expect(rack_span.name).to eq('rack.request') - expect(rack_span.span_type).to eq('web') - expect(rack_span.service).to eq(tracer.default_service) - expect(rack_span.resource).to eq('GET 404') - expect(rack_span).to_not have_error - expect(rack_span).to be_root_span + expect(span.name).to eq('rack.request') + expect(span.span_type).to eq('web') + expect(span.service).to eq(tracer.default_service) + expect(span.resource).to eq('GET 404') + expect(span).to_not have_error + expect(span).to be_root_span end end From a7405cd74286b7322eb283176c8de5c52eb54494 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Thu, 4 Jan 2024 18:04:48 +0100 Subject: [PATCH 02/12] Remove obsolete status code matcher --- .../tracing/contrib/status_code_matcher.rb | 72 ------------------- lib/datadog/tracing/metadata/ext.rb | 1 - .../tracing/contrib/status_code_matcher.rbs | 23 ------ .../contrib/status_code_matcher_spec.rb | 40 ----------- 4 files changed, 136 deletions(-) delete mode 100644 lib/datadog/tracing/contrib/status_code_matcher.rb delete mode 100644 sig/datadog/tracing/contrib/status_code_matcher.rbs delete mode 100644 spec/datadog/tracing/contrib/status_code_matcher_spec.rb diff --git a/lib/datadog/tracing/contrib/status_code_matcher.rb b/lib/datadog/tracing/contrib/status_code_matcher.rb deleted file mode 100644 index a568ef6be65..00000000000 --- a/lib/datadog/tracing/contrib/status_code_matcher.rb +++ /dev/null @@ -1,72 +0,0 @@ -require 'set' - -require_relative '../metadata/ext' - -module Datadog - module Tracing - module Contrib - # Contains methods helpful for tracing/annotating HTTP request libraries - class StatusCodeMatcher - REGEX_PARSER = /^\d{3}(?:-\d{3})?(?:,\d{3}(?:-\d{3})?)*$/.freeze - - def initialize(range) - @error_response_range = range - set_range - end - - def include?(exception_status) - set_range.include?(exception_status) - end - - def to_s - @error_response_range.to_s - end - - private - - def set_range - @datadog_set ||= begin - set = Set.new - handle_statuses.each do |statuses| - status = statuses.to_s.split('-') - case status.length - when 1 - set.add(Integer(status[0])) - when 2 - min, max = status.minmax - Array(min..max).each do |i| - set.add(Integer(i)) - end - end - end - set - end - @datadog_set - end - - def error_responses - return @error_response_range if @error_response_range.is_a?(String) && !@error_response_range.nil? - - @error_response_range.join(',') if @error_response_range.is_a?(Array) && !@error_response_range.empty? - end - - def handle_statuses - if error_responses - filter_error_responses = error_responses.gsub(/\s+/, '').split(',').select do |code| - if !code.to_s.match(REGEX_PARSER) - Datadog.logger.debug("Invalid config provided: #{code}. Must be formatted like '400-403,405,410-499'.") - next - else - true - end - end - filter_error_responses.empty? ? Tracing::Metadata::Ext::HTTP::ERROR_RANGE.to_a : filter_error_responses - else - Datadog.logger.debug('No valid config was provided for :error_statuses - falling back to default.') - Tracing::Metadata::Ext::HTTP::ERROR_RANGE.to_a - end - end - end - end - end -end diff --git a/lib/datadog/tracing/metadata/ext.rb b/lib/datadog/tracing/metadata/ext.rb index e8d2a6f0ed2..c93088f58df 100644 --- a/lib/datadog/tracing/metadata/ext.rb +++ b/lib/datadog/tracing/metadata/ext.rb @@ -74,7 +74,6 @@ module Errors # @public_api module HTTP - ERROR_RANGE = (500...600).freeze TAG_BASE_URL = 'http.base_url' TAG_METHOD = 'http.method' TAG_STATUS_CODE = 'http.status_code' diff --git a/sig/datadog/tracing/contrib/status_code_matcher.rbs b/sig/datadog/tracing/contrib/status_code_matcher.rbs deleted file mode 100644 index e97cda48246..00000000000 --- a/sig/datadog/tracing/contrib/status_code_matcher.rbs +++ /dev/null @@ -1,23 +0,0 @@ -module Datadog - module Tracing - module Contrib - class StatusCodeMatcher - REGEX_PARSER: ::Regexp - - def initialize: (untyped range) -> void - - def include?: (untyped exception_status) -> untyped - - def to_s: () -> untyped - - private - - def set_range: () -> untyped - - def error_responses: () -> untyped - - def handle_statuses: () -> untyped - end - end - end -end diff --git a/spec/datadog/tracing/contrib/status_code_matcher_spec.rb b/spec/datadog/tracing/contrib/status_code_matcher_spec.rb deleted file mode 100644 index 7508c0c3870..00000000000 --- a/spec/datadog/tracing/contrib/status_code_matcher_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'datadog/tracing/contrib/status_code_matcher' - -RSpec.describe Datadog::Tracing::Contrib::StatusCodeMatcher do - describe '#include?' do - context 'when given a string to parse' do - it do - matcher = described_class.new('400') - - expect(matcher).to include 400 - end - - it do - matcher = described_class.new('400,500') - - expect(matcher).to include 400 - expect(matcher).not_to include 499 - expect(matcher).to include 500 - expect(matcher).not_to include 599 - end - - it do - matcher = described_class.new('400-500') - - expect(matcher).to include 400 - expect(matcher).to include 499 - expect(matcher).to include 500 - expect(matcher).not_to include 599 - end - - it do - matcher = described_class.new('400-404,500') - - expect(matcher).to include 400 - expect(matcher).not_to include 499 - expect(matcher).to include 500 - expect(matcher).not_to include 599 - end - end - end -end From e0fd1926a34e1d2b5ba9860691a0ff46cfcf2e24 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Mon, 8 Jan 2024 20:42:44 +0100 Subject: [PATCH 03/12] Enable settings spec --- .../contrib/excon/configuration/settings_spec.rb | 2 +- .../contrib/faraday/configuration/settings_spec.rb | 2 +- .../contrib/grape/configuration/settings_spec.rb | 4 ++-- .../contrib/http/configuration/settings_spec.rb | 2 +- .../contrib/httpclient/configuration/settings_spec.rb | 2 +- .../contrib/httprb/configuration/settings_spec.rb | 2 +- .../tracing/contrib/shared_settings_examples.rb | 11 +++++------ 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/spec/datadog/tracing/contrib/excon/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/excon/configuration/settings_spec.rb index ba36e0526e5..2959f1abd30 100644 --- a/spec/datadog/tracing/contrib/excon/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/excon/configuration/settings_spec.rb @@ -5,5 +5,5 @@ RSpec.describe Datadog::Tracing::Contrib::Excon::Configuration::Settings do it_behaves_like 'service name setting', 'excon' it_behaves_like 'with on_error setting' - it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_EXCON_ERROR_STATUS_CODES' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_EXCON_ERROR_STATUS_CODES', default: 400...600 end diff --git a/spec/datadog/tracing/contrib/faraday/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/faraday/configuration/settings_spec.rb index 07a5f8a3a44..d425c50b729 100644 --- a/spec/datadog/tracing/contrib/faraday/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/faraday/configuration/settings_spec.rb @@ -5,5 +5,5 @@ RSpec.describe Datadog::Tracing::Contrib::Faraday::Configuration::Settings do it_behaves_like 'service name setting', 'faraday' it_behaves_like 'with on_error setting' - it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_FARADAY_ERROR_STATUS_CODES' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_FARADAY_ERROR_STATUS_CODES', default: 400...600 end diff --git a/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb index fb7a40eecb7..481d619ca42 100644 --- a/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/grape/configuration/settings_spec.rb @@ -2,6 +2,6 @@ require 'datadog/tracing/contrib/shared_settings_examples' RSpec.describe Datadog::Tracing::Contrib::Grape::Configuration::Settings do - # it_behaves_like 'with on_error setting' - # it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_GRAPE_ERROR_STATUS_CODES' + it_behaves_like 'with on_error setting' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_GRAPE_ERROR_STATUS_CODES', default: 500...600 end diff --git a/spec/datadog/tracing/contrib/http/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/http/configuration/settings_spec.rb index 8e428368185..ade0151aa1b 100644 --- a/spec/datadog/tracing/contrib/http/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/http/configuration/settings_spec.rb @@ -4,5 +4,5 @@ RSpec.describe Datadog::Tracing::Contrib::HTTP::Configuration::Settings do it_behaves_like 'service name setting', 'net/http' - it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTP_ERROR_STATUS_CODES' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTP_ERROR_STATUS_CODES', default: 400...600 end diff --git a/spec/datadog/tracing/contrib/httpclient/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/httpclient/configuration/settings_spec.rb index 9d8b9521092..5644183b640 100644 --- a/spec/datadog/tracing/contrib/httpclient/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/httpclient/configuration/settings_spec.rb @@ -4,5 +4,5 @@ RSpec.describe Datadog::Tracing::Contrib::Httpclient::Configuration::Settings do it_behaves_like 'service name setting', 'httpclient' - it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES', default: 400...600 end diff --git a/spec/datadog/tracing/contrib/httprb/configuration/settings_spec.rb b/spec/datadog/tracing/contrib/httprb/configuration/settings_spec.rb index a2561f56a8d..1283619843d 100644 --- a/spec/datadog/tracing/contrib/httprb/configuration/settings_spec.rb +++ b/spec/datadog/tracing/contrib/httprb/configuration/settings_spec.rb @@ -4,5 +4,5 @@ RSpec.describe Datadog::Tracing::Contrib::Httprb::Configuration::Settings do it_behaves_like 'service name setting', 'httprb' - it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTPRB_ERROR_STATUS_CODES' + it_behaves_like 'with error_status_codes setting', env: 'DD_TRACE_HTTPRB_ERROR_STATUS_CODES', default: 400...600 end diff --git a/spec/datadog/tracing/contrib/shared_settings_examples.rb b/spec/datadog/tracing/contrib/shared_settings_examples.rb index 59dc6838203..0e22fdb0e60 100644 --- a/spec/datadog/tracing/contrib/shared_settings_examples.rb +++ b/spec/datadog/tracing/contrib/shared_settings_examples.rb @@ -28,15 +28,14 @@ end end -RSpec.shared_examples_for 'with error_status_codes setting' do |env:| +RSpec.shared_examples_for 'with error_status_codes setting' do |env:, default:| context 'default without settings' do subject { described_class.new } - it { expect(subject.error_status_codes).to include 400 } - it { expect(subject.error_status_codes).to include 499 } - it { expect(subject.error_status_codes).to include 500 } - it { expect(subject.error_status_codes).to include 599 } - it { expect(subject.error_status_codes).not_to include 600 } + it { expect(subject.error_status_codes).not_to include(default.min - 1) } + it { expect(subject.error_status_codes).to include(default.min) } + it { expect(subject.error_status_codes).to include(default.max) } + it { expect(subject.error_status_codes).not_to include(default.max + 1) } end context 'when given error_status_codes' do From d6fd673d6515ac5459f2b83a3520c10f64af24c5 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Mon, 8 Jan 2024 21:29:11 +0100 Subject: [PATCH 04/12] Update doc --- docs/GettingStarted.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index b7680039093..1220d252a54 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -728,7 +728,7 @@ connection.get | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | | `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | -| `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | Range or Array of HTTP status codes that should be traced as errors.| `400...600` | +| `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | **Configuring connections to use different settings** @@ -792,8 +792,8 @@ connection.get('/foo') | `peer_service` | `DD_TRACE_FARADAY_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | -| `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | Range or Array of HTTP status codes that should be traced as errors.| `400...600` | +| `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |**default: 400...600** +| `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### Grape @@ -824,7 +824,7 @@ end | Key | Env Var | Description | Default | |------------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------| | `enabled` | `DD_TRACE_GRAPE_ENABLED` | Defines whether Grape should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | -| `error_statuses` | | Defines a status code or range of status codes which should be marked as errors. `'404,405,500-599'` or `[404,405,'500-599']` | `nil` | +| `error_status_codes` | `DD_TRACE_GRAPE_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `500...600` | ### GraphQL @@ -997,8 +997,7 @@ end | `peer_service` | `DD_TRACE_HTTPRB_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTPRB_ERROR_STATUS_CODES` | Range or Array of HTTP status codes that should be traced as errors. | `400...600` | - +| `error_status_codes` | `DD_TRACE_HTTPRB_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### httpclient @@ -1025,7 +1024,7 @@ end | `peer_service` | `DD_TRACE_HTTPCLIENT_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES` | Range or Array of HTTP status codes that should be traced as errors. | `400...600` | +| `error_status_codes` | `DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### httpx @@ -1181,7 +1180,7 @@ content = Net::HTTP.get(URI('http://127.0.0.1/index.html')) | `peer_service` | `DD_TRACE_NET_HTTP_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTP_ERROR_STATUS_CODES` | Range or Array of HTTP status codes that should be traced as errors. | `400...600` | +| `error_status_codes` | `DD_TRACE_HTTP_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | If you wish to configure each connection object individually, you may use the `Datadog.configure_onto` as it follows: From 2e17696bc1799dd5d3ceb6532656f7840df1cda1 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Mon, 8 Jan 2024 21:41:51 +0100 Subject: [PATCH 05/12] Add `ERROR_RANGE` constant back --- lib/datadog/tracing/metadata/ext.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/datadog/tracing/metadata/ext.rb b/lib/datadog/tracing/metadata/ext.rb index c93088f58df..e8d2a6f0ed2 100644 --- a/lib/datadog/tracing/metadata/ext.rb +++ b/lib/datadog/tracing/metadata/ext.rb @@ -74,6 +74,7 @@ module Errors # @public_api module HTTP + ERROR_RANGE = (500...600).freeze TAG_BASE_URL = 'http.base_url' TAG_METHOD = 'http.method' TAG_STATUS_CODE = 'http.status_code' From 6a4677da0f1468bd68d23b0e478327cf6af0f1bb Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:09 +0100 Subject: [PATCH 06/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 1220d252a54..87d2233ba58 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -728,7 +728,7 @@ connection.get | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | | `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | -| `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | +| `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | **Configuring connections to use different settings** From 2d8a6529c1a662676884fa6b588887a8adadedb3 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:14 +0100 Subject: [PATCH 07/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 87d2233ba58..51e896fedef 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -793,7 +793,7 @@ connection.get('/foo') | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | | `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |**default: 400...600** -| `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | +| `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### Grape From c64f05fc389154d4864e2bf27ea4e15d324f9ad7 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:22 +0100 Subject: [PATCH 08/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 51e896fedef..752bf8c9774 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -824,7 +824,7 @@ end | Key | Env Var | Description | Default | |------------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------| | `enabled` | `DD_TRACE_GRAPE_ENABLED` | Defines whether Grape should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | -| `error_status_codes` | `DD_TRACE_GRAPE_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `500...600` | +| `error_status_codes` | `DD_TRACE_GRAPE_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `500...600` | ### GraphQL From 6869cdb02e3a163e2c5245f971802bc04d7639cb Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:32 +0100 Subject: [PATCH 09/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 752bf8c9774..8bdcab45029 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -997,7 +997,7 @@ end | `peer_service` | `DD_TRACE_HTTPRB_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTPRB_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | +| `error_status_codes` | `DD_TRACE_HTTPRB_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### httpclient From 160e7a7c1243402b316ce4ad830b0c5c4f369e5d Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:39 +0100 Subject: [PATCH 10/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8bdcab45029..490b87bb1f1 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -1024,7 +1024,7 @@ end | `peer_service` | `DD_TRACE_HTTPCLIENT_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | +| `error_status_codes` | `DD_TRACE_HTTPCLIENT_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### httpx From a8a0a4fa1d77f213cc2cb58b71758e93807dd9a4 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Wed, 10 Jan 2024 13:35:50 +0100 Subject: [PATCH 11/12] Update docs/GettingStarted.md Co-authored-by: Brett Blue <84536271+brett0000FF@users.noreply.github.com> --- docs/GettingStarted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 490b87bb1f1..3077a338e9a 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -1180,7 +1180,7 @@ content = Net::HTTP.get(URI('http://127.0.0.1/index.html')) | `peer_service` | `DD_TRACE_NET_HTTP_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `error_status_codes` | `DD_TRACE_HTTP_ERROR_STATUS_CODES` | Defines HTTP status codes that would be traced as errors. Value could be a range(`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | +| `error_status_codes` | `DD_TRACE_HTTP_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | If you wish to configure each connection object individually, you may use the `Datadog.configure_onto` as it follows: From 94b086cdb1a4e5f7ad5f7ecee7772cc4d5110d1e Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Wed, 10 Jan 2024 13:56:58 +0100 Subject: [PATCH 12/12] Fix doc style --- docs/GettingStarted.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 3077a338e9a..a333fd2e3f0 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -727,7 +727,7 @@ connection.get | `peer_service` | `DD_TRACE_EXCON_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` || Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | | `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | @@ -792,7 +792,7 @@ connection.get('/foo') | `peer_service` | `DD_TRACE_FARADAY_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |**default: 400...600** +| `on_error` || Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by deault. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` |**default: 400...600** | `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### Grape @@ -1241,7 +1241,7 @@ end | `service_name` | `DD_TRACE_PG_SERVICE_NAME` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See *Additional Configuration* for more details](#additional-configuration) | `pg` | | `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | Name of external service the application connects to | `nil` | | `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: *Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database.* | `'disabled'` | -| `on_error` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` || Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Presto