Module: Sentry::Net::HTTP Private

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"
"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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sentry/net/http.rb', line 28

def request(req, body = nil, &block)
  return super unless started?

  sentry_span = start_sentry_span
  set_sentry_trace_header(req, sentry_span)

  super.tap do |res|
    record_sentry_breadcrumb(req, res)
    record_sentry_span(req, res, sentry_span)
  end
end