Class: NewRelic::Agent::TransactionInfo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransactionInfo

Returns a new instance of TransactionInfo.



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

def initialize
  @guid = ""
  @transaction_name = "(unknown)"
  @start_time = Time.now
  @ignore_end_user = false
end

Instance Attribute Details

#capture_deep_ttObject

Returns the value of attribute capture_deep_tt.



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

def capture_deep_tt
  @capture_deep_tt
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#transaction_nameObject

Returns the value of attribute transaction_name.



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

def transaction_name
  @transaction_name
end

Class Method Details

.clearObject



53
54
55
# File 'lib/new_relic/agent/transaction_info.rb', line 53

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

.getObject



45
46
47
# File 'lib/new_relic/agent/transaction_info.rb', line 45

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

.get_token(request) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/new_relic/agent/transaction_info.rb', line 65

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.



59
60
61
62
63
# File 'lib/new_relic/agent/transaction_info.rb', line 59

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



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

def self.sanitize_token(token)

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

.set(instance) ⇒ Object



49
50
51
# File 'lib/new_relic/agent/transaction_info.rb', line 49

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

Instance Method Details

#durationObject



33
34
35
# File 'lib/new_relic/agent/transaction_info.rb', line 33

def duration
  Time.now - start_time
end

#force_persist_sample?(sample) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/new_relic/agent/transaction_info.rb', line 17

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

#guidObject



25
26
27
# File 'lib/new_relic/agent/transaction_info.rb', line 25

def guid
  @guid
end

#guid=(value) ⇒ Object



29
30
31
# File 'lib/new_relic/agent/transaction_info.rb', line 29

def guid=(value)
  @guid = value
end

#ignore_end_user=(value) ⇒ Object



41
42
43
# File 'lib/new_relic/agent/transaction_info.rb', line 41

def ignore_end_user=(value)
  @ignore_end_user = value
end

#ignore_end_user?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/new_relic/agent/transaction_info.rb', line 37

def ignore_end_user?
  @ignore_end_user
end

#include_guid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/new_relic/agent/transaction_info.rb', line 21

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