stackify-ruby-apm 1.9.8 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 897d8d6a22f1c94f016daa020e4b423a9f3d891141a88874c9630a0940a1ccec
4
- data.tar.gz: 701690bce6b06e581c57640107f1e49999ba81e284fd269edb893390d15fbb6f
3
+ metadata.gz: 9d62649a9bf57a77665b23b7e42ffe0d19395853a9b0b79e128197691e5bfb62
4
+ data.tar.gz: '0216963cac56d043591eb797ab64cce012a479de25d9a5fbe202eb6f3d73929a'
5
5
  SHA512:
6
- metadata.gz: 55f6cff0dcdcef0626befd3522ca56cd78ce82a360d2ed13aba19dc6b00c6fb6bdc7f0033fd40bfc5ecdc25608f65b293654ac2993c171ab301f84e5c92b72f8
7
- data.tar.gz: 71c2cfdfa651ba9bcefc10e2c747e83016e5394fa601bd30640ae0a3729dde52b037df36134c1a773e963f8b74102c50466fed7d0642f013cc67bd559ea61a00
6
+ metadata.gz: 5c6c501b6eac9dbad6378a03cf1234468c84480fe15b977e44187d331452c39f6a76d19348b9141616791e564ccc436c48f8d27900796ca06104a67863c5a02f
7
+ data.tar.gz: 89edd6496518ed877c65e87320a8bbf543f60a34b7e9023e0546b011854077d1c31f656bccbf1947229831b21f1fdf4f352c984cf11931dd3dc1b8e15e17e102
@@ -209,6 +209,7 @@ module StackifyRubyAPM
209
209
  curb/multi
210
210
  httparty
211
211
  stackify_logger
212
+ sidekiq
212
213
  ]
213
214
  end
214
215
 
@@ -3,6 +3,7 @@
3
3
  # Monkey patch for the custom instrumentation any values from config/stackify.json will be loop and will
4
4
  # register as a spy.
5
5
  #
6
+ require 'logger'
6
7
  require 'stackify_apm/instrumenter_helper.rb'
7
8
  require 'stackify_apm/config'
8
9
  require 'json'
@@ -10,7 +11,8 @@ require 'json'
10
11
  # rubocop:disable Metrics/PerceivedComplexity
11
12
  module StackifyRubyAPM
12
13
  # @api private
13
- module Spies
14
+ module Spies extend Log
15
+
14
16
  def self.run_custom_instrumentation
15
17
  config = Config.new
16
18
  to_instrument = parse_json_config(config.json_config_file)
@@ -27,11 +29,21 @@ module StackifyRubyAPM
27
29
  tracked_func = custom_spy['trackedFunction']
28
30
  tracked_func_name = defined?(custom_spy['trackedFunctionName']) ? custom_spy['trackedFunctionName'] : ''
29
31
  transaction = defined?(custom_spy['transaction']) ? custom_spy['transaction'] : nil
32
+ file_path = defined?(custom_spy['file_path']) ? custom_spy['file_path'] : nil
30
33
 
31
34
  tracked_function_tpl = tracked_func_name.nil? ? '{{ClassName}}.{{MethodName}}' : tracked_func_name
32
35
  tracked_function_name = tracked_function_tpl.sub '{{ClassName}}', current_class
33
36
  tracked_function_name = tracked_function_name.sub '{{MethodName}}', current_method
34
37
 
38
+ if !class_exists?(current_class) && !file_path.nil?
39
+ begin
40
+ require file_path
41
+ rescue LoadError => e
42
+ debug "[StackifyRubyAPM] File path doesn't exist."
43
+ debug e.inspect
44
+ end
45
+ end
46
+
35
47
  # rubocop:disable Style/Next
36
48
  if class_exists?(current_class)
37
49
  mod_constant = Module.const_get(current_class.to_s)
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Monkey patch for the sidekiq class for running async tasks.
4
+ #
5
+
6
+ module StackifyRubyAPM
7
+ # @api private
8
+ module Spies
9
+ # @api private
10
+ class SidekiqClientSpy
11
+ def install
12
+ Sidekiq::Processor.class_eval do
13
+ alias_method 'process_without_apm', 'process'
14
+
15
+ def process(work, *args, &block)
16
+ ret = nil
17
+ begin
18
+ job = nil
19
+ if defined? work.message
20
+ job = work.message
21
+ else
22
+ job = work.job
23
+ end
24
+ job_hash = JSON.parse job
25
+ name = job_hash["class"]
26
+ transaction = StackifyRubyAPM.transaction name, 'TASK'
27
+ ret = process_without_apm(work, *args, &block)
28
+ rescue StackifyRubyAPM::InternalError
29
+ raise # Don't report StackifyRubyAPM errors
30
+ rescue StandardError => e
31
+ StackifyRubyAPM.report e
32
+ raise e
33
+ ensure
34
+ transaction.submit()
35
+ end
36
+ ret
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ register 'Sidekiq::Processor', 'sidekiq/processor', SidekiqClientSpy.new
43
+ end
44
+ end
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'stackify_apm/root_info'
2
3
  require 'stackify_apm/serializers'
3
4
 
@@ -12,6 +13,15 @@ module StackifyRubyAPM
12
13
  @transaction_serializers = Serializers::Transactions.new(config)
13
14
  end
14
15
 
16
+ def get_protobuf_message(transactions)
17
+ protobuf_obj = build_message(transactions)
18
+ StackifyProtoBuf::Traces.encode(protobuf_obj)
19
+ end
20
+
21
+ def get_json_message(transactions)
22
+ JSON.generate(build_json_message(transactions))
23
+ end
24
+
15
25
  # This method will build a group of Stackify::Traces from the protobuf objects.
16
26
  # It accept Array of transactions.
17
27
  def build_message(transactions = [])
@@ -28,6 +38,19 @@ module StackifyRubyAPM
28
38
  debug "[AgentBaseTransport] build_message() exception: #{e.inspect}"
29
39
  end
30
40
 
41
+ def build_json_message(transactions = [])
42
+ traces = []
43
+ transactions.each do |transaction|
44
+ # convert transaction to json
45
+ json_transaction = @transaction_serializers.build_json(@config, transaction)
46
+ # add to traces array
47
+ traces << json_transaction
48
+ end
49
+ return traces
50
+ rescue StandardError => e
51
+ debug "[AgentBaseTransport] build_json_message() exception: #{e.inspect}"
52
+ end
53
+
31
54
  def post(_transactions = [])
32
55
  raise NotImplementedError
33
56
  end
@@ -5,24 +5,32 @@ require 'faraday'
5
5
  require 'ostruct'
6
6
 
7
7
  module StackifyRubyAPM
8
- # This class will handle the sending of protobuf messages through HTTP.
8
+ # This class will handle the sending of transaction messages through HTTP.
9
9
  # @api private
10
10
  class AgentHTTPClient < AgentBaseTransport
11
11
  include Log
12
12
 
13
- HEADERS = {
14
- 'Content-Type' => 'application/x-protobuf'
15
- }.freeze
16
-
17
13
  def initialize(config)
18
14
  @config = config
19
15
  super(config)
20
16
  end
21
17
 
18
+ def get_protobuf_headers
19
+ {
20
+ 'Content-Type' => 'application/x-protobuf'
21
+ }.freeze
22
+ end
23
+
24
+ def get_json_headers
25
+ {
26
+ 'Content-Type' => 'application/json'
27
+ }.freeze
28
+ end
29
+
22
30
  # rubocop:disable Metrics/CyclomaticComplexity
23
31
  # rubocop:disable Metrics/PerceivedComplexity
24
32
  #
25
- # This method will send a protobuf message to HTTP request.
33
+ # This method will send a transction message to HTTP request.
26
34
  # It will accept Array of transactions.
27
35
  def post(transactions = [])
28
36
  debug '[AgentHTTPClient] post()' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
@@ -31,16 +39,14 @@ module StackifyRubyAPM
31
39
  retry_count = 0
32
40
  delay = @config.delay_seconds
33
41
  begin
34
- protobuf_obj = build_message(transactions)
35
- message = StackifyProtoBuf::Traces.encode(protobuf_obj)
36
- # Convert message into binary and send it to http request
42
+ message = get_json_message(transactions)
37
43
  conn = Faraday.new(ssl: { verify: false })
38
44
  response = conn.post do |req|
39
45
  req.url URI(@config.transport_http_endpoint + @config.agent_traces_url)
40
- req.headers = HEADERS
46
+ req.headers = get_json_headers
41
47
  req.body = message
42
48
  end
43
- if response.try(:status) == 200
49
+ if defined?(response.status) && response.status == 200
44
50
  debug '[AgentHTTPClient] Successfully send message via http request.' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
45
51
  elsif ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
46
52
  debug "[AgentHTTPClient] Failure sending via http request: #{response.inspect}"
@@ -4,7 +4,7 @@ require 'net_http_unix'
4
4
  require 'ostruct'
5
5
 
6
6
  module StackifyRubyAPM
7
- # This class will handle the sending of protobuf messages through unix domain socket.
7
+ # This class will handle the sending of transaction messages through unix domain socket.
8
8
  # @api private
9
9
  class UnixSocketClient < AgentBaseTransport
10
10
  include Log
@@ -14,10 +14,18 @@ module StackifyRubyAPM
14
14
  super(config)
15
15
  end
16
16
 
17
+ def get_protobuf_headers
18
+ 'application/x-protobuf'
19
+ end
20
+
21
+ def get_json_headers
22
+ 'application/json'
23
+ end
24
+
17
25
  # rubocop:disable Metrics/CyclomaticComplexity
18
26
  # rubocop:disable Metrics/PerceivedComplexity
19
27
  #
20
- # This method will send a protobuf message to the unix domain socket.
28
+ # This method will send a transaction message to the unix domain socket.
21
29
  # It will accept Array of transactions.
22
30
  def post(transactions = [])
23
31
  debug '[UnixSocketClient] post()' if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
@@ -27,11 +35,10 @@ module StackifyRubyAPM
27
35
  delay = @config.delay_seconds
28
36
  begin
29
37
  # Convert message into binary and send it to unix domain socket
30
- protobuf_obj = build_message(transactions)
31
- message = StackifyProtoBuf::Traces.encode(protobuf_obj)
38
+ message = get_json_message(transactions)
32
39
  client = NetX::HTTPUnix.new('unix://' + @config.unix_socket_path)
33
40
  req = Net::HTTP::Post.new(@config.agent_traces_url)
34
- req.set_content_type('application/x-protobuf')
41
+ req.set_content_type(get_json_headers)
35
42
  req.body = message
36
43
  response = client.request(req)
37
44
  debug "[UnixSocketClient] status_code = #{response.code}" if ENV['STACKIFY_TRANSPORT_LOG_LEVEL'] == '0'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Sets the version of the APM
4
4
  module StackifyRubyAPM
5
- VERSION = '1.9.8'.freeze
5
+ VERSION = '1.10.0'.freeze
6
6
  end
@@ -35,9 +35,6 @@ require 'stackify_apm/transport/unix_socket_client'
35
35
  require 'stackify_apm/transport/agent_http_client'
36
36
  require 'stackify_apm/transport/aws_lambda_logging'
37
37
 
38
- require 'google/protobuf'
39
- require 'proto/stackify_trace'
40
-
41
38
  # Checks if the framework using is Rails
42
39
  require 'stackify_apm/railtie' if defined?(::Rails::Railtie)
43
40
 
@@ -33,20 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'bigdecimal'
34
34
  end
35
35
 
36
- # rubocop
37
- if RUBY_VERSION >= '2.2.0'
38
- spec.add_development_dependency 'rubocop-performance'
39
- end
40
-
41
- # protobuf
42
- if RUBY_VERSION >= '2.7'
43
- spec.add_development_dependency 'google-protobuf', '= 3.5.0'
44
- elsif RUBY_VERSION > '2.3'
45
- spec.add_development_dependency 'google-protobuf', '>= 3.5.0'
46
- else
47
- spec.add_development_dependency 'google-protobuf', '= 3.5.0'
48
- end
49
-
50
36
  spec.add_development_dependency 'bundler', '~> 1.16'
51
37
  spec.add_development_dependency 'rake', '~> 10.0'
52
38
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -57,7 +43,6 @@ Gem::Specification.new do |spec|
57
43
  spec.add_development_dependency 'httpclient'
58
44
  spec.add_development_dependency 'mongo'
59
45
  spec.add_development_dependency 'mysql2'
60
- spec.add_development_dependency 'net_http_unix', '~> 0.2'
61
46
  spec.add_development_dependency 'pg', '~> 0.20'
62
47
  spec.add_development_dependency 'rack-test'
63
48
  spec.add_development_dependency 'rubocop'
@@ -73,7 +58,6 @@ Gem::Specification.new do |spec|
73
58
  spec.add_dependency('concurrent-ruby', '~> 1.0')
74
59
  spec.add_dependency('delegate_matcher', '~> 0.4')
75
60
  spec.add_dependency('faraday', '~> 0.8')
76
- spec.add_dependency('google-protobuf', '>= 3.5.0', '< 4.0')
77
61
  spec.add_dependency('net_http_unix', '~> 0.2')
78
62
  spec.add_dependency('rufus-scheduler', '~> 3.0')
79
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-ruby-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.8
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-11 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,34 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop-performance
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: google-protobuf
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 3.5.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 3.5.0
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: bundler
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -206,20 +178,6 @@ dependencies:
206
178
  - - ">="
207
179
  - !ruby/object:Gem::Version
208
180
  version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: net_http_unix
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: '0.2'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: '0.2'
223
181
  - !ruby/object:Gem::Dependency
224
182
  name: pg
225
183
  requirement: !ruby/object:Gem::Requirement
@@ -416,26 +374,6 @@ dependencies:
416
374
  - - "~>"
417
375
  - !ruby/object:Gem::Version
418
376
  version: '0.8'
419
- - !ruby/object:Gem::Dependency
420
- name: google-protobuf
421
- requirement: !ruby/object:Gem::Requirement
422
- requirements:
423
- - - ">="
424
- - !ruby/object:Gem::Version
425
- version: 3.5.0
426
- - - "<"
427
- - !ruby/object:Gem::Version
428
- version: '4.0'
429
- type: :runtime
430
- prerelease: false
431
- version_requirements: !ruby/object:Gem::Requirement
432
- requirements:
433
- - - ">="
434
- - !ruby/object:Gem::Version
435
- version: 3.5.0
436
- - - "<"
437
- - !ruby/object:Gem::Version
438
- version: '4.0'
439
377
  - !ruby/object:Gem::Dependency
440
378
  name: net_http_unix
441
379
  requirement: !ruby/object:Gem::Requirement
@@ -526,6 +464,7 @@ files:
526
464
  - lib/stackify_apm/spies/net_http.rb
527
465
  - lib/stackify_apm/spies/redis.rb
528
466
  - lib/stackify_apm/spies/sequel.rb
467
+ - lib/stackify_apm/spies/sidekiq.rb
529
468
  - lib/stackify_apm/spies/sinatra.rb
530
469
  - lib/stackify_apm/spies/sinatra_activerecord/mysql_adapter.rb
531
470
  - lib/stackify_apm/spies/sinatra_activerecord/postgresql_adapter.rb