Class: NewRelic::Agent::Transaction::RequestAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/transaction/request_attributes.rb

Constant Summary collapse

HTTP_ACCEPT_HEADER_KEY =
'HTTP_ACCEPT'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestAttributes

Returns a new instance of RequestAttributes.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 16

def initialize(request)
  @request_path = path_from_request(request)
  @referer = referer_from_request(request)
  @accept = attribute_from_env(request, HTTP_ACCEPT_HEADER_KEY)
  @content_length = content_length_from_request(request)
  @content_type = attribute_from_request(request, :content_type)
  @host = attribute_from_request(request, :host)
  @port = port_from_request(request)
  @user_agent = attribute_from_request(request, :user_agent)
  @request_method = attribute_from_request(request, :request_method)
end

Instance Attribute Details

#acceptObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def accept
  @accept
end

#content_lengthObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def content_length
  @content_length
end

#content_typeObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def content_type
  @content_type
end

#hostObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def host
  @host
end

#portObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def port
  @port
end

#refererObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def referer
  @referer
end

#request_methodObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def request_method
  @request_method
end

#request_pathObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def request_path
  @request_path
end

#user_agentObject (readonly)



11
12
13
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 11

def user_agent
  @user_agent
end

Instance Method Details

#assign_agent_attributes(txn) ⇒ Object



28
29
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
64
65
66
67
# File 'lib/new_relic/agent/transaction/request_attributes.rb', line 28

def assign_agent_attributes(txn)
  default_destinations = AttributeFilter::DST_TRANSACTION_TRACER |
    AttributeFilter::DST_TRANSACTION_EVENTS |
    AttributeFilter::DST_ERROR_COLLECTOR

  if referer
    txn.add_agent_attribute(:'request.headers.referer', referer, AttributeFilter::DST_ERROR_COLLECTOR)
  end

  if request_path
    txn.add_agent_attribute(:'request.uri',
      request_path,
      AttributeFilter::DST_TRANSACTION_TRACER |
        AttributeFilter::DST_ERROR_COLLECTOR)
  end

  if accept
    txn.add_agent_attribute(:'request.headers.accept', accept, default_destinations)
  end

  if content_length
    txn.add_agent_attribute(:'request.headers.contentLength', content_length, default_destinations)
  end

  if content_type
    txn.add_agent_attribute(:'request.headers.contentType', content_type, default_destinations)
  end

  if host
    txn.add_agent_attribute(:'request.headers.host', host, default_destinations)
  end

  if user_agent
    txn.add_agent_attribute(:'request.headers.userAgent', user_agent, default_destinations)
  end

  if request_method
    txn.add_agent_attribute(:'request.method', request_method, default_destinations)
  end
end