appoptics_apm 4.4.1 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +1 -1
- data/appoptics_apm.gemspec +2 -2
- data/lib/appoptics_apm.rb +5 -0
- data/lib/appoptics_apm/api/logging.rb +1 -1
- data/lib/appoptics_apm/api/metrics.rb +1 -1
- data/lib/appoptics_apm/config.rb +2 -2
- data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +1 -1
- data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +3 -8
- data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +4 -9
- data/lib/appoptics_apm/inst/grpc_server.rb +120 -0
- data/lib/appoptics_apm/version.rb +2 -2
- data/lib/oboe_metal.rb +7 -2
- data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c8c572a8723e86a62a48fbd32aaa6659454ab9f463f06d8b46d268139c1a30
|
4
|
+
data.tar.gz: b147aa117802cee2b26e1362239fad37211979f13c52cb66a3784ab7c361490c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0cd3f37c066dd3b3a5bc1a8449b1d2342f6f6292b412a61defe946abf77cbe67b3ee91180357784ad3303f370e34c93b9f5c76c195b4613c9ebff5dfd491f44
|
7
|
+
data.tar.gz: 5960b044aa3cd9ed21e22925504a215e935484d66427a3c29bd374ea19fb2c3eb76c8b035e2ffab8b7d20ee8bd51b2d05338c9630a08373d60d388a21c7f6006
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/appoptics_apm.gemspec
CHANGED
@@ -41,11 +41,11 @@ Automatic tracing and metrics for Ruby applications. Get started at appoptics.co
|
|
41
41
|
|
42
42
|
s.add_runtime_dependency('json', '>= 0')
|
43
43
|
s.add_runtime_dependency('no_proxy_fix', '~> 0.1.2', '>= 0.1.2')
|
44
|
-
s.add_runtime_dependency('simplecov', '>= 0.16.0') if ENV["SIMPLECOV_COVERAGE"]
|
45
|
-
s.add_runtime_dependency('simplecov-console', '>= 0.4.0') if ENV["SIMPLECOV_COVERAGE"]
|
46
44
|
|
47
45
|
# Development dependencies used in gem development & testing
|
48
46
|
s.add_development_dependency('rake', '>= 0.9.0')
|
47
|
+
s.add_development_dependency('simplecov', '>= 0.16.0') if ENV["SIMPLECOV_COVERAGE"]
|
48
|
+
s.add_development_dependency('simplecov-console', '>= 0.4.0') if ENV["SIMPLECOV_COVERAGE"]
|
49
49
|
|
50
50
|
unless defined?(JRUBY_VERSION)
|
51
51
|
s.add_development_dependency('byebug', '>= 8.0.0')
|
data/lib/appoptics_apm.rb
CHANGED
@@ -44,6 +44,7 @@ begin
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
# appoptics_apm/loading can set AppOpticsAPM.loaded = false if the service key is not working
|
47
48
|
require 'appoptics_apm/loading'
|
48
49
|
require 'appoptics_apm/legacy_method_profiling'
|
49
50
|
require 'appoptics_apm/method_profiling'
|
@@ -59,6 +60,10 @@ begin
|
|
59
60
|
require 'appoptics_apm/frameworks/padrino'
|
60
61
|
require 'appoptics_apm/frameworks/grape'
|
61
62
|
else
|
63
|
+
$stderr.puts '=============================================================='
|
64
|
+
$stderr.puts 'AppOpticsAPM not loaded. Tracing disabled.'
|
65
|
+
$stderr.puts 'Service Key may be wrong or missing.'
|
66
|
+
$stderr.puts '=============================================================='
|
62
67
|
require 'appoptics_apm/noop/context'
|
63
68
|
end
|
64
69
|
|
@@ -42,7 +42,7 @@ module AppOpticsAPM
|
|
42
42
|
# AppOpticsAPM::API.log('logical_layer', 'exit')
|
43
43
|
#
|
44
44
|
# Returns nothing.
|
45
|
-
def log(layer, label, opts = {}, event=nil)
|
45
|
+
def log(layer, label, opts = {}, event = nil)
|
46
46
|
return AppOpticsAPM::Context.toString unless AppOpticsAPM.tracing?
|
47
47
|
|
48
48
|
event ||= AppOpticsAPM::Context.createEvent
|
@@ -22,7 +22,7 @@ module AppOpticsAPM
|
|
22
22
|
start = Time.now
|
23
23
|
yield
|
24
24
|
ensure
|
25
|
-
duration =(1000 * 1000 * (Time.now - start)).
|
25
|
+
duration = (1000 * 1000 * (Time.now - start)).to_i
|
26
26
|
transaction_name = determine_transaction_name(span, kvs)
|
27
27
|
kvs[:TransactionName] = AppOpticsAPM::Span.createSpan(transaction_name, nil, duration)
|
28
28
|
AppOpticsAPM.transaction_name = nil
|
data/lib/appoptics_apm/config.rb
CHANGED
@@ -14,8 +14,8 @@ module AppOpticsAPM
|
|
14
14
|
@@instrumentation = [:action_controller, :action_controller_api, :action_view,
|
15
15
|
:active_record, :bunnyclient, :bunnyconsumer, :cassandra, :curb,
|
16
16
|
:dalli, :delayed_jobclient, :delayed_jobworker,
|
17
|
-
:em_http_request, :excon, :faraday, :grpc_client, :grape,
|
18
|
-
:httpclient, :memcached, :mongo, :moped, :
|
17
|
+
:em_http_request, :excon, :faraday, :grpc_client, :grpc_server, :grape,
|
18
|
+
:httpclient, :nethttp, :memcached, :mongo, :moped, :padrino, :rack, :redis,
|
19
19
|
:resqueclient, :resqueworker, :rest_client,
|
20
20
|
:sequel, :sidekiqclient, :sidekiqworker, :sinatra, :typhoeus]
|
21
21
|
|
@@ -7,7 +7,7 @@ require 'appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql'
|
|
7
7
|
|
8
8
|
if AppOpticsAPM::Config[:active_record][:enabled] && !defined?(JRUBY_VERSION)
|
9
9
|
begin
|
10
|
-
adapter = ActiveRecord::Base.
|
10
|
+
adapter = ActiveRecord::Base.connection_config[:adapter]
|
11
11
|
|
12
12
|
if Rails::VERSION::MAJOR < 5
|
13
13
|
require 'appoptics_apm/frameworks/rails/inst/connection_adapters/utils'
|
@@ -20,15 +20,10 @@ module AppOpticsAPM
|
|
20
20
|
opts[:Name] = name.to_s if name
|
21
21
|
opts[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:active_record][:collect_backtraces]
|
22
22
|
|
23
|
-
|
24
|
-
config = ::Rails.configuration.database_configuration[::Rails.env]
|
25
|
-
else
|
26
|
-
config = ActiveRecord::Base.connection.instance_variable_get(:@config)
|
27
|
-
end
|
28
|
-
|
23
|
+
config = ActiveRecord::Base.connection_config
|
29
24
|
if config
|
30
|
-
opts[:Database] = config[
|
31
|
-
opts[:RemoteHost] = config[
|
25
|
+
opts[:Database] = config[:database] if config.key?(:database)
|
26
|
+
opts[:RemoteHost] = config[:host] if config.key?(:host)
|
32
27
|
adapter_name = config[:adapter]
|
33
28
|
|
34
29
|
case adapter_name
|
@@ -26,15 +26,10 @@ module AppOpticsAPM
|
|
26
26
|
opts[:Backtrace] = AppOpticsAPM::API.backtrace
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
config = ::Rails.configuration.database_configuration[::Rails.env]
|
31
|
-
else
|
32
|
-
config = ActiveRecord::Base.connection.instance_variable_get(:@config)
|
33
|
-
end
|
34
|
-
|
29
|
+
config = ActiveRecord::Base.connection_config
|
35
30
|
if config
|
36
|
-
opts[:Database] = config[
|
37
|
-
opts[:RemoteHost] = config[
|
31
|
+
opts[:Database] = config[:database] if config.key?(:database)
|
32
|
+
opts[:RemoteHost] = config[:host] if config.key?(:host)
|
38
33
|
adapter_name = config[:adapter]
|
39
34
|
|
40
35
|
case adapter_name
|
@@ -49,7 +44,7 @@ module AppOpticsAPM
|
|
49
44
|
AppOpticsAPM.logger.debug e.backtrace.join('\n')
|
50
45
|
end
|
51
46
|
|
52
|
-
opts
|
47
|
+
opts
|
53
48
|
end
|
54
49
|
|
55
50
|
# We don't want to trace framework caches. Only instrument SQL that
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Copyright (c) 2018 SolarWinds, LLC.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
module AppOpticsAPM
|
5
|
+
module GRPC
|
6
|
+
|
7
|
+
if defined? ::GRPC
|
8
|
+
STATUSCODES = {}
|
9
|
+
::GRPC::Core::StatusCodes.constants.each { |code| STATUSCODES[::GRPC::Core::StatusCodes.const_get(code)] = code }
|
10
|
+
end
|
11
|
+
|
12
|
+
module RpcDesc
|
13
|
+
|
14
|
+
def self.included(klass)
|
15
|
+
::AppOpticsAPM::Util.method_alias(klass, :handle_request_response, ::GRPC::RpcDesc)
|
16
|
+
::AppOpticsAPM::Util.method_alias(klass, :handle_client_streamer, ::GRPC::RpcDesc)
|
17
|
+
::AppOpticsAPM::Util.method_alias(klass, :handle_server_streamer, ::GRPC::RpcDesc)
|
18
|
+
::AppOpticsAPM::Util.method_alias(klass, :handle_bidi_streamer, ::GRPC::RpcDesc)
|
19
|
+
::AppOpticsAPM::Util.method_alias(klass, :run_server_method, ::GRPC::RpcDesc)
|
20
|
+
end
|
21
|
+
|
22
|
+
def grpc_tags(active_call, mth)
|
23
|
+
tags = {
|
24
|
+
'Spec' => 'grpc_server',
|
25
|
+
'URL' => active_call.metadata['method'],
|
26
|
+
'Controller' => mth.owner.to_s,
|
27
|
+
'Action' => mth.name.to_s,
|
28
|
+
'HTTP-Host' => active_call.peer
|
29
|
+
}
|
30
|
+
|
31
|
+
if request_response?
|
32
|
+
tags['GRPCMethodType'] = 'UNARY'
|
33
|
+
elsif client_streamer?
|
34
|
+
tags['GRPCMethodType'] = 'CLIENT_STREAMING'
|
35
|
+
elsif server_streamer?
|
36
|
+
tags['GRPCMethodType'] = 'SERVER_STREAMING'
|
37
|
+
else # is a bidi_stream
|
38
|
+
tags['GRPCMethodType'] = 'BIDI_STREAMING'
|
39
|
+
end
|
40
|
+
|
41
|
+
tags
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_request_response_with_appoptics(active_call, mth, inter_ctx)
|
45
|
+
handle_call('handle_request_response_without_appoptics', active_call, mth, inter_ctx)
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_client_streamer_with_appoptics(active_call, mth, inter_ctx)
|
49
|
+
handle_call('handle_client_streamer_without_appoptics', active_call, mth, inter_ctx)
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_server_streamer_with_appoptics(active_call, mth, inter_ctx)
|
53
|
+
handle_call('handle_server_streamer_without_appoptics', active_call, mth, inter_ctx)
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_bidi_streamer_with_appoptics(active_call, mth, inter_ctx)
|
57
|
+
handle_call('handle_bidi_streamer_without_appoptics', active_call, mth, inter_ctx)
|
58
|
+
end
|
59
|
+
|
60
|
+
# status codes need to be determined in this lower method, because they may not get raised to the
|
61
|
+
# next instrumented method
|
62
|
+
def handle_call(without, active_call, mth, inter_ctx)
|
63
|
+
begin
|
64
|
+
send(without, active_call, mth, inter_ctx)
|
65
|
+
rescue ::GRPC::Core::CallError, ::GRPC::BadStatus, ::GRPC::Core::OutOfTime, StandardError, NotImplementedError => e
|
66
|
+
log_grpc_exception(active_call, e)
|
67
|
+
raise e
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def run_server_method_with_appoptics(active_call, mth, inter_ctx)
|
72
|
+
tags = grpc_tags(active_call, mth)
|
73
|
+
AppOpticsAPM::API.log_start('grpc-server', active_call.metadata['x-trace'], tags)
|
74
|
+
|
75
|
+
exit_event = AppOpticsAPM::Event.startTrace(AppOpticsAPM::Context.get)
|
76
|
+
active_call.merge_metadata_to_send({ 'x-trace' => exit_event.metadataString })
|
77
|
+
begin
|
78
|
+
AppOpticsAPM::API.send_metrics('grpc-server', tags) do
|
79
|
+
run_server_method_without_appoptics(active_call, mth, inter_ctx)
|
80
|
+
end
|
81
|
+
rescue => e
|
82
|
+
log_grpc_exception(active_call, e)
|
83
|
+
raise e
|
84
|
+
ensure
|
85
|
+
tags['GRPCStatus'] = active_call.metadata_to_send.delete('grpc_status')
|
86
|
+
tags['GRPCStatus'] ||= active_call.status ? AppOpticsAPM::GRPC::STATUSCODES[active_call.status.code].to_s : 'OK'
|
87
|
+
tags['Backtrace'] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:grpc_server][:collect_backtraces]
|
88
|
+
|
89
|
+
exit_event.addEdge(AppOpticsAPM::Context.get)
|
90
|
+
AppOpticsAPM::API.log_end('grpc-server', tags, exit_event)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def log_grpc_exception(active_call, e)
|
97
|
+
unless e.instance_variable_get(:@exn_logged)
|
98
|
+
AppOpticsAPM::API.log_exception('grpc-server', e)
|
99
|
+
|
100
|
+
unless active_call.metadata_sent
|
101
|
+
if e.class == ::GRPC::Core::OutOfTime
|
102
|
+
active_call.merge_metadata_to_send({ 'grpc_status' => 'DEADLINE_EXCEEDED' })
|
103
|
+
elsif e.respond_to?(:code)
|
104
|
+
active_call.merge_metadata_to_send({ 'grpc_status' => AppOpticsAPM::GRPC::STATUSCODES[e.code].to_s })
|
105
|
+
else
|
106
|
+
active_call.merge_metadata_to_send({ 'grpc_status' => 'UNKNOWN' })
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
if defined?(GRPC) && AppOpticsAPM::Config['grpc_server'][:enabled]
|
118
|
+
# server side is instrumented in RpcDesc
|
119
|
+
AppOpticsAPM::Util.send_include(GRPC::RpcDesc, AppOpticsAPM::GRPC::RpcDesc)
|
120
|
+
end
|
data/lib/oboe_metal.rb
CHANGED
@@ -31,8 +31,13 @@ module AppOpticsAPM
|
|
31
31
|
when 'udp'
|
32
32
|
ENV['APPOPTICS_REPORTER_UDP'] = "#{AppOpticsAPM::Config[:reporter_host]}:#{AppOpticsAPM::Config[:reporter_port]}"
|
33
33
|
else # default is ssl, service_key is mandatory
|
34
|
-
|
35
|
-
|
34
|
+
service_key = ENV['APPOPTICS_SERVICE_KEY'].to_s || AppOpticsAPM::Config[:service_key].to_s
|
35
|
+
if service_key == ''
|
36
|
+
AppOpticsAPM.logger.warn '[appoptics_apm/warn] APPOPTICS_SERVICE_KEY not set. Cannot submit data.'
|
37
|
+
AppOpticsAPM.loaded = false
|
38
|
+
return
|
39
|
+
elsif service_key !~ /^[0-9a-fA-F]{64}:[-.:_?\\\/\w ]{1,255}$/
|
40
|
+
AppOpticsAPM.logger.warn '[appoptics_apm/warn] APPOPTICS_SERVICE_KEY problem. No service name or api token in wrong format. Cannot submit data.'
|
36
41
|
AppOpticsAPM.loaded = false
|
37
42
|
return
|
38
43
|
end
|
@@ -177,6 +177,7 @@ if defined?(AppOpticsAPM::Config)
|
|
177
177
|
AppOpticsAPM::Config[:excon][:enabled] = true
|
178
178
|
AppOpticsAPM::Config[:faraday][:enabled] = true
|
179
179
|
AppOpticsAPM::Config[:grpc_client][:enabled] = true
|
180
|
+
AppOpticsAPM::Config[:grpc_server][:enabled] = true
|
180
181
|
AppOpticsAPM::Config[:grape][:enabled] = true
|
181
182
|
AppOpticsAPM::Config[:httpclient][:enabled] = true
|
182
183
|
AppOpticsAPM::Config[:memcached][:enabled] = true
|
@@ -243,6 +244,7 @@ if defined?(AppOpticsAPM::Config)
|
|
243
244
|
AppOpticsAPM::Config[:faraday][:collect_backtraces] = false
|
244
245
|
AppOpticsAPM::Config[:grape][:collect_backtraces] = true
|
245
246
|
AppOpticsAPM::Config[:grpc_client][:collect_backtraces] = false
|
247
|
+
AppOpticsAPM::Config[:grpc_server][:collect_backtraces] = false
|
246
248
|
AppOpticsAPM::Config[:httpclient][:collect_backtraces] = true
|
247
249
|
AppOpticsAPM::Config[:memcached][:collect_backtraces] = false
|
248
250
|
AppOpticsAPM::Config[:mongo][:collect_backtraces] = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appoptics_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maia Engeli
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-12-
|
13
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/appoptics_apm/inst/excon.rb
|
194
194
|
- lib/appoptics_apm/inst/faraday.rb
|
195
195
|
- lib/appoptics_apm/inst/grpc_client.rb
|
196
|
+
- lib/appoptics_apm/inst/grpc_server.rb
|
196
197
|
- lib/appoptics_apm/inst/http.rb
|
197
198
|
- lib/appoptics_apm/inst/httpclient.rb
|
198
199
|
- lib/appoptics_apm/inst/memcached.rb
|