elastic-apm 3.3.0 → 3.4.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.jenkins_exclude.yml +4 -4
  3. data/.ci/.jenkins_ruby.yml +1 -1
  4. data/.ci/Jenkinsfile +5 -3
  5. data/.ci/jobs/apm-agent-ruby-downstream.yml +1 -0
  6. data/.ci/jobs/apm-agent-ruby-linting-mbp.yml +1 -0
  7. data/.ci/jobs/apm-agent-ruby-mbp.yml +1 -0
  8. data/.ci/prepare-git-context.sh +5 -2
  9. data/.github/ISSUE_TEMPLATE/Bug_report.md +38 -0
  10. data/.github/ISSUE_TEMPLATE/Feature_request.md +17 -0
  11. data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  12. data/.gitignore +3 -0
  13. data/.rubocop.yml +6 -0
  14. data/CHANGELOG.asciidoc +25 -1
  15. data/Gemfile +6 -2
  16. data/bench/sql.rb +49 -0
  17. data/bin/build_docs +1 -1
  18. data/codecov.yml +32 -0
  19. data/docs/api.asciidoc +37 -0
  20. data/docs/configuration.asciidoc +18 -1
  21. data/docs/supported-technologies.asciidoc +20 -1
  22. data/lib/elastic_apm.rb +29 -5
  23. data/lib/elastic_apm/agent.rb +6 -2
  24. data/lib/elastic_apm/child_durations.rb +9 -4
  25. data/lib/elastic_apm/config.rb +8 -1
  26. data/lib/elastic_apm/config/options.rb +3 -4
  27. data/lib/elastic_apm/context/response.rb +10 -2
  28. data/lib/elastic_apm/instrumenter.rb +20 -11
  29. data/lib/elastic_apm/normalizers/rails/active_record.rb +12 -5
  30. data/lib/elastic_apm/rails.rb +1 -10
  31. data/lib/elastic_apm/railtie.rb +1 -1
  32. data/lib/elastic_apm/span.rb +3 -2
  33. data/lib/elastic_apm/span/context.rb +26 -44
  34. data/lib/elastic_apm/span/context/db.rb +19 -0
  35. data/lib/elastic_apm/span/context/destination.rb +44 -0
  36. data/lib/elastic_apm/span/context/http.rb +26 -0
  37. data/lib/elastic_apm/spies/elasticsearch.rb +18 -5
  38. data/lib/elastic_apm/spies/faraday.rb +36 -18
  39. data/lib/elastic_apm/spies/http.rb +16 -2
  40. data/lib/elastic_apm/spies/mongo.rb +5 -0
  41. data/lib/elastic_apm/spies/net_http.rb +27 -7
  42. data/lib/elastic_apm/spies/sequel.rb +25 -15
  43. data/lib/elastic_apm/spies/shoryuken.rb +48 -0
  44. data/lib/elastic_apm/spies/sneakers.rb +57 -0
  45. data/lib/elastic_apm/sql.rb +19 -0
  46. data/lib/elastic_apm/sql/signature.rb +152 -0
  47. data/lib/elastic_apm/sql/tokenizer.rb +247 -0
  48. data/lib/elastic_apm/sql/tokens.rb +46 -0
  49. data/lib/elastic_apm/sql_summarizer.rb +1 -2
  50. data/lib/elastic_apm/transaction.rb +11 -11
  51. data/lib/elastic_apm/transport/connection/proxy_pipe.rb +2 -2
  52. data/lib/elastic_apm/transport/headers.rb +4 -0
  53. data/lib/elastic_apm/transport/serializers/span_serializer.rb +24 -7
  54. data/lib/elastic_apm/version.rb +1 -1
  55. metadata +16 -3
  56. data/.github/workflows/main.yml +0 -14
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElasticAPM
4
+ module Sql
5
+ # @api private
6
+ module Tokens
7
+ OTHER = :OTHER
8
+ COMMENT = :COMMENT
9
+ IDENT = :IDENT
10
+ NUMBER = :NUMBER
11
+ STRING = :STRING
12
+
13
+ PERIOD = :PERIOD
14
+ COMMA = :COMMA
15
+ LPAREN = :LPAREN
16
+ RPAREN = :RPAREN
17
+
18
+ AS = :AS
19
+ CALL = :CALL
20
+ DELETE = :DELETE
21
+ FROM = :FROM
22
+ INSERT = :INSERT
23
+ INTO = :INTO
24
+ OR = :OR
25
+ REPLACE = :REPLACE
26
+ SELECT = :SELECT
27
+ SET = :SET
28
+ TABLE = :TABLE
29
+ TRUNCATE = :TRUNCATE
30
+ UPDATE = :UPDATE
31
+
32
+ KEYWORDS = {
33
+ 2 => [AS, OR],
34
+ 3 => [SET],
35
+ 4 => [CALL, FROM, INTO],
36
+ 5 => [TABLE],
37
+ 6 => [DELETE, INSERT, SELECT, UPDATE],
38
+ 7 => [REPLACE],
39
+ 8 => [TRUNCATE]
40
+ }.freeze
41
+
42
+ KEYWORD_MIN_LENGTH = KEYWORDS.keys.first
43
+ KEYWORD_MAX_LENGTH = KEYWORDS.keys.last
44
+ end
45
+ end
46
+ end
@@ -18,14 +18,13 @@ module ElasticAPM
18
18
  }.freeze
19
19
 
20
20
  FORMAT = '%s%s'
21
- UTF8 = 'UTF-8'
22
21
 
23
22
  def self.cache
24
23
  @cache ||= Util::LruCache.new
25
24
  end
26
25
 
27
26
  def summarize(sql)
28
- sql = sql.encode(UTF8, invalid: :replace, undef: :replace)
27
+ sql = sql.encode('utf-8', invalid: :replace, undef: :replace)
29
28
  self.class.cache[sql] ||=
30
29
  REGEXES.find do |regex, sig|
31
30
  if (match = sql[0...1000].match(regex))
@@ -10,6 +10,7 @@ module ElasticAPM
10
10
  :trace_id, :parent_id, :id, :ensure_parent_id
11
11
 
12
12
  DEFAULT_TYPE = 'custom'
13
+ MUTEX = Mutex.new
13
14
 
14
15
  # rubocop:disable Metrics/ParameterLists
15
16
  def initialize(
@@ -78,21 +79,20 @@ module ElasticAPM
78
79
  # spans
79
80
 
80
81
  def inc_started_spans!
81
- @started_spans += 1
82
- end
83
-
84
- def inc_dropped_spans!
85
- @dropped_spans += 1
86
- end
87
-
88
- def max_spans_reached?
89
- started_spans > config.transaction_max_spans
82
+ MUTEX.synchronize do
83
+ @started_spans += 1
84
+ if @started_spans > config.transaction_max_spans
85
+ @dropped_spans += 1
86
+ return false
87
+ end
88
+ end
89
+ true
90
90
  end
91
91
 
92
92
  # context
93
93
 
94
- def add_response(*args)
95
- context.response = Context::Response.new(*args)
94
+ def add_response(status = nil, **args)
95
+ context.response = Context::Response.new(status, **args)
96
96
  end
97
97
 
98
98
  def set_user(user)
@@ -62,8 +62,8 @@ module ElasticAPM
62
62
  end
63
63
  end
64
64
 
65
- def self.pipe(*args)
66
- pipe = new(*args)
65
+ def self.pipe(**args)
66
+ pipe = new(**args)
67
67
  [pipe.read, pipe.write]
68
68
  end
69
69
  end
@@ -55,6 +55,10 @@ module ElasticAPM
55
55
  headers[:Authorization] = "Bearer #{token}"
56
56
  end
57
57
 
58
+ if (api_key = @config.api_key)
59
+ headers[:Authorization] = "ApiKey #{api_key}"
60
+ end
61
+
58
62
  headers
59
63
  end
60
64
  end
@@ -12,6 +12,7 @@ module ElasticAPM
12
12
  end
13
13
 
14
14
  attr_reader :context_serializer
15
+
15
16
  def build(span)
16
17
  {
17
18
  span: {
@@ -31,20 +32,28 @@ module ElasticAPM
31
32
 
32
33
  # @api private
33
34
  class ContextSerializer < Serializer
35
+ # rubocop:disable Metrics/CyclomaticComplexity
34
36
  def build(context)
35
37
  return unless context
36
38
 
37
- { sync: context.sync }.tap do |base|
38
- base[:db] = build_db(context.db) if context.db
39
- base[:http] = build_http(context.http) if context.http
39
+ base = {}
40
+
41
+ base[:tags] = mixed_object(context.labels) if context.labels.any?
42
+ base[:sync] = context.sync unless context.sync.nil?
43
+ base[:db] = build_db(context.db) if context.db
44
+ base[:http] = build_http(context.http) if context.http
45
+
46
+ if context.destination
47
+ base[:destination] = build_destination(context.destination)
40
48
  end
49
+
50
+ base
41
51
  end
52
+ # rubocop:enable Metrics/CyclomaticComplexity
42
53
 
43
54
  private
44
55
 
45
56
  def build_db(db)
46
- return unless db
47
-
48
57
  {
49
58
  instance: db.instance,
50
59
  statement: Util.truncate(db.statement, max_length: 10_000),
@@ -54,14 +63,22 @@ module ElasticAPM
54
63
  end
55
64
 
56
65
  def build_http(http)
57
- return unless http
58
-
59
66
  {
60
67
  url: http.url,
61
68
  status_code: http.status_code.to_i,
62
69
  method: keyword_field(http.method)
63
70
  }
64
71
  end
72
+
73
+ def build_destination(destination)
74
+ {
75
+ service: {
76
+ name: keyword_field(destination.name),
77
+ resource: keyword_field(destination.resource),
78
+ type: keyword_field(destination.type)
79
+ }
80
+ }
81
+ end
65
82
  end
66
83
 
67
84
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElasticAPM
4
- VERSION = '3.3.0'
4
+ VERSION = '3.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-05 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -59,7 +59,9 @@ files:
59
59
  - ".ci/jobs/defaults.yml"
60
60
  - ".ci/linting.groovy"
61
61
  - ".ci/prepare-git-context.sh"
62
- - ".github/workflows/main.yml"
62
+ - ".github/ISSUE_TEMPLATE/Bug_report.md"
63
+ - ".github/ISSUE_TEMPLATE/Feature_request.md"
64
+ - ".github/PULL_REQUEST_TEMPLATE.md"
63
65
  - ".gitignore"
64
66
  - ".pre-commit-config.yaml"
65
67
  - ".rspec"
@@ -78,6 +80,7 @@ files:
78
80
  - bench/benchmark.rb
79
81
  - bench/report.rb
80
82
  - bench/rubyprof.rb
83
+ - bench/sql.rb
81
84
  - bench/stackprof.rb
82
85
  - bench/tmp/.gitkeep
83
86
  - bin/build_docs
@@ -86,6 +89,7 @@ files:
86
89
  - bin/run-tests
87
90
  - bin/setup
88
91
  - bin/with_framework
92
+ - codecov.yml
89
93
  - docker-compose.yml
90
94
  - docs/advanced.asciidoc
91
95
  - docs/api.asciidoc
@@ -162,6 +166,9 @@ files:
162
166
  - lib/elastic_apm/sinatra.rb
163
167
  - lib/elastic_apm/span.rb
164
168
  - lib/elastic_apm/span/context.rb
169
+ - lib/elastic_apm/span/context/db.rb
170
+ - lib/elastic_apm/span/context/destination.rb
171
+ - lib/elastic_apm/span/context/http.rb
165
172
  - lib/elastic_apm/span_helpers.rb
166
173
  - lib/elastic_apm/spies.rb
167
174
  - lib/elastic_apm/spies/action_dispatch.rb
@@ -175,9 +182,15 @@ files:
175
182
  - lib/elastic_apm/spies/rake.rb
176
183
  - lib/elastic_apm/spies/redis.rb
177
184
  - lib/elastic_apm/spies/sequel.rb
185
+ - lib/elastic_apm/spies/shoryuken.rb
178
186
  - lib/elastic_apm/spies/sidekiq.rb
179
187
  - lib/elastic_apm/spies/sinatra.rb
188
+ - lib/elastic_apm/spies/sneakers.rb
180
189
  - lib/elastic_apm/spies/tilt.rb
190
+ - lib/elastic_apm/sql.rb
191
+ - lib/elastic_apm/sql/signature.rb
192
+ - lib/elastic_apm/sql/tokenizer.rb
193
+ - lib/elastic_apm/sql/tokens.rb
181
194
  - lib/elastic_apm/sql_summarizer.rb
182
195
  - lib/elastic_apm/stacktrace.rb
183
196
  - lib/elastic_apm/stacktrace/frame.rb
@@ -1,14 +0,0 @@
1
- name: Lint
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
- name: Rubocop
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v1
11
- - name: Rubocop checks
12
- uses: mikker/rubocop-action@master
13
- env:
14
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}