Module: Sentry::Net::HTTP Private

Includes:
Utils::HttpTracing
Defined in:
lib/sentry/net/http.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

OP_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"http.client"
SPAN_ORIGIN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"auto.http.net_http"
"net.http"

Instance Method Summary collapse

Instance Method Details

#request(req, body = nil, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

To explain how the entire thing works, we need to know how the original Net::HTTP#request works Here’s part of its definition. As you can see, it usually calls itself inside a #start block

“‘ def request(req, body = nil, &block)

unless started?
  start {
    req['connection'] ||= 'close'
    return request(req, body, &block) # <- request will be called for the second time from the first call
  }
end # .....

end “‘

So we’re only instrumenting request when ‘Net::HTTP` is already started



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sentry/net/http.rb', line 32

def request(req, body = nil, &block)
  return super unless started? && Sentry.initialized?
  return super if from_sentry_sdk?

  Sentry.with_child_span(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f, origin: SPAN_ORIGIN) do |sentry_span|
    request_info = extract_request_info(req)

    if propagate_trace?(request_info[:url])
      set_propagation_headers(req)
    end

    res = super
    response_status = res.code.to_i

    if record_sentry_breadcrumb?
      record_sentry_breadcrumb(request_info, response_status)
    end

    if sentry_span
      set_span_info(sentry_span, request_info, response_status)
    end

    res
  end
end