aspecto-opentelemetry-instrumentation-aws_sdk 0.1.4 → 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: 07cea588556e47fdc18637f2eaafbfc925a54fa10b1a5f0e90e3252028512c52
4
- data.tar.gz: 0b77c9ae3b96d84bdc2065fbce499c371d4d03b49789ab862b823cad9907b87b
3
+ metadata.gz: fd22dbff8fc844572b0134bc017e7202b7b0a0b117b3eceab65249449493d57e
4
+ data.tar.gz: c9466be404ec13f25017f7db758819500ae4f109ad2826923d86907ce72ba13a
5
5
  SHA512:
6
- metadata.gz: fd02cdfca52ecec95c992481bc42cb05e4b9568294fe05b279ea3015bbc39b80312be002590cdc68ccbb9f5125c8c80d14240df0b40ad01a847f76268a633ce1
7
- data.tar.gz: 1691f847d0914cb362440813a9f8584d3811303b007cec058ca2b278618d3060ce38fbd32edfd7d30936f654e0090ec8f1d23fc41efd4993ad2827784431adf0
6
+ metadata.gz: 1337b7ad6217685438f65de8655865f2f699b3ac12c7cd17d78e292f8fade4afddbfe1e7ee35e974abd4645e042d6209b2fc52fdda4e1291b2ca61ae6d129eb4
7
+ data.tar.gz: 03fb4f63e6b7a485b6acd925e351d6d289ccdcc008b891f584662830d21c3a0900b03e41a7fc1575e436d003309a8bebdf1b548a499242e9e903ad3ea020f91e
data/CHANGELOG.md CHANGED
@@ -1 +1,5 @@
1
1
  # Release History: opentelemetry-instrumentation-aws_sdk
2
+
3
+ ### v0.1.0 / 2021-12-01
4
+
5
+ * Initial release.
data/README.md CHANGED
@@ -19,6 +19,8 @@ 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,
23
+ inject_messaging_context: true,
22
24
  suppress_internal_instrumentation: true
23
25
  }
24
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 = 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
- tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(service_name, operation)) do |span|
33
+ prepare_extract_context(context, client_method)
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
@@ -57,6 +61,7 @@ module OpenTelemetry
57
61
 
58
62
  def inject_context(context, client_method)
59
63
  return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
64
+ return unless instrumentation_config[:inject_messaging_context]
60
65
 
61
66
  if client_method == SQS_SEND_MESSAGE_BATCH
62
67
  context.params[:entries].each do |entry|
@@ -69,7 +74,14 @@ module OpenTelemetry
69
74
  end
70
75
  end
71
76
 
72
- def span_kind(service_name, client_method)
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
+
84
+ def span_kind(client_method)
73
85
  case client_method
74
86
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
75
87
  OpenTelemetry::Trace::SpanKind::PRODUCER
@@ -83,9 +95,9 @@ module OpenTelemetry
83
95
  def span_name(context, client_method)
84
96
  case client_method
85
97
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
86
- "#{MessagingHelper.queue_name(context)} send"
98
+ "#{MessagingHelper.destination_name(context)} send"
87
99
  when SQS_RECEIVE_MESSAGE
88
- "#{MessagingHelper.queue_name(context)} receive"
100
+ "#{MessagingHelper.destination_name(context)} receive"
89
101
  else
90
102
  client_method
91
103
  end
@@ -24,17 +24,10 @@ module OpenTelemetry
24
24
  gem_version >= MINIMUM_VERSION
25
25
  end
26
26
 
27
+ option :extract_messaging_context, default: false, validate: :boolean
28
+ option :inject_messaging_context, default: false, validate: :boolean
27
29
  option :suppress_internal_instrumentation, default: false, validate: :boolean
28
30
 
29
- private
30
-
31
- def require_dependencies
32
- require_relative 'handler'
33
- require_relative 'services'
34
- require_relative 'message_attribute_setter'
35
- require_relative 'messaging_helper'
36
- end
37
-
38
31
  def gem_version
39
32
  if Gem.loaded_specs['aws-sdk']
40
33
  Gem.loaded_specs['aws-sdk'].version
@@ -43,6 +36,15 @@ module OpenTelemetry
43
36
  end
44
37
  end
45
38
 
39
+ private
40
+
41
+ def require_dependencies
42
+ require_relative 'handler'
43
+ require_relative 'services'
44
+ require_relative 'message_attributes'
45
+ require_relative 'messaging_helper'
46
+ end
47
+
46
48
  def add_plugin(*targets)
47
49
  targets.each { |klass| klass.add_plugin(AwsSdk::Plugin) }
48
50
  end
@@ -22,6 +22,16 @@ module OpenTelemetry
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ # The MessageAttributeGetter class provides methods for getting tracing information from SQS message.
27
+ #
28
+ # @example
29
+ # OpenTelemetry.propagation.extract(message.message_attributes, getter: MessageAttributeGetter)
30
+ class MessageAttributeGetter
31
+ def self.get(carrier, key)
32
+ return carrier&.[](key)&.[]('string_value') if carrier&.[](key)&.[]('data_type') == 'String'
33
+ end
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -10,11 +10,11 @@ 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
14
- topic_arn = params(context, :topic_arn)
15
- target_arn = params(context, :target_arn)
16
- phone_number = params(context, :phone_number)
17
- queue_url = params(context, :queue_url)
13
+ def destination_name(context) # rubocop:disable Metrics/CyclomaticComplexity
14
+ topic_arn = context.params[:topic_arn]
15
+ target_arn = context.params[:target_arn]
16
+ phone_number = context.params[:phone_number]
17
+ queue_url = context.params[:queue_url]
18
18
 
19
19
  if topic_arn || target_arn
20
20
  arn = topic_arn || target_arn
@@ -25,7 +25,7 @@ module OpenTelemetry
25
25
  end
26
26
  end
27
27
 
28
- return phone_number if phone_number
28
+ return 'phone_number' if phone_number
29
29
 
30
30
  return queue_url.split('/')[-1] if queue_url
31
31
 
@@ -35,8 +35,8 @@ 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)
39
- attributes[SemanticConventions::Trace::MESSAGING_URL] = params(context, :queue_url)
38
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = destination_name(context)
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'
42
42
  end
@@ -47,11 +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
51
  end
52
52
 
53
- def params(context, param)
54
- defined?(context.metadata[:original_params][param]) ? context.metadata[:original_params][param] : context.params[param]
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)] : []
55
73
  end
56
74
  end
57
75
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.1.4'
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.4
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aspecto Authors
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-23 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
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.18.3
33
+ version: 0.19.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.18.3
40
+ version: 0.19.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -236,7 +236,7 @@ files:
236
236
  - lib/opentelemetry/instrumentation/aws_sdk.rb
237
237
  - lib/opentelemetry/instrumentation/aws_sdk/handler.rb
238
238
  - lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
239
- - lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb
239
+ - lib/opentelemetry/instrumentation/aws_sdk/message_attributes.rb
240
240
  - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
241
241
  - lib/opentelemetry/instrumentation/aws_sdk/services.rb
242
242
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
@@ -244,11 +244,11 @@ 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.4/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.4
251
- post_install_message:
250
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.8
251
+ post_install_message:
252
252
  rdoc_options: []
253
253
  require_paths:
254
254
  - lib
@@ -263,8 +263,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  - !ruby/object:Gem::Version
264
264
  version: '0'
265
265
  requirements: []
266
- rubygems_version: 3.2.22
267
- signing_key:
266
+ rubygems_version: 3.0.3
267
+ signing_key:
268
268
  specification_version: 4
269
269
  summary: AWS SDK instrumentation for the OpenTelemetry framework
270
270
  test_files: []