diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index fb619adcb..11c2ce3bd 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -243,6 +243,11 @@ def capture_exception_frame_locals=(value) # @return [Boolean] attr_accessor :auto_session_tracking + # Allowlist of outgoing request targets to which sentry-trace and baggage headers are attached. + # Default is all (/.*/) + # @return [Array] + attr_accessor :trace_propagation_targets + # The instrumenter to use, :sentry or :otel # @return [Symbol] attr_reader :instrumenter @@ -290,6 +295,8 @@ def capture_exception_frame_locals=(value) INSTRUMENTERS = [:sentry, :otel] + PROPAGATION_TARGETS_MATCH_ALL = /.*/.freeze + class << self # Post initialization callbacks are called at the end of initialization process # allowing extending the configuration of sentry-ruby by multiple extensions @@ -332,6 +339,7 @@ def initialize self.dsn = ENV['SENTRY_DSN'] self.server_name = server_name_from_env self.instrumenter = :sentry + self.trace_propagation_targets = [PROPAGATION_TARGETS_MATCH_ALL] self.before_send = nil self.before_send_transaction = nil diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index 470d1a796..3c8c3d469 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -53,6 +53,8 @@ def set_sentry_trace_header(req, sentry_span) return unless sentry_span client = Sentry.get_current_client + return unless client + return unless propagate_trace?(client.configuration.trace_propagation_targets) trace = client.generate_sentry_trace(sentry_span) req[SENTRY_TRACE_HEADER_NAME] = trace if trace @@ -96,6 +98,10 @@ def extract_request_info(req) result end + + def propagate_trace?(trace_propagation_targets) + trace_propagation_targets.any? { |target| address.match?(target) } + end end end end