Class: NewRelic::Agent::TransactionInfo

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

Constant Summary collapse

DEFAULT_TRANSACTION_NAME =
'(unknown)'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ TransactionInfo

Returns a new instance of TransactionInfo.



12
13
14
15
16
17
# File 'lib/new_relic/agent/transaction_info.rb', line 12

def initialize
  @guid = ""
  @transaction_name = nil
  @start_time = Time.now
  @ignore_end_user = false
end

Instance Attribute Details

#capture_deep_tt ⇒ Object

Returns the value of attribute capture_deep_tt.



8
9
10
# File 'lib/new_relic/agent/transaction_info.rb', line 8

def capture_deep_tt
  @capture_deep_tt
end

#start_time ⇒ Object (readonly)

Returns the value of attribute start_time.



10
11
12
# File 'lib/new_relic/agent/transaction_info.rb', line 10

def start_time
  @start_time
end

#token ⇒ Object

Returns the value of attribute token.



8
9
10
# File 'lib/new_relic/agent/transaction_info.rb', line 8

def token
  @token
end

#transaction_name ⇒ Object



23
24
25
# File 'lib/new_relic/agent/transaction_info.rb', line 23

def transaction_name
  @transaction_name || DEFAULT_TRANSACTION_NAME
end

Class Method Details

.clear ⇒ Object



78
79
80
# File 'lib/new_relic/agent/transaction_info.rb', line 78

def self.clear
  Thread.current[:newrelic_transaction_info] = nil
end

.get ⇒ Object



70
71
72
# File 'lib/new_relic/agent/transaction_info.rb', line 70

def self.get()
  Thread.current[:newrelic_transaction_info] ||= TransactionInfo.new
end

.get_token(request) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/new_relic/agent/transaction_info.rb', line 90

def self.get_token(request)
  return nil unless request

  agent_flag = request.cookies['NRAGENT']
  if agent_flag and agent_flag.instance_of? String
    s = agent_flag.split("=")
    if s.length == 2
      if s[0] == "tk" && s[1]
        ERB::Util.h(sanitize_token(s[1]))
      end
    end
  else
    nil
  end
end

.reset(request = nil) ⇒ Object

clears any existing transaction info object and initializes a new one. This starts the timer for the transaction.



84
85
86
87
88
# File 'lib/new_relic/agent/transaction_info.rb', line 84

def self.reset(request=nil)
  clear
  instance = get
  instance.token = get_token(request)
end

.sanitize_token(token) ⇒ Object

Run through a collection of unsafe characters ( in the context of the token ) and set the token to an empty string if any of them are found in the token so that potential XSS attacks via the token are avoided



109
110
111
112
113
114
115
# File 'lib/new_relic/agent/transaction_info.rb', line 109

def self.sanitize_token(token)

  if ( /[<>'"]/ =~ token )
    token.replace("")
  end
  token
end

.set(instance) ⇒ Object



74
75
76
# File 'lib/new_relic/agent/transaction_info.rb', line 74

def self.set(instance)
  Thread.current[:newrelic_transaction_info] = instance
end

Instance Method Details

#apdex_t ⇒ Object



55
56
57
58
59
# File 'lib/new_relic/agent/transaction_info.rb', line 55

def apdex_t
  (Agent.config[:web_transactions_apdex] &&
   Agent.config[:web_transactions_apdex][@transaction_name]) ||
    Agent.config[:apdex_t]
end

#duration ⇒ Object



43
44
45
# File 'lib/new_relic/agent/transaction_info.rb', line 43

def duration
  Time.now - start_time
end

#force_persist_sample?(sample) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/new_relic/agent/transaction_info.rb', line 27

def force_persist_sample?(sample)
  token && sample.duration > Agent.config[:apdex_t]
end

#guid ⇒ Object



35
36
37
# File 'lib/new_relic/agent/transaction_info.rb', line 35

def guid
  @guid
end

#guid=(value) ⇒ Object



39
40
41
# File 'lib/new_relic/agent/transaction_info.rb', line 39

def guid=(value)
  @guid = value
end

#ignore_end_user=(value) ⇒ Object



51
52
53
# File 'lib/new_relic/agent/transaction_info.rb', line 51

def ignore_end_user=(value)
  @ignore_end_user = value
end

#ignore_end_user? ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/new_relic/agent/transaction_info.rb', line 47

def ignore_end_user?
  @ignore_end_user
end

#include_guid? ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/new_relic/agent/transaction_info.rb', line 31

def include_guid?
  token && duration > Agent.config[:apdex_t]
end

#transaction_name_set? ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/new_relic/agent/transaction_info.rb', line 19

def transaction_name_set?
  !@transaction_name.nil?
end

#transaction_trace_threshold ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/new_relic/agent/transaction_info.rb', line 61

def transaction_trace_threshold
  key = :'transaction_tracer.transaction_threshold'
  if Agent.config.source(key).class == Configuration::DefaultSource
    apdex_t * 4
  else
    Agent.config[key]
  end
end