instana 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instana/agent.rb +55 -2
- data/lib/instana/instrumentation/rack.rb +8 -6
- data/lib/instana/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4e0afa7990ec121d8542873c665d2ddda7e1ee9
|
4
|
+
data.tar.gz: 33143dc761cf85e27ab21ed22c9f64f8670c3a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85b7857890a0da50ef837027a1c5e0e7f413189b60175d1f26e682f5c109c7f98534efa2a84ef0f2cbf0e1162eb00f88b10604118fc18ca8036b3aef94e4c02e
|
7
|
+
data.tar.gz: 57d956387066525d20f4e6efc108115f4b02d001418fdad0cdf639143be00e32bfc26173eccc96cfed2bf63be36dbc3b0e09fd96db9209c1037f44ff27a36801
|
data/lib/instana/agent.rb
CHANGED
@@ -22,6 +22,9 @@ module Instana
|
|
22
22
|
# Supported two states (unannounced & announced)
|
23
23
|
@state = :unannounced
|
24
24
|
|
25
|
+
# Store the pid from process boot so we can detect forks
|
26
|
+
@pid = Process.pid
|
27
|
+
|
25
28
|
# Snapshot data is collected once per process but resent
|
26
29
|
# every 10 minutes along side process metrics.
|
27
30
|
@snapshot = take_snapshot
|
@@ -39,8 +42,9 @@ module Instana
|
|
39
42
|
@announce_timer = nil
|
40
43
|
@collect_timer = nil
|
41
44
|
|
42
|
-
# Detect
|
45
|
+
# Detect platform flags
|
43
46
|
@is_linux = (RUBY_PLATFORM =~ /linux/i) ? true : false
|
47
|
+
@is_osx = (RUBY_PLATFORM =~ /darwin/i) ? true : false
|
44
48
|
|
45
49
|
# In case we're running in Docker, have the default gateway available
|
46
50
|
# to check in case we're running in bridged network mode
|
@@ -53,16 +57,57 @@ module Instana
|
|
53
57
|
# The agent UUID returned from the host agent
|
54
58
|
@agent_uuid = nil
|
55
59
|
|
60
|
+
collect_process_info
|
61
|
+
end
|
62
|
+
|
63
|
+
# Used in class initialization and after a fork, this method
|
64
|
+
# collects up process information and stores it in @process
|
65
|
+
#
|
66
|
+
def collect_process_info
|
56
67
|
@process = {}
|
57
68
|
cmdline = ProcTable.ps(Process.pid).cmdline.split("\0")
|
58
69
|
@process[:name] = cmdline.shift
|
59
70
|
@process[:arguments] = cmdline
|
60
|
-
|
71
|
+
|
72
|
+
if @is_osx
|
73
|
+
# Handle OSX bug where env vars show up at the end of process name
|
74
|
+
# such as MANPATH etc..
|
75
|
+
@process[:name].gsub!(/[_A-Z]+=\S+/, '')
|
76
|
+
@process[:name].rstrip!
|
77
|
+
end
|
78
|
+
|
79
|
+
@process[:original_pid] = @pid
|
61
80
|
# This is usually Process.pid but in the case of docker, the host agent
|
62
81
|
# will return to us the true host pid in which we use to report data.
|
63
82
|
@process[:report_pid] = nil
|
64
83
|
end
|
65
84
|
|
85
|
+
# Determine whether the pid has changed since Agent start.
|
86
|
+
#
|
87
|
+
# @ return [Boolean] true or false to indicate if forked
|
88
|
+
#
|
89
|
+
def forked?
|
90
|
+
@pid != Process.pid
|
91
|
+
end
|
92
|
+
|
93
|
+
# Used post fork to re-initialize state and restart communications with
|
94
|
+
# the host agent.
|
95
|
+
#
|
96
|
+
def after_fork
|
97
|
+
::Instana.logger.debug "after_fork hook called. Falling back to unannounced state."
|
98
|
+
|
99
|
+
# Re-collect process information post fork
|
100
|
+
@pid = Process.pid
|
101
|
+
collect_process_info
|
102
|
+
|
103
|
+
# Set last snapshot to 10 minutes ago
|
104
|
+
# so we send a snapshot sooner than later
|
105
|
+
@last_snapshot = Time.now - 600
|
106
|
+
|
107
|
+
transition_to(:unannounced)
|
108
|
+
start
|
109
|
+
end
|
110
|
+
|
66
111
|
# Sets up periodic timers and starts the agent in a background thread.
|
67
112
|
#
|
68
113
|
def start
|
@@ -70,6 +115,10 @@ module Instana
|
|
70
115
|
# We attempt to announce this ruby sensor to the host agent.
|
71
116
|
# In case of failure, we try again in 30 seconds.
|
72
117
|
@announce_timer = @timers.now_and_every(30) do
|
118
|
+
if forked?
|
119
|
+
after_fork
|
120
|
+
break
|
121
|
+
end
|
73
122
|
if host_agent_ready? && announce_sensor
|
74
123
|
::Instana.logger.debug "Announce successful. Switching to metrics collection."
|
75
124
|
transition_to(:announced)
|
@@ -81,6 +130,10 @@ module Instana
|
|
81
130
|
# every ::Instana::Collector.interval seconds.
|
82
131
|
@collect_timer = @timers.every(::Instana::Collector.interval) do
|
83
132
|
if @state == :announced
|
133
|
+
if forked?
|
134
|
+
after_fork
|
135
|
+
break
|
136
|
+
end
|
84
137
|
unless ::Instana::Collector.collect_and_report
|
85
138
|
# If report has been failing for more than 1 minute,
|
86
139
|
# fall back to unannounced state
|
@@ -27,19 +27,21 @@ module Instana
|
|
27
27
|
|
28
28
|
status, headers, response = @app.call(env)
|
29
29
|
|
30
|
-
|
30
|
+
if ::Instana.tracer.tracing?
|
31
|
+
kvs[:http][:status] = status
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
# Save the IDs before the trace ends so we can place
|
34
|
+
# them in the response headers in the ensure block
|
35
|
+
trace_id = ::Instana.tracer.trace_id
|
36
|
+
span_id = ::Instana.tracer.span_id
|
37
|
+
end
|
36
38
|
|
37
39
|
[status, headers, response]
|
38
40
|
rescue Exception => e
|
39
41
|
::Instana.tracer.log_error(e)
|
40
42
|
raise
|
41
43
|
ensure
|
42
|
-
if headers
|
44
|
+
if headers && ::Instana.tracer.tracing?
|
43
45
|
# Set reponse headers; encode as hex string
|
44
46
|
headers['X-Instana-T'] = ::Instana.tracer.id_to_header(trace_id)
|
45
47
|
headers['X-Instana-S'] = ::Instana.tracer.id_to_header(span_id)
|
data/lib/instana/version.rb
CHANGED