Skip to content

Commit

Permalink
Add new trace_propagation_targets configuration to set outgoing targe…
Browse files Browse the repository at this point in the history
…ts for trace header propagation
  • Loading branch information
sl0thentr0py committed Jul 27, 2023
1 parent 94a4895 commit f9c5c8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Regexp>]
attr_accessor :trace_propagation_targets

# The instrumenter to use, :sentry or :otel
# @return [Symbol]
attr_reader :instrumenter
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/lib/sentry/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 57 in sentry-ruby/lib/sentry/net/http.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/net/http.rb#L56-L57

Added lines #L56 - L57 were not covered by tests

trace = client.generate_sentry_trace(sentry_span)
req[SENTRY_TRACE_HEADER_NAME] = trace if trace
Expand Down Expand Up @@ -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) }

Check warning on line 103 in sentry-ruby/lib/sentry/net/http.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/net/http.rb#L103

Added line #L103 was not covered by tests
end
end
end
end
Expand Down

0 comments on commit f9c5c8c

Please sign in to comment.