aspecto-opentelemetry-instrumentation-aws_sdk 0.1.2 → 0.1.3

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: 1fb173a9b6f6b808809096ed8197c1613830a59f05141deb338f9b50f2385b62
4
- data.tar.gz: abf40be87810f0f6143d08992e5d1f8df5a5e2c4305e1157f7d536bec0093d86
3
+ metadata.gz: 7d56c9d2bed4f998ebcdc3d8749099ede72c95ea8948bc39375b776ca4c60a19
4
+ data.tar.gz: bf5af54a01e30d3d699845a3c94af34bb5bfd230f7bfccc863c611594e34ea34
5
5
  SHA512:
6
- metadata.gz: f7ee252047b645f04c863afe2f2a9b6dc7e1e8cb7636313e523cd1eb95277c8bf7044cf153c2f8da92e63da69243b581e29e62403940367efa023edb7b218987
7
- data.tar.gz: d6c471fd137dba3f4fb05423c462b3d26fa0b3ee7a4e0dff223d244eee98cfb6768df2ee3b3d3ba5dbf2a42de4c4f2e80148bbca32816a5c02c096bd8bf41334
6
+ metadata.gz: e2a6c0fed13608fbc523f8d8eb6f86284b10b730ea9661559d269aabbab57f05f98822f848511b76cf1a942edac0812be17966c121350a72b61f08b949b1a5b1
7
+ data.tar.gz: 64a9433cf193b388212de556c614d2e62fda9a25e894b3d1fec578ef2fa9abdc0e9c0232fae60f150e290e7dcac5c95441e2dd7da58fbb31cec0ad2d861958aa
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.api.metadata['serviceId'] || 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(service_name, 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)
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(service_name, 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,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 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 = 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)
18
18
 
19
19
  if topic_arn || target_arn
20
20
  arn = topic_arn || target_arn
@@ -32,37 +32,26 @@ 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'
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] = params(context, :queue_url)
38
40
 
39
- {}
41
+ attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
40
42
  end
41
43
 
42
- def get_sqs_attributes(context, operation)
43
- sqs_attributes = {
44
- SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sqs',
45
- SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue',
46
- SemanticConventions::Trace::MESSAGING_DESTINATION => get_queue_name(context),
47
- SemanticConventions::Trace::MESSAGING_URL => context.metadata[:original_params][:queue_url]
48
- }
44
+ def apply_sns_attributes(attributes, context, client_method)
45
+ attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
49
46
 
50
- sqs_attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if operation == 'ReceiveMessage'
47
+ return unless client_method == 'SNS.Publish'
51
48
 
52
- sqs_attributes
49
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
50
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
53
51
  end
54
52
 
55
- def get_sns_attributes(context, operation)
56
- sns_attributes = {
57
- SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sns'
58
- }
59
-
60
- if operation == 'Publish'
61
- sns_attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
62
- sns_attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = get_queue_name(context)
63
- end
64
-
65
- sns_attributes
53
+ def params(context, param)
54
+ defined?(context.metadata[:original_params][param]) ? context.metadata[:original_params][param] : context.params[param]
66
55
  end
67
56
  end
68
57
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.1.2'
10
+ VERSION = '0.1.3'
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
- - OpenTelemetry Authors
8
- autorequire:
7
+ - Aspecto Authors
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2021-11-22 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,7 +234,6 @@ 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
@@ -245,11 +244,11 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
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.2/file.CHANGELOG.html
247
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.3/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.2
252
- post_install_message:
250
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.3
251
+ post_install_message:
253
252
  rdoc_options: []
254
253
  require_paths:
255
254
  - lib
@@ -264,8 +263,8 @@ 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
268
- signing_key:
266
+ rubygems_version: 3.0.3
267
+ signing_key:
269
268
  specification_version: 4
270
269
  summary: AWS SDK instrumentation for the OpenTelemetry framework
271
270
  test_files: []
@@ -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