aspecto-opentelemetry-instrumentation-aws_sdk 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c0d66d31a0f6bc5f4fce712eac7a89dd9496bb184e94ef3d8f020d34da908c6
4
- data.tar.gz: 9684ac5b863abddf558f0aa13e4b5f06a66ae84c81eb99362fd99e3906a016b9
3
+ metadata.gz: 8dac418df022dc543ee882cea6830b87325ba92d2adc1be9e5e2d2221ab4e8ee
4
+ data.tar.gz: 6eaebb7d974533635d7215e53244b9865cc6c5d56a44e811d6de1ff9b6d0f608
5
5
  SHA512:
6
- metadata.gz: 01e7d9fdc6def5ba52d4fd6859fe35f1002988d621dd19174cc49e035db0b2e312fef0bb03982f02e850d9dbdb3d14d841a5eda4cf97a7681da2b7a5e2b61f69
7
- data.tar.gz: fcb4db3a7b95b559e9b5afe82962a67e1c50a8b85efa58582d0c6da44698afa5cc95be01c69930983f56b309c3981efba2656497f64b4ba19b797dd7d06b5341
6
+ metadata.gz: b25f6c3b3dc0bfac3a808a2080a2a8ca5024d1c87b04944decac672fac176574da1b4e7ce7f3275708bb43e238fcb497e42ed82d7ec6ad6dec4a18f77ac5ed72
7
+ data.tar.gz: d9e3dab08de91b76ec74909ff3a83096f114d48c03acbb4e493e069528565878e7c2ba5535fe8c97d983d8b87832323635238d2b9f22ba985dc9c6be1fcef764
data/CHANGELOG.md CHANGED
@@ -0,0 +1 @@
1
+ # Release History: opentelemetry-instrumentation-aws_sdk
@@ -14,60 +14,62 @@ module OpenTelemetry
14
14
  SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
15
15
  SNS_PUBLISH = 'SNS.Publish'
16
16
 
17
- def call(context)
18
- span_name = get_span_name(context)
19
- attributes = get_span_attributes(context)
17
+ def call(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
18
+ return super unless context
20
19
 
21
- tracer.in_span(span_name, kind: get_span_kind(context), attributes: attributes) do |span|
22
- execute = proc {
23
- inject_context(context)
24
- super(context).tap do |response|
25
- if (err = response.error)
26
- span.record_exception(err)
27
- span.status = Trace::Status.error(err)
28
- end
29
- end
30
- }
20
+ service_name = context.client.class.to_s.split('::')[1]
21
+ operation = context.operation&.name
22
+ client_method = "#{service_name}.#{operation}"
23
+ attributes = {
24
+ 'aws.region' => context.config.region,
25
+ OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
26
+ OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => operation,
27
+ OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_name
28
+ }
29
+ attributes[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_name == 'DynamoDB'
30
+ MessagingHelper.apply_sqs_attributes(attributes, context, client_method) if service_name == 'SQS'
31
+ MessagingHelper.apply_sns_attributes(attributes, context, client_method) if service_name == 'SNS'
31
32
 
33
+ tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(operation)) do |span|
34
+ inject_context(context, client_method)
32
35
  if instrumentation_config[:suppress_internal_instrumentation]
33
- OpenTelemetry::Common::Utilities.untraced(&execute)
36
+ OpenTelemetry::Common::Utilities.untraced { super }
34
37
  else
35
- execute.call
38
+ super
39
+ end.tap do |response|
40
+ if (err = response.error)
41
+ span.record_exception(err)
42
+ span.status = Trace::Status.error(err.to_s)
43
+ end
36
44
  end
37
45
  end
38
46
  end
39
47
 
40
- def inject_context(context)
41
- client_method = get_client_method(context)
42
- return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
48
+ private
43
49
 
44
- context.params[:message_attributes] ||= {}
45
- OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
50
+ def tracer
51
+ AwsSdk::Instrumentation.instance.tracer
46
52
  end
47
53
 
48
- def get_span_attributes(context)
49
- span_attributes = {
50
- 'aws.region' => context.config.region,
51
- OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
52
- OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => get_operation(context),
53
- OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => get_service_name(context)
54
- }
55
-
56
- messaging_attributes = MessagingHelper.get_messaging_attributes(context, get_service_name(context), get_operation(context))
57
- db_attributes = DbHelper.get_db_attributes(context, get_service_name(context), get_operation(context))
58
- span_attributes.merge(messaging_attributes).merge(db_attributes)
54
+ def instrumentation_config
55
+ AwsSdk::Instrumentation.instance.config
59
56
  end
60
57
 
61
- def get_service_name(context)
62
- context&.client.class.api.metadata['serviceId'] || context&.client.class.to_s.split('::')[1]
63
- end
58
+ def inject_context(context, client_method)
59
+ return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
64
60
 
65
- def get_operation(context)
66
- context&.operation&.name
61
+ if client_method == SQS_SEND_MESSAGE_BATCH
62
+ context.params[:entries].each do |entry|
63
+ entry[:message_attributes] ||= {}
64
+ OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
65
+ end
66
+ else
67
+ context.params[:message_attributes] ||= {}
68
+ OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
69
+ end
67
70
  end
68
71
 
69
- def get_span_kind(context)
70
- client_method = get_client_method(context)
72
+ def span_kind(client_method)
71
73
  case client_method
72
74
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
73
75
  OpenTelemetry::Trace::SpanKind::PRODUCER
@@ -78,29 +80,16 @@ module OpenTelemetry
78
80
  end
79
81
  end
80
82
 
81
- def get_span_name(context)
82
- client_method = get_client_method(context)
83
+ def span_name(context, client_method)
83
84
  case client_method
84
85
  when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
85
- "#{MessagingHelper.get_queue_name(context)} send"
86
+ "#{MessagingHelper.queue_name(context)} send"
86
87
  when SQS_RECEIVE_MESSAGE
87
- "#{MessagingHelper.get_queue_name(context)} receive"
88
+ "#{MessagingHelper.queue_name(context)} receive"
88
89
  else
89
90
  client_method
90
91
  end
91
92
  end
92
-
93
- def get_client_method(context)
94
- "#{get_service_name(context)}.#{get_operation(context)}"
95
- end
96
-
97
- def tracer
98
- AwsSdk::Instrumentation.instance.tracer
99
- end
100
-
101
- def instrumentation_config
102
- AwsSdk::Instrumentation.instance.config
103
- end
104
93
  end
105
94
 
106
95
  # A Seahorse::Client::Plugin that enables instrumentation for all AWS services
@@ -12,12 +12,7 @@ module OpenTelemetry
12
12
  MINIMUM_VERSION = Gem::Version.new('2.0')
13
13
 
14
14
  install do |_config|
15
- require_relative 'handler'
16
- require_relative 'services'
17
- require_relative 'message_attribute_setter'
18
- require_relative 'messaging_helper'
19
- require_relative 'db_helper'
20
-
15
+ require_dependencies
21
16
  add_plugin(Seahorse::Client::Base, *loaded_constants)
22
17
  end
23
18
 
@@ -31,6 +26,15 @@ module OpenTelemetry
31
26
 
32
27
  option :suppress_internal_instrumentation, default: false, validate: :boolean
33
28
 
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
+
34
38
  def gem_version
35
39
  if Gem.loaded_specs['aws-sdk']
36
40
  Gem.loaded_specs['aws-sdk'].version
@@ -10,18 +10,18 @@ module OpenTelemetry
10
10
  # MessagingHelper class provides methods for calculating messaging span attributes
11
11
  class MessagingHelper
12
12
  class << self
13
- def get_queue_name(context)
14
- topic_arn = context.metadata[:original_params][:topic_arn]
15
- target_arn = context.metadata[:original_params][:target_arn]
16
- phone_number = context.metadata[:original_params][:phone_number]
17
- queue_url = context.metadata[:original_params][:queue_url]
13
+ def queue_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
21
21
  begin
22
- arn.split(':')[-1]
22
+ return arn.split(':')[-1]
23
23
  rescue StandardError
24
- arn
24
+ return arn
25
25
  end
26
26
  end
27
27
 
@@ -32,36 +32,22 @@ module OpenTelemetry
32
32
  'unknown'
33
33
  end
34
34
 
35
- def get_messaging_attributes(context, service_name, operation)
36
- return get_sns_attributes(context, operation) if service_name == 'SNS'
37
- return get_sqs_attributes(context, operation) if service_name == 'SQS'
38
- {}
39
- end
40
-
41
- def get_sqs_attributes(context, operation)
42
- sqs_attributes = {
43
- SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sqs',
44
- SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue',
45
- SemanticConventions::Trace::MESSAGING_DESTINATION => get_queue_name(context),
46
- SemanticConventions::Trace::MESSAGING_URL => context.metadata[:original_params][:queue_url]
47
- }
35
+ def apply_sqs_attributes(attributes, context, client_method)
36
+ attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
37
+ 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]
48
40
 
49
- sqs_attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if operation == 'ReceiveMessage'
50
-
51
- sqs_attributes
41
+ attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
52
42
  end
53
43
 
54
- def get_sns_attributes(context, operation)
55
- sns_attributes = {
56
- SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sns'
57
- }
44
+ def apply_sns_attributes(attributes, context, client_method)
45
+ attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
58
46
 
59
- if operation == 'Publish'
60
- sns_attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
61
- sns_attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = get_queue_name(context)
62
- end
47
+ return unless client_method == 'SNS.Publish'
63
48
 
64
- sns_attributes
49
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
50
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
65
51
  end
66
52
  end
67
53
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.1.1'
10
+ VERSION = '0.1.5'
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.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
- - OpenTelemetry Authors
7
+ - Aspecto Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -222,7 +222,7 @@ dependencies:
222
222
  version: 0.1.6
223
223
  description: AWS SDK instrumentation for the OpenTelemetry framework
224
224
  email:
225
- - cncf-opentelemetry-contributors@lists.cncf.io
225
+ - info@aspecto.io
226
226
  executables: []
227
227
  extensions: []
228
228
  extra_rdoc_files: []
@@ -234,21 +234,20 @@ files:
234
234
  - lib/opentelemetry-instrumentation-aws_sdk.rb
235
235
  - lib/opentelemetry/instrumentation.rb
236
236
  - lib/opentelemetry/instrumentation/aws_sdk.rb
237
- - lib/opentelemetry/instrumentation/aws_sdk/db_helper.rb
238
237
  - lib/opentelemetry/instrumentation/aws_sdk/handler.rb
239
238
  - lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
240
239
  - lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb
241
240
  - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
242
241
  - lib/opentelemetry/instrumentation/aws_sdk/services.rb
243
242
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
244
- homepage: https://github.com/open-telemetry/opentelemetry-ruby
243
+ homepage: https://aspecto.io
245
244
  licenses:
246
245
  - Apache-2.0
247
246
  metadata:
248
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.1/file.CHANGELOG.html
247
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.5/file.CHANGELOG.html
249
248
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
250
249
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
251
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.1
250
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.5
252
251
  post_install_message:
253
252
  rdoc_options: []
254
253
  require_paths:
@@ -264,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
263
  - !ruby/object:Gem::Version
265
264
  version: '0'
266
265
  requirements: []
267
- rubygems_version: 3.2.22
266
+ rubygems_version: 3.1.4
268
267
  signing_key:
269
268
  specification_version: 4
270
269
  summary: AWS SDK instrumentation for the OpenTelemetry framework
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module OpenTelemetry
8
- module Instrumentation
9
- module AwsSdk
10
- # DbHelper class provides methods for calculating aws db span attributes
11
- class DbHelper
12
- class << self
13
- def get_db_attributes(context, service_name, operation)
14
- return get_dynamodb_attributes(context, operation) if service_name == 'DynamoDB'
15
-
16
- {}
17
- end
18
-
19
- def get_dynamodb_attributes(context, operation)
20
- {
21
- SemanticConventions::Trace::DB_SYSTEM => 'dynamodb'
22
- }
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end