elastic-apm 3.6.0 → 3.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/Jenkinsfile +183 -100
  3. data/.ci/jobs/defaults.yml +1 -1
  4. data/.ci/packer_cache.sh +12 -10
  5. data/.rspec +0 -1
  6. data/.rubocop.yml +3 -0
  7. data/CHANGELOG.asciidoc +84 -0
  8. data/Gemfile +22 -1
  9. data/Rakefile +28 -1
  10. data/bin/run-tests +4 -1
  11. data/docker-compose.yml +2 -0
  12. data/docs/configuration.asciidoc +117 -16
  13. data/docs/debugging.asciidoc +14 -0
  14. data/docs/getting-started-rails.asciidoc +2 -0
  15. data/docs/images/dynamic-config.svg +1 -0
  16. data/docs/index.asciidoc +2 -1
  17. data/docs/introduction.asciidoc +2 -1
  18. data/docs/performance-tuning.asciidoc +106 -0
  19. data/docs/set-up.asciidoc +5 -2
  20. data/docs/supported-technologies.asciidoc +18 -1
  21. data/elastic-apm.gemspec +17 -0
  22. data/lib/elastic-apm.rb +17 -0
  23. data/lib/elastic_apm.rb +18 -1
  24. data/lib/elastic_apm/agent.rb +48 -2
  25. data/lib/elastic_apm/central_config.rb +27 -8
  26. data/lib/elastic_apm/central_config/cache_control.rb +17 -0
  27. data/lib/elastic_apm/child_durations.rb +17 -0
  28. data/lib/elastic_apm/config.rb +52 -2
  29. data/lib/elastic_apm/config/bytes.rb +17 -0
  30. data/lib/elastic_apm/config/duration.rb +17 -0
  31. data/lib/elastic_apm/config/options.rb +18 -1
  32. data/lib/elastic_apm/config/regexp_list.rb +17 -0
  33. data/lib/elastic_apm/config/wildcard_pattern_list.rb +28 -1
  34. data/lib/elastic_apm/context.rb +17 -0
  35. data/lib/elastic_apm/context/request.rb +17 -0
  36. data/lib/elastic_apm/context/request/socket.rb +17 -0
  37. data/lib/elastic_apm/context/request/url.rb +17 -0
  38. data/lib/elastic_apm/context/response.rb +17 -0
  39. data/lib/elastic_apm/context/user.rb +17 -0
  40. data/lib/elastic_apm/context_builder.rb +18 -1
  41. data/lib/elastic_apm/deprecations.rb +17 -0
  42. data/lib/elastic_apm/error.rb +17 -0
  43. data/lib/elastic_apm/error/exception.rb +17 -0
  44. data/lib/elastic_apm/error/log.rb +17 -0
  45. data/lib/elastic_apm/error_builder.rb +17 -0
  46. data/lib/elastic_apm/grape.rb +17 -0
  47. data/lib/elastic_apm/graphql.rb +17 -0
  48. data/lib/elastic_apm/grpc.rb +19 -2
  49. data/lib/elastic_apm/instrumenter.rb +29 -4
  50. data/lib/elastic_apm/internal_error.rb +17 -0
  51. data/lib/elastic_apm/logging.rb +17 -0
  52. data/lib/elastic_apm/metadata.rb +17 -0
  53. data/lib/elastic_apm/metadata/process_info.rb +17 -0
  54. data/lib/elastic_apm/metadata/service_info.rb +22 -2
  55. data/lib/elastic_apm/metadata/system_info.rb +22 -3
  56. data/lib/elastic_apm/metadata/system_info/container_info.rb +45 -4
  57. data/lib/elastic_apm/metrics.rb +33 -1
  58. data/lib/elastic_apm/metrics/breakdown_set.rb +17 -0
  59. data/lib/elastic_apm/metrics/cpu_mem_set.rb +17 -0
  60. data/lib/elastic_apm/metrics/metric.rb +17 -0
  61. data/lib/elastic_apm/metrics/set.rb +17 -0
  62. data/lib/elastic_apm/metrics/span_scoped_set.rb +17 -0
  63. data/lib/elastic_apm/metrics/transaction_set.rb +17 -0
  64. data/lib/elastic_apm/metrics/vm_set.rb +17 -0
  65. data/lib/elastic_apm/metricset.rb +17 -0
  66. data/lib/elastic_apm/middleware.rb +25 -2
  67. data/lib/elastic_apm/naively_hashable.rb +17 -0
  68. data/lib/elastic_apm/normalizers.rb +17 -0
  69. data/lib/elastic_apm/normalizers/grape.rb +17 -0
  70. data/lib/elastic_apm/normalizers/grape/endpoint_run.rb +18 -1
  71. data/lib/elastic_apm/normalizers/rails.rb +17 -0
  72. data/lib/elastic_apm/normalizers/rails/action_controller.rb +17 -0
  73. data/lib/elastic_apm/normalizers/rails/action_mailer.rb +17 -0
  74. data/lib/elastic_apm/normalizers/rails/action_view.rb +17 -0
  75. data/lib/elastic_apm/normalizers/rails/active_record.rb +17 -0
  76. data/lib/elastic_apm/opentracing.rb +64 -23
  77. data/lib/elastic_apm/rails.rb +17 -0
  78. data/lib/elastic_apm/railtie.rb +17 -0
  79. data/lib/elastic_apm/resque.rb +17 -0
  80. data/lib/elastic_apm/sinatra.rb +17 -0
  81. data/lib/elastic_apm/span.rb +20 -2
  82. data/lib/elastic_apm/span/context.rb +17 -0
  83. data/lib/elastic_apm/span/context/db.rb +17 -0
  84. data/lib/elastic_apm/span/context/destination.rb +17 -0
  85. data/lib/elastic_apm/span/context/http.rb +17 -0
  86. data/lib/elastic_apm/span_helpers.rb +17 -0
  87. data/lib/elastic_apm/spies.rb +33 -14
  88. data/lib/elastic_apm/spies/action_dispatch.rb +17 -0
  89. data/lib/elastic_apm/spies/delayed_job.rb +17 -0
  90. data/lib/elastic_apm/spies/dynamo_db.rb +58 -0
  91. data/lib/elastic_apm/spies/elasticsearch.rb +37 -2
  92. data/lib/elastic_apm/spies/faraday.rb +17 -0
  93. data/lib/elastic_apm/spies/http.rb +17 -0
  94. data/lib/elastic_apm/spies/json.rb +17 -0
  95. data/lib/elastic_apm/spies/mongo.rb +18 -1
  96. data/lib/elastic_apm/spies/net_http.rb +23 -2
  97. data/lib/elastic_apm/spies/rake.rb +17 -0
  98. data/lib/elastic_apm/spies/redis.rb +17 -0
  99. data/lib/elastic_apm/spies/resque.rb +19 -9
  100. data/lib/elastic_apm/spies/sequel.rb +18 -1
  101. data/lib/elastic_apm/spies/shoryuken.rb +17 -0
  102. data/lib/elastic_apm/spies/sidekiq.rb +17 -0
  103. data/lib/elastic_apm/spies/sinatra.rb +17 -0
  104. data/lib/elastic_apm/spies/sneakers.rb +17 -0
  105. data/lib/elastic_apm/spies/sucker_punch.rb +54 -0
  106. data/lib/elastic_apm/spies/tilt.rb +17 -0
  107. data/lib/elastic_apm/sql.rb +17 -0
  108. data/lib/elastic_apm/sql/signature.rb +17 -0
  109. data/lib/elastic_apm/sql/tokenizer.rb +17 -0
  110. data/lib/elastic_apm/sql/tokens.rb +17 -0
  111. data/lib/elastic_apm/sql_summarizer.rb +17 -0
  112. data/lib/elastic_apm/stacktrace.rb +17 -0
  113. data/lib/elastic_apm/stacktrace/frame.rb +17 -0
  114. data/lib/elastic_apm/stacktrace_builder.rb +17 -0
  115. data/lib/elastic_apm/subscriber.rb +17 -0
  116. data/lib/elastic_apm/trace_context.rb +17 -0
  117. data/lib/elastic_apm/trace_context/traceparent.rb +17 -0
  118. data/lib/elastic_apm/trace_context/tracestate.rb +17 -0
  119. data/lib/elastic_apm/transaction.rb +33 -5
  120. data/lib/elastic_apm/transport/base.rb +39 -23
  121. data/lib/elastic_apm/transport/connection.rb +17 -0
  122. data/lib/elastic_apm/transport/connection/http.rb +17 -0
  123. data/lib/elastic_apm/transport/connection/proxy_pipe.rb +22 -0
  124. data/lib/elastic_apm/transport/filters.rb +17 -0
  125. data/lib/elastic_apm/transport/filters/hash_sanitizer.rb +77 -0
  126. data/lib/elastic_apm/transport/filters/secrets_filter.rb +30 -56
  127. data/lib/elastic_apm/transport/headers.rb +17 -0
  128. data/lib/elastic_apm/transport/serializers.rb +17 -0
  129. data/lib/elastic_apm/transport/serializers/context_serializer.rb +17 -0
  130. data/lib/elastic_apm/transport/serializers/error_serializer.rb +17 -0
  131. data/lib/elastic_apm/transport/serializers/metadata_serializer.rb +44 -20
  132. data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +17 -0
  133. data/lib/elastic_apm/transport/serializers/span_serializer.rb +17 -0
  134. data/lib/elastic_apm/transport/serializers/transaction_serializer.rb +17 -0
  135. data/lib/elastic_apm/transport/user_agent.rb +17 -0
  136. data/lib/elastic_apm/transport/worker.rb +21 -0
  137. data/lib/elastic_apm/util.rb +17 -0
  138. data/lib/elastic_apm/util/inflector.rb +17 -0
  139. data/lib/elastic_apm/util/lru_cache.rb +17 -0
  140. data/lib/elastic_apm/util/throttle.rb +17 -0
  141. data/lib/elastic_apm/version.rb +18 -1
  142. metadata +12 -11
  143. data/.ci/downstreamTests.groovy +0 -185
  144. data/.ci/prepare-git-context.sh +0 -27
  145. data/codecov.yml +0 -32
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  #
2
19
  # frozen_string_literal: true
3
20
 
@@ -42,9 +59,15 @@ module ElasticAPM
42
59
  end
43
60
 
44
61
  def path_ignored?(env)
45
- config.ignore_url_patterns.any? do |r|
46
- env['PATH_INFO'].match r
62
+ return true if config.ignore_url_patterns.any? do |r|
63
+ r.match(env['PATH_INFO'])
47
64
  end
65
+
66
+ return true if config.transaction_ignore_urls.any? do |r|
67
+ r.match(env['PATH_INFO'])
68
+ end
69
+
70
+ false
48
71
  end
49
72
 
50
73
  def start_transaction(env)
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM # :nodoc:
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  %w[endpoint_run].each do |lib|
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -33,7 +50,7 @@ module ElasticAPM
33
50
  private
34
51
 
35
52
  def transaction_from_host_app?(transaction)
36
- transaction.config.framework_name != FRAMEWORK_NAME
53
+ transaction.framework_name != FRAMEWORK_NAME
37
54
  end
38
55
 
39
56
  def endpoint(env)
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  %w[
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module ElasticAPM
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'elastic_apm/sql'
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  require 'elastic_apm'
@@ -22,7 +39,7 @@ module ElasticAPM
22
39
  @span_context
23
40
  end
24
41
 
25
- def set_label(key, val)
42
+ def set_tag(key, val)
26
43
  if elastic_span.is_a?(Transaction)
27
44
  case key.to_s
28
45
  when 'type'
@@ -37,6 +54,8 @@ module ElasticAPM
37
54
  else
38
55
  elastic_span.context.labels[key] = val
39
56
  end
57
+
58
+ self
40
59
  end
41
60
 
42
61
  def set_baggage_item(_key, _value)
@@ -61,18 +80,12 @@ module ElasticAPM
61
80
  ElasticAPM.report_message message
62
81
  end
63
82
  end
64
-
65
83
  # rubocop:enable Lint/UnusedMethodArgument
66
- def finish(clock_end: Util.monotonic_micros, end_time: nil)
67
- return unless (agent = ElasticAPM.agent)
68
84
 
69
- if end_time
70
- warn '[ElasticAPM] DEPRECATED: Setting a custom end time as a ' \
71
- '`Time` is deprecated. Use `clock_end:` and monotonic time instead.'
72
- clock_end = end_time
73
- end
85
+ def finish(end_time: Time.now)
86
+ return unless (agent = ElasticAPM.agent)
74
87
 
75
- elastic_span.done clock_end: clock_end
88
+ elastic_span.done clock_end: Util.micros(end_time)
76
89
 
77
90
  case elastic_span
78
91
  when ElasticAPM::Transaction
@@ -97,6 +110,8 @@ module ElasticAPM
97
110
 
98
111
  # @api private
99
112
  class SpanContext
113
+ extend Forwardable
114
+
100
115
  def initialize(trace_context:, baggage: nil)
101
116
  if baggage
102
117
  ElasticAPM.agent.config.logger.warn(
@@ -108,10 +123,27 @@ module ElasticAPM
108
123
  end
109
124
 
110
125
  attr_accessor :trace_context
126
+ def_delegators :trace_context, :trace_id, :id, :parent_id
127
+
128
+ def self.from_header(header)
129
+ return unless header
130
+
131
+ trace_context = ElasticAPM::TraceContext.parse(header)
132
+ return unless trace_context
133
+
134
+ trace_context.traceparent.id = trace_context.parent_id
135
+ trace_context.traceparent.parent_id = nil
136
+
137
+ from_trace_context(trace_context)
138
+ end
111
139
 
112
140
  def self.from_trace_context(trace_context)
113
141
  new(trace_context: trace_context)
114
142
  end
143
+
144
+ def child
145
+ self.class.from_trace_context(trace_context.child)
146
+ end
115
147
  end
116
148
 
117
149
  # @api private
@@ -193,7 +225,7 @@ module ElasticAPM
193
225
  child_of: nil,
194
226
  references: nil,
195
227
  start_time: Time.now,
196
- labels: {},
228
+ tags: {},
197
229
  ignore_active_scope: false,
198
230
  finish_on_close: true,
199
231
  **
@@ -203,14 +235,14 @@ module ElasticAPM
203
235
  child_of: child_of,
204
236
  references: references,
205
237
  start_time: start_time,
206
- labels: labels,
238
+ tags: tags,
207
239
  ignore_active_scope: ignore_active_scope
208
240
  )
209
241
  scope = scope_manager.activate(span, finish_on_close: finish_on_close)
210
242
 
211
243
  if block_given?
212
244
  begin
213
- yield scope
245
+ return yield scope
214
246
  ensure
215
247
  scope.close
216
248
  end
@@ -226,7 +258,7 @@ module ElasticAPM
226
258
  child_of: nil,
227
259
  references: nil,
228
260
  start_time: Time.now,
229
- labels: {},
261
+ tags: {},
230
262
  ignore_active_scope: false,
231
263
  **
232
264
  )
@@ -263,7 +295,7 @@ module ElasticAPM
263
295
  span_context ||=
264
296
  SpanContext.from_trace_context(elastic_span.trace_context)
265
297
 
266
- labels.each do |key, value|
298
+ tags.each do |key, value|
267
299
  elastic_span.context.labels[key] = value
268
300
  end
269
301
 
@@ -276,7 +308,7 @@ module ElasticAPM
276
308
 
277
309
  def inject(span_context, format, carrier)
278
310
  case format
279
- when ::OpenTracing::FORMAT_RACK
311
+ when ::OpenTracing::FORMAT_RACK, ::OpenTracing::FORMAT_TEXT_MAP
280
312
  carrier['elastic-apm-traceparent'] =
281
313
  span_context.traceparent.to_header
282
314
  else
@@ -287,10 +319,16 @@ module ElasticAPM
287
319
  def extract(format, carrier)
288
320
  case format
289
321
  when ::OpenTracing::FORMAT_RACK
290
- ElasticAPM::TraceContext
291
- .parse(carrier['HTTP_ELASTIC_APM_TRACEPARENT'])
322
+ SpanContext.from_header(
323
+ carrier['HTTP_ELASTIC_APM_TRACEPARENT']
324
+ )
325
+ when ::OpenTracing::FORMAT_TEXT_MAP
326
+ SpanContext.from_header(
327
+ carrier['elastic-apm-traceparent']
328
+ )
292
329
  else
293
- warn 'Only extraction from HTTP headers via Rack is available'
330
+ warn 'Only extraction from HTTP headers via Rack or in ' \
331
+ 'text map format are available'
294
332
  nil
295
333
  end
296
334
  rescue ElasticAPM::TraceContext::InvalidTraceparentHeader
@@ -304,9 +342,12 @@ module ElasticAPM
304
342
  references:,
305
343
  ignore_active_scope:
306
344
  )
307
- context_from_child_of(child_of) ||
308
- context_from_references(references) ||
309
- context_from_active_scope(ignore_active_scope)
345
+ context = context_from_child_of(child_of) ||
346
+ context_from_references(references) ||
347
+ context_from_active_scope(ignore_active_scope)
348
+ return context.child if context&.respond_to?(:child)
349
+
350
+ context
310
351
  end
311
352
 
312
353
  def context_from_child_of(child_of)
@@ -327,7 +368,7 @@ module ElasticAPM
327
368
  def context_from_active_scope(ignore_active_scope)
328
369
  if ignore_active_scope
329
370
  ElasticAPM.agent&.config&.logger&.warn(
330
- 'ignore_active_scope might lead to unexpeced results'
371
+ 'ignore_active_scope might lead to unexpected results'
331
372
  )
332
373
  return
333
374
  end