aspecto-opentelemetry-instrumentation-aws_sdk 0.1.0 → 0.1.4

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: 5ec3341f2b96c740a02d140ed58196b6cf592592129a599b70813a5b2589e764
4
- data.tar.gz: 2b29e56274e254fcddad2fe4166541efae62a176e93c1e0a27fc4e81d7fa6334
3
+ metadata.gz: 07cea588556e47fdc18637f2eaafbfc925a54fa10b1a5f0e90e3252028512c52
4
+ data.tar.gz: 0b77c9ae3b96d84bdc2065fbce499c371d4d03b49789ab862b823cad9907b87b
5
5
  SHA512:
6
- metadata.gz: abf572bbad78da60fe057d3650cdbb1c37cc85ea6902533da363ea730f40f139b61ab7f19fa34360769fb376f0a17767f8be8917aace1e398308920e54e71314
7
- data.tar.gz: d45d7ef1ec899412d0ff33225e45a8cd3c506629d65ac3aa0d76b358d3cfc7ecb7ea4c362d0cd610a14b2ed89b416bc66771015f6309251bfb0f81cd4885aef0
6
+ metadata.gz: fd02cdfca52ecec95c992481bc42cb05e4b9568294fe05b279ea3015bbc39b80312be002590cdc68ccbb9f5125c8c80d14240df0b40ad01a847f76268a633ce1
7
+ data.tar.gz: 1691f847d0914cb362440813a9f8584d3811303b007cec058ca2b278618d3060ce38fbd32edfd7d30936f654e0090ec8f1d23fc41efd4993ad2827784431adf0
data/CHANGELOG.md CHANGED
@@ -0,0 +1 @@
1
+ # Release History: opentelemetry-instrumentation-aws_sdk
@@ -9,58 +9,86 @@ module OpenTelemetry
9
9
  module AwsSdk
10
10
  # Generates Spans for all interactions with AwsSdk
11
11
  class Handler < Seahorse::Client::Handler
12
- def call(context)
13
- span_name = get_span_name(context)
14
- attributes = get_span_attributes(context)
12
+ SQS_SEND_MESSAGE = 'SQS.SendMessage'
13
+ SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
14
+ SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
15
+ SNS_PUBLISH = 'SNS.Publish'
15
16
 
16
- tracer.in_span(span_name, kind: OpenTelemetry::Trace::SpanKind::CLIENT, attributes: attributes) do |span|
17
- execute = proc {
18
- super(context).tap do |response|
19
- if (err = response.error)
20
- span.record_exception(err)
21
- span.status = Trace::Status.error(err)
22
- end
23
- end
24
- }
17
+ def call(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
18
+ return super unless context
19
+
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'
25
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)
26
35
  if instrumentation_config[:suppress_internal_instrumentation]
27
- OpenTelemetry::Common::Utilities.untraced(&execute)
36
+ OpenTelemetry::Common::Utilities.untraced { super }
28
37
  else
29
- 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
30
44
  end
31
45
  end
32
46
  end
33
47
 
34
- def get_span_attributes(context)
35
- span_attributes = {
36
- 'aws.region' => context.config.region,
37
- OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
38
- OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => get_operation(context),
39
- OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => get_service_name(context)
40
- }
48
+ private
41
49
 
42
- db_attributes = DbHelper.get_db_attributes(context, get_service_name(context), get_operation(context))
43
- span_attributes.merge(db_attributes)
50
+ def tracer
51
+ AwsSdk::Instrumentation.instance.tracer
44
52
  end
45
53
 
46
- def get_service_name(context)
47
- context&.client.class.api.metadata['serviceId'] || context&.client.class.to_s.split('::')[1]
54
+ def instrumentation_config
55
+ AwsSdk::Instrumentation.instance.config
48
56
  end
49
57
 
50
- def get_operation(context)
51
- context&.operation&.name
52
- end
58
+ def inject_context(context, client_method)
59
+ return unless [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].include? client_method
53
60
 
54
- def get_span_name(context)
55
- "#{get_service_name(context)}.#{get_operation(context)}"
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
56
70
  end
57
71
 
58
- def tracer
59
- AwsSdk::Instrumentation.instance.tracer
72
+ def span_kind(service_name, client_method)
73
+ case client_method
74
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
75
+ OpenTelemetry::Trace::SpanKind::PRODUCER
76
+ when SQS_RECEIVE_MESSAGE
77
+ OpenTelemetry::Trace::SpanKind::CONSUMER
78
+ else
79
+ OpenTelemetry::Trace::SpanKind::CLIENT
80
+ end
60
81
  end
61
82
 
62
- def instrumentation_config
63
- AwsSdk::Instrumentation.instance.config
83
+ def span_name(context, client_method)
84
+ case client_method
85
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
86
+ "#{MessagingHelper.queue_name(context)} send"
87
+ when SQS_RECEIVE_MESSAGE
88
+ "#{MessagingHelper.queue_name(context)} receive"
89
+ else
90
+ client_method
91
+ end
64
92
  end
65
93
  end
66
94
 
@@ -12,10 +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 'db_helper'
18
-
15
+ require_dependencies
19
16
  add_plugin(Seahorse::Client::Base, *loaded_constants)
20
17
  end
21
18
 
@@ -29,6 +26,15 @@ module OpenTelemetry
29
26
 
30
27
  option :suppress_internal_instrumentation, default: false, validate: :boolean
31
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
+
32
38
  def gem_version
33
39
  if Gem.loaded_specs['aws-sdk']
34
40
  Gem.loaded_specs['aws-sdk'].version
@@ -0,0 +1,27 @@
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
+ # The MessageAttributeSetter class provides methods for writing tracing information to
11
+ # SNS / SQS messages.
12
+ #
13
+ # @example
14
+ # OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
15
+ class MessageAttributeSetter
16
+ def self.set(carrier, key, value)
17
+ # https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html
18
+ if carrier.length < 10
19
+ carrier[key] = { string_value: value, data_type: 'String' }
20
+ else
21
+ OpenTelemetry.logger.warn('aws-sdk instrumentation: cannot set context propagation on SQS/SNS message due to maximum amount of MessageAttributes')
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,60 @@
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
+ # MessagingHelper class provides methods for calculating messaging span attributes
11
+ class MessagingHelper
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)
18
+
19
+ if topic_arn || target_arn
20
+ arn = topic_arn || target_arn
21
+ begin
22
+ return arn.split(':')[-1]
23
+ rescue StandardError
24
+ return arn
25
+ end
26
+ end
27
+
28
+ return phone_number if phone_number
29
+
30
+ return queue_url.split('/')[-1] if queue_url
31
+
32
+ 'unknown'
33
+ end
34
+
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)
40
+
41
+ attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
42
+ end
43
+
44
+ def apply_sns_attributes(attributes, context, client_method)
45
+ attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
46
+
47
+ return unless client_method == 'SNS.Publish'
48
+
49
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
50
+ attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
51
+ end
52
+
53
+ def params(context, param)
54
+ defined?(context.metadata[:original_params][param]) ? context.metadata[:original_params][param] : context.params[param]
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.1.0'
10
+ VERSION = '0.1.4'
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.0
4
+ version: 0.1.4
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-23 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,19 +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
239
+ - lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb
240
+ - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
240
241
  - lib/opentelemetry/instrumentation/aws_sdk/services.rb
241
242
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
242
- homepage: https://github.com/open-telemetry/opentelemetry-ruby
243
+ homepage: https://aspecto.io
243
244
  licenses:
244
245
  - Apache-2.0
245
246
  metadata:
246
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.0/file.CHANGELOG.html
247
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.4/file.CHANGELOG.html
247
248
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
248
249
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
249
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.0
250
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.4
250
251
  post_install_message:
251
252
  rdoc_options: []
252
253
  require_paths:
@@ -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