aspecto-opentelemetry-instrumentation-aws_sdk 0.1.7 → 0.1.8

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: fd22dbff8fc844572b0134bc017e7202b7b0a0b117b3eceab65249449493d57e
4
+ data.tar.gz: c9466be404ec13f25017f7db758819500ae4f109ad2826923d86907ce72ba13a
5
5
  SHA512:
6
- metadata.gz: abf2b797bdadaa5024b02424ceb15fab0b05bb64ddab85f26025cf2c9519873e910a2d1ef8bcabdcd051ee7f292c8afca0a2356ed84d054de2d71f067529b535
7
- data.tar.gz: a318c1bc59465a3aafe5059746860f2effaa1404343ddf5955a3e0a5891e61f815a410e9d073afb016d2d0f0fa755cc6e167aa315468afd055cf3ed0ce415121
6
+ metadata.gz: 1337b7ad6217685438f65de8655865f2f699b3ac12c7cd17d78e292f8fade4afddbfe1e7ee35e974abd4645e042d6209b2fc52fdda4e1291b2ca61ae6d129eb4
7
+ data.tar.gz: 03fb4f63e6b7a485b6acd925e351d6d289ccdcc008b891f584662830d21c3a0900b03e41a7fc1575e436d003309a8bebdf1b548a499242e9e903ad3ea020f91e
data/README.md CHANGED
@@ -19,6 +19,7 @@ To install the instrumentation, call `use` with the name of the instrumentation.
19
19
  ```ruby
20
20
  OpenTelemetry::SDK.configure do |c|
21
21
  c.use 'OpenTelemetry::Instrumentation::AwsSdk', {
22
+ extract_messaging_context: true,
22
23
  inject_messaging_context: true,
23
24
  suppress_internal_instrumentation: true
24
25
  }
@@ -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 = context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1] rescue context.client.class.to_s.split('::')[1] # rubocop:disable Style/RescueModifier
21
21
  operation = context.operation&.name
22
22
  client_method = "#{service_name}.#{operation}"
23
23
  attributes = {
@@ -30,8 +30,10 @@ 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
@@ -41,6 +43,8 @@ module OpenTelemetry
41
43
  span.record_exception(err)
42
44
  span.status = Trace::Status.error(err.to_s)
43
45
  end
46
+
47
+ MessagingHelper.create_sqs_processing_spans(context, tracer, response.messages) if client_method == SQS_RECEIVE_MESSAGE && response.respond_to?(:messages)
44
48
  end
45
49
  end
46
50
  end
@@ -70,6 +74,13 @@ module OpenTelemetry
70
74
  end
71
75
  end
72
76
 
77
+ def prepare_extract_context(context, client_method)
78
+ return unless client_method == SQS_RECEIVE_MESSAGE
79
+ return unless instrumentation_config[:extract_messaging_context]
80
+
81
+ context.params[:message_attribute_names] = ['All']
82
+ end
83
+
73
84
  def span_kind(client_method)
74
85
  case client_method
75
86
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
@@ -84,9 +95,9 @@ module OpenTelemetry
84
95
  def span_name(context, client_method)
85
96
  case client_method
86
97
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
87
- "#{MessagingHelper.queue_name(context)} send"
98
+ "#{MessagingHelper.destination_name(context)} send"
88
99
  when SQS_RECEIVE_MESSAGE
89
- "#{MessagingHelper.queue_name(context)} receive"
100
+ "#{MessagingHelper.destination_name(context)} receive"
90
101
  else
91
102
  client_method
92
103
  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')
13
13
 
14
14
  install do |_config|
15
15
  require_dependencies
@@ -24,6 +24,7 @@ module OpenTelemetry
24
24
  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
 
@@ -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,7 +10,7 @@ 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) # rubocop:disable Metrics/CyclomaticComplexity
14
14
  topic_arn = context.params[:topic_arn]
15
15
  target_arn = context.params[:target_arn]
16
16
  phone_number = context.params[:phone_number]
@@ -35,7 +35,7 @@ module OpenTelemetry
35
35
  def apply_sqs_attributes(attributes, context, client_method)
36
36
  attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
37
37
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
38
- attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
38
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = destination_name(context)
39
39
  attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url]
40
40
 
41
41
  attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
@@ -47,7 +47,29 @@ module OpenTelemetry
47
47
  return unless client_method == 'SNS.Publish'
48
48
 
49
49
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
50
- attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
50
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = destination_name(context)
51
+ end
52
+
53
+ def create_sqs_processing_spans(context, tracer, messages)
54
+ queue_name = destination_name(context)
55
+ messages.each do |message|
56
+ attributes = {
57
+ SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sqs',
58
+ SemanticConventions::Trace::MESSAGING_DESTINATION => queue_name,
59
+ SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue',
60
+ SemanticConventions::Trace::MESSAGING_MESSAGE_ID => message.message_id,
61
+ SemanticConventions::Trace::MESSAGING_URL => context.params[:queue_url],
62
+ SemanticConventions::Trace::MESSAGING_OPERATION => 'process'
63
+ }
64
+ tracer.in_span("#{queue_name} process", attributes: attributes, links: extract_links(message), kind: :consumer) {}
65
+ end
66
+ end
67
+
68
+ def extract_links(sqs_message)
69
+ extracted_context = OpenTelemetry.propagation.extract(sqs_message.message_attributes, context: Context::ROOT, getter: MessageAttributeGetter)
70
+ span_context = OpenTelemetry::Trace.current_span(extracted_context).context
71
+
72
+ span_context.valid? ? [OpenTelemetry::Trace::Link.new(span_context)] : []
51
73
  end
52
74
  end
53
75
  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.1.8'
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.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aspecto Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -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
@@ -244,10 +244,10 @@ homepage: https://aspecto.io
244
244
  licenses:
245
245
  - Apache-2.0
246
246
  metadata:
247
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.7/file.CHANGELOG.html
247
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.8/file.CHANGELOG.html
248
248
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
249
249
  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
250
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.8
251
251
  post_install_message:
252
252
  rdoc_options: []
253
253
  require_paths: