Module: ElasticAPM::Spies::HTTPSpy::Ext Private

Defined in:
lib/elastic_apm/spies/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.

Instance Method Summary collapse

Instance Method Details

#perform(req, options) ⇒ 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.



30
31
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
57
58
59
60
61
62
63
# File 'lib/elastic_apm/spies/http.rb', line 30

def perform(req, options)
  unless (transaction = ElasticAPM.current_transaction)
    return super(req, options)
  end

  method = req.verb.to_s.upcase
  host = req.uri.host

  context = ElasticAPM::Span::Context.new(
    http: { url: req.uri, method: method },
    destination: ElasticAPM::Span::Context::Destination.from_uri(req.uri, type: SUBTYPE)
  )

  name = "#{method} #{host}"

  ElasticAPM.with_span(
    name,
    TYPE,
    subtype: SUBTYPE,
    context: context
  ) do |span|
    trace_context = span&.trace_context || transaction.trace_context
    trace_context.apply_headers { |key, value| req[key] = value }

    result = super(req, options)

    if (http = span&.context&.http)
      http.status_code = result.status.to_s
    end

    span&.outcome = Span::Outcome.from_http_status(result.status)
    result
  end
end