Skip to content

Commit

Permalink
Make net/http conditional cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Oct 10, 2022
1 parent ff707e3 commit ea75bc7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions sentry-ruby/lib/sentry/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ module HTTP
def request(req, body = nil, &block)
return super unless started?

if Sentry.configuration.instrumenter == :sentry
sentry_span = start_sentry_span
set_sentry_trace_header(req, sentry_span)
else
set_sentry_trace_header(req, Sentry.get_current_scope.get_span)
end
sentry_span = start_sentry_span
set_sentry_trace_header(req, sentry_span)

super.tap do |res|
record_sentry_breadcrumb(req, res)
Expand All @@ -44,14 +40,16 @@ def request(req, body = nil, &block)
private

def set_sentry_trace_header(req, sentry_span)
return unless sentry_span
# TODO-neel maybe some otel span validation
sentry_or_otel_span = sentry_span || Sentry.get_current_scope.get_span
return unless sentry_or_otel_span

client = Sentry.get_current_client

trace = client.generate_sentry_trace(sentry_span)
trace = client.generate_sentry_trace(sentry_or_otel_span)
req[SENTRY_TRACE_HEADER_NAME] = trace if trace

baggage = client.generate_baggage(sentry_span)
baggage = client.generate_baggage(sentry_or_otel_span)
req[BAGGAGE_HEADER_NAME] = baggage if baggage && !baggage.empty?
end

Expand Down Expand Up @@ -83,8 +81,11 @@ def record_sentry_span(req, res, sentry_span)
end

def start_sentry_span
return unless Sentry.initialized? && span = Sentry.get_current_scope.get_span
return unless Sentry.initialized?
return unless Sentry.configuration.instrumenter == :sentry
return if from_sentry_sdk?

span = Sentry.get_current_scope.get_span
return if span.sampled == false

span.start_child(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f)
Expand Down

0 comments on commit ea75bc7

Please sign in to comment.