aspecto-opentelemetry-instrumentation-aws_sdk 0.1.7 → 0.4.1

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: a86c4c6fbaab797ffa640c003796e15aa76ef4f3d89ceabe77c68ecda81d3f61
4
- data.tar.gz: d083d4e406da3673a4b7e355c5bdb1f27a404f7e0cfdaf16c7997f66a93788cc
3
+ metadata.gz: 738e00b5912b370afbd292ec6b1e526fa36d0ef2cc9f4632a8a92a81152011ed
4
+ data.tar.gz: dd277f0de439f4a0dc74b255da0d9354920dceabfdd3de1882451a5c4fb1adff
5
5
  SHA512:
6
- metadata.gz: abf2b797bdadaa5024b02424ceb15fab0b05bb64ddab85f26025cf2c9519873e910a2d1ef8bcabdcd051ee7f292c8afca0a2356ed84d054de2d71f067529b535
7
- data.tar.gz: a318c1bc59465a3aafe5059746860f2effaa1404343ddf5955a3e0a5891e61f815a410e9d073afb016d2d0f0fa755cc6e167aa315468afd055cf3ed0ce415121
6
+ metadata.gz: ce269d02df853545d3e94cb896e1757f69fb1e530cebc0997cb6f1fc44cdc2f6347bdf93079ada68c95b8e758e0faa5ff1a0dc56417d3dada28f5c6b65ae7811
7
+ data.tar.gz: 016a76bd722014e1ac1b3bcca0e1c2b2fbea314ddfa7c33dbdca27e590c30483151c2e4c35fbdabc198ebf1f62fdbcd63d7e952723c0f98229a2d9ce36b3c6a0
data/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
- # Release History: opentelemetry-instrumentation-aws_sdk
1
+ # Release History: opentelemetry-instrumentation-aws_sdk
2
+
3
+ ### v0.2.3 / 2022-05-02
4
+
5
+ * FIXED: RubyGems Fallback
6
+
7
+ ### v0.2.2 / 2022-01-26
8
+
9
+ * (No significant changes)
10
+
11
+ ### v0.2.1 / 2022-01-21
12
+
13
+ * ADDED: attach HTTP status code to AWS spans
14
+
15
+ ### v0.2.0 / 2022-01-20
16
+
17
+ * ADDED: SQS / SNS messaging attributes and context propagation
2
18
 
3
19
  ### v0.1.0 / 2021-12-01
4
20
 
data/README.md CHANGED
@@ -20,6 +20,7 @@ To install the instrumentation, call `use` with the name of the instrumentation.
20
20
  OpenTelemetry::SDK.configure do |c|
21
21
  c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
22
22
  inject_messaging_context: true,
23
+ extract_messaging_context: true,
23
24
  suppress_internal_instrumentation: true
24
25
  }
25
26
  end
@@ -17,7 +17,7 @@ module OpenTelemetry
17
17
  def call(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
18
18
  return super unless context
19
19
 
20
- service_name = context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
20
+ service_name = service_name(context)
21
21
  operation = context.operation&.name
22
22
  client_method = "#{service_name}.#{operation}"
23
23
  attributes = {
@@ -30,17 +30,24 @@ module OpenTelemetry
30
30
  MessagingHelper.apply_sqs_attributes(attributes, context, client_method) if service_name == 'SQS'
31
31
  MessagingHelper.apply_sns_attributes(attributes, context, client_method) if service_name == 'SNS'
32
32
 
33
+ prepare_extract_context(context, client_method)
33
34
  tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(client_method)) do |span|
34
35
  inject_context(context, client_method)
36
+
35
37
  if instrumentation_config[:suppress_internal_instrumentation]
36
38
  OpenTelemetry::Common::Utilities.untraced { super }
37
39
  else
38
40
  super
39
41
  end.tap do |response|
42
+ span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE,
43
+ context.http_response.status_code)
44
+
40
45
  if (err = response.error)
41
46
  span.record_exception(err)
42
47
  span.status = Trace::Status.error(err.to_s)
43
48
  end
49
+
50
+ MessagingHelper.create_sqs_processing_spans(context, tracer, response.messages) if instrumentation_config[:extract_messaging_context] && client_method == SQS_RECEIVE_MESSAGE && response.respond_to?(:messages)
44
51
  end
45
52
  end
46
53
  end
@@ -55,8 +62,16 @@ module OpenTelemetry
55
62
  AwsSdk::Instrumentation.instance.config
56
63
  end
57
64
 
65
+ def service_name(context) # rubocop:disable Metrics/AbcSize
66
+ # Support aws-sdk v2.0.x, which 'metadata' has a setter method only
67
+ return context.client.class.to_s.split('::')[1] if ::Seahorse::Model::Api.instance_method(:metadata).parameters.length.positive?
68
+
69
+ context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
70
+ end
71
+
72
+ SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze
58
73
  def inject_context(context, client_method)
59
- return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
74
+ return unless SEND_MESSAGE_CLIENT_METHODS.include? client_method
60
75
  return unless instrumentation_config[:inject_messaging_context]
61
76
 
62
77
  if client_method == SQS_SEND_MESSAGE_BATCH
@@ -70,6 +85,13 @@ module OpenTelemetry
70
85
  end
71
86
  end
72
87
 
88
+ def prepare_extract_context(context, client_method)
89
+ return unless client_method == SQS_RECEIVE_MESSAGE
90
+ return unless instrumentation_config[:extract_messaging_context]
91
+
92
+ context.params[:message_attribute_names] = ['All']
93
+ end
94
+
73
95
  def span_kind(client_method)
74
96
  case client_method
75
97
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
@@ -84,9 +106,9 @@ module OpenTelemetry
84
106
  def span_name(context, client_method)
85
107
  case client_method
86
108
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
87
- "#{MessagingHelper.queue_name(context)} send"
109
+ "#{MessagingHelper.destination_name(context)} send"
88
110
  when SQS_RECEIVE_MESSAGE
89
- "#{MessagingHelper.queue_name(context)} receive"
111
+ "#{MessagingHelper.destination_name(context)} receive"
90
112
  else
91
113
  client_method
92
114
  end
@@ -9,7 +9,7 @@ module OpenTelemetry
9
9
  module AwsSdk
10
10
  # Instrumentation class that detects and installs the AwsSdk instrumentation
11
11
  class Instrumentation < OpenTelemetry::Instrumentation::Base
12
- MINIMUM_VERSION = Gem::Version.new('2.1')
12
+ MINIMUM_VERSION = Gem::Version.new('2.0.0')
13
13
 
14
14
  install do |_config|
15
15
  require_dependencies
@@ -21,9 +21,10 @@ module OpenTelemetry
21
21
  end
22
22
 
23
23
  compatible do
24
- gem_version >= MINIMUM_VERSION
24
+ !gem_version.nil? && gem_version >= MINIMUM_VERSION
25
25
  end
26
26
 
27
+ option :extract_messaging_context, default: false, validate: :boolean
27
28
  option :inject_messaging_context, default: false, validate: :boolean
28
29
  option :suppress_internal_instrumentation, default: false, validate: :boolean
29
30
 
@@ -32,6 +33,8 @@ module OpenTelemetry
32
33
  Gem.loaded_specs['aws-sdk'].version
33
34
  elsif Gem.loaded_specs['aws-sdk-core']
34
35
  Gem.loaded_specs['aws-sdk-core'].version
36
+ elsif defined?(::Aws::CORE_GEM_VERSION)
37
+ Gem::Version.new(::Aws::CORE_GEM_VERSION)
35
38
  end
36
39
  end
37
40
 
@@ -26,10 +26,10 @@ module OpenTelemetry
26
26
  # The MessageAttributeGetter class provides methods for getting tracing information from SQS message.
27
27
  #
28
28
  # @example
29
- # OpenTelemetry.propagation.extract(message, getter: MessageAttributeGetter)
29
+ # OpenTelemetry.propagation.extract(message.message_attributes, getter: MessageAttributeGetter)
30
30
  class MessageAttributeGetter
31
31
  def self.get(carrier, key)
32
- return carrier[key][:string_value] if carrier[key][:data_type] == 'String'
32
+ return carrier&.[](key)&.[]('string_value') if carrier&.[](key)&.[]('data_type') == 'String'
33
33
  end
34
34
  end
35
35
  end
@@ -10,23 +10,19 @@ module OpenTelemetry
10
10
  # MessagingHelper class provides methods for calculating messaging span attributes
11
11
  class MessagingHelper
12
12
  class << self
13
- def queue_name(context) # rubocop:disable Metrics/CyclomaticComplexity
13
+ def destination_name(context)
14
14
  topic_arn = context.params[:topic_arn]
15
15
  target_arn = context.params[:target_arn]
16
- phone_number = context.params[:phone_number]
17
- queue_url = context.params[:queue_url]
18
16
 
19
17
  if topic_arn || target_arn
20
18
  arn = topic_arn || target_arn
21
- begin
22
- return arn.split(':')[-1]
23
- rescue StandardError
24
- return arn
25
- end
19
+ return arn.split(':')[-1]
26
20
  end
27
21
 
22
+ phone_number = context.params[:phone_number]
28
23
  return 'phone_number' if phone_number
29
24
 
25
+ queue_url = context.params[:queue_url]
30
26
  return queue_url.split('/')[-1] if queue_url
31
27
 
32
28
  'unknown'
@@ -35,8 +31,8 @@ module OpenTelemetry
35
31
  def apply_sqs_attributes(attributes, context, client_method)
36
32
  attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
37
33
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
38
- attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
39
- attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url]
34
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = destination_name(context)
35
+ attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url] if context.params[:queue_url]
40
36
 
41
37
  attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
42
38
  end
@@ -47,7 +43,29 @@ module OpenTelemetry
47
43
  return unless client_method == 'SNS.Publish'
48
44
 
49
45
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
50
- attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
46
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = destination_name(context)
47
+ end
48
+
49
+ def create_sqs_processing_spans(context, tracer, messages)
50
+ queue_name = destination_name(context)
51
+ messages.each do |message|
52
+ attributes = {
53
+ SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sqs',
54
+ SemanticConventions::Trace::MESSAGING_DESTINATION => queue_name,
55
+ SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue',
56
+ SemanticConventions::Trace::MESSAGING_MESSAGE_ID => message.message_id,
57
+ SemanticConventions::Trace::MESSAGING_URL => context.params[:queue_url],
58
+ SemanticConventions::Trace::MESSAGING_OPERATION => 'process'
59
+ }
60
+ tracer.in_span("#{queue_name} process", attributes: attributes, links: extract_links(message), kind: :consumer) {}
61
+ end
62
+ end
63
+
64
+ def extract_links(sqs_message)
65
+ extracted_context = OpenTelemetry.propagation.extract(sqs_message.message_attributes, context: Context::ROOT, getter: MessageAttributeGetter)
66
+ span_context = OpenTelemetry::Trace.current_span(extracted_context).context
67
+
68
+ span_context.valid? ? [OpenTelemetry::Trace::Link.new(span_context)] : []
51
69
  end
52
70
  end
53
71
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.1.7'
10
+ VERSION = '0.4.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspecto-opentelemetry-instrumentation-aws_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
- - Aspecto Authors
8
- autorequire:
7
+ - OpenTelemetry Authors
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.19.0
33
+ version: 0.21.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.19.0
40
+ version: 0.21.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '1.1'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.0'
110
+ version: '1.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: opentelemetry-test-helpers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -222,7 +236,7 @@ dependencies:
222
236
  version: 0.1.6
223
237
  description: AWS SDK instrumentation for the OpenTelemetry framework
224
238
  email:
225
- - info@aspecto.io
239
+ - cncf-opentelemetry-contributors@lists.cncf.io
226
240
  executables: []
227
241
  extensions: []
228
242
  extra_rdoc_files: []
@@ -240,15 +254,15 @@ files:
240
254
  - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
241
255
  - lib/opentelemetry/instrumentation/aws_sdk/services.rb
242
256
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
243
- homepage: https://aspecto.io
257
+ homepage: https://github.com/open-telemetry/opentelemetry-ruby
244
258
  licenses:
245
259
  - Apache-2.0
246
260
  metadata:
247
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.7/file.CHANGELOG.html
261
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.4.1/file.CHANGELOG.html
248
262
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
249
263
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
250
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.7
251
- post_install_message:
264
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.4.1
265
+ post_install_message:
252
266
  rdoc_options: []
253
267
  require_paths:
254
268
  - lib
@@ -256,15 +270,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
256
270
  requirements:
257
271
  - - ">="
258
272
  - !ruby/object:Gem::Version
259
- version: 2.5.0
273
+ version: 2.6.0
260
274
  required_rubygems_version: !ruby/object:Gem::Requirement
261
275
  requirements:
262
276
  - - ">="
263
277
  - !ruby/object:Gem::Version
264
278
  version: '0'
265
279
  requirements: []
266
- rubygems_version: 3.0.3
267
- signing_key:
280
+ rubygems_version: 3.1.4
281
+ signing_key:
268
282
  specification_version: 4
269
283
  summary: AWS SDK instrumentation for the OpenTelemetry framework
270
284
  test_files: []