diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb52ec0d..ccc9825e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,21 @@ config.trace_propagation_targets = [/.*/] # default is to all targets config.trace_propagation_targets = [/example.com/, 'foobar.org/api/v2'] ``` +- Tracing without Performance + - Implement `PropagationContext` on `Scope` and add `Sentry.get_trace_propagation_headers` API [#2084](https://github.com/getsentry/sentry-ruby/pull/2084) + + The SDK now supports connecting arbitrary events (Errors / Transactions / Replays) across distributed services and not just Transactions. + To continue an incoming trace starting with this version of the SDK, use `Sentry.continue_trace` as follows. + + ```rb + # rack application + def call(env) + transaction = Sentry.continue_trace(env, name: 'transaction', op: 'op') + Sentry.start_transaction(transaction: transaction) + end + ``` + + To inject headers into outgoing requests, use `Sentry.get_trace_propagation_headers` to get a hash of headers to add to your request. ## 5.10.0 diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index af6e12aa6..04eedb290 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -31,7 +31,10 @@ def request(req, body = nil, &block) Sentry.with_child_span(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f) do |sentry_span| request_info = extract_request_info(req) - set_propagation_headers(req, request_info) + + if propagate_trace?(request_info[:url], Sentry.configuration.trace_propagation_targets) + set_propagation_headers(req) + end super.tap do |res| record_sentry_breadcrumb(request_info, res) @@ -49,10 +52,7 @@ def request(req, body = nil, &block) private - def set_propagation_headers(req, request_info) - client = Sentry.get_current_client - return unless propagate_trace?(request_info[:url], client.configuration.trace_propagation_targets) - + def set_propagation_headers(req) Sentry.get_trace_propagation_headers&.each { |k, v| req[k] = v } end