aspecto-opentelemetry-instrumentation-aws_sdk 0.1.0 → 0.1.1

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: 0c0d66d31a0f6bc5f4fce712eac7a89dd9496bb184e94ef3d8f020d34da908c6
4
+ data.tar.gz: 9684ac5b863abddf558f0aa13e4b5f06a66ae84c81eb99362fd99e3906a016b9
5
5
  SHA512:
6
- metadata.gz: abf572bbad78da60fe057d3650cdbb1c37cc85ea6902533da363ea730f40f139b61ab7f19fa34360769fb376f0a17767f8be8917aace1e398308920e54e71314
7
- data.tar.gz: d45d7ef1ec899412d0ff33225e45a8cd3c506629d65ac3aa0d76b358d3cfc7ecb7ea4c362d0cd610a14b2ed89b416bc66771015f6309251bfb0f81cd4885aef0
6
+ metadata.gz: 01e7d9fdc6def5ba52d4fd6859fe35f1002988d621dd19174cc49e035db0b2e312fef0bb03982f02e850d9dbdb3d14d841a5eda4cf97a7681da2b7a5e2b61f69
7
+ data.tar.gz: fcb4db3a7b95b559e9b5afe82962a67e1c50a8b85efa58582d0c6da44698afa5cc95be01c69930983f56b309c3981efba2656497f64b4ba19b797dd7d06b5341
@@ -9,12 +9,18 @@ module OpenTelemetry
9
9
  module AwsSdk
10
10
  # Generates Spans for all interactions with AwsSdk
11
11
  class Handler < Seahorse::Client::Handler
12
+ SQS_SEND_MESSAGE = 'SQS.SendMessage'
13
+ SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
14
+ SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
15
+ SNS_PUBLISH = 'SNS.Publish'
16
+
12
17
  def call(context)
13
18
  span_name = get_span_name(context)
14
19
  attributes = get_span_attributes(context)
15
20
 
16
- tracer.in_span(span_name, kind: OpenTelemetry::Trace::SpanKind::CLIENT, attributes: attributes) do |span|
21
+ tracer.in_span(span_name, kind: get_span_kind(context), attributes: attributes) do |span|
17
22
  execute = proc {
23
+ inject_context(context)
18
24
  super(context).tap do |response|
19
25
  if (err = response.error)
20
26
  span.record_exception(err)
@@ -31,6 +37,14 @@ module OpenTelemetry
31
37
  end
32
38
  end
33
39
 
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
43
+
44
+ context.params[:message_attributes] ||= {}
45
+ OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
46
+ end
47
+
34
48
  def get_span_attributes(context)
35
49
  span_attributes = {
36
50
  'aws.region' => context.config.region,
@@ -39,8 +53,9 @@ module OpenTelemetry
39
53
  OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => get_service_name(context)
40
54
  }
41
55
 
56
+ messaging_attributes = MessagingHelper.get_messaging_attributes(context, get_service_name(context), get_operation(context))
42
57
  db_attributes = DbHelper.get_db_attributes(context, get_service_name(context), get_operation(context))
43
- span_attributes.merge(db_attributes)
58
+ span_attributes.merge(messaging_attributes).merge(db_attributes)
44
59
  end
45
60
 
46
61
  def get_service_name(context)
@@ -51,7 +66,31 @@ module OpenTelemetry
51
66
  context&.operation&.name
52
67
  end
53
68
 
69
+ def get_span_kind(context)
70
+ client_method = get_client_method(context)
71
+ case client_method
72
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
73
+ OpenTelemetry::Trace::SpanKind::PRODUCER
74
+ when SQS_RECEIVE_MESSAGE
75
+ OpenTelemetry::Trace::SpanKind::CONSUMER
76
+ else
77
+ OpenTelemetry::Trace::SpanKind::CLIENT
78
+ end
79
+ end
80
+
54
81
  def get_span_name(context)
82
+ client_method = get_client_method(context)
83
+ case client_method
84
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
85
+ "#{MessagingHelper.get_queue_name(context)} send"
86
+ when SQS_RECEIVE_MESSAGE
87
+ "#{MessagingHelper.get_queue_name(context)} receive"
88
+ else
89
+ client_method
90
+ end
91
+ end
92
+
93
+ def get_client_method(context)
55
94
  "#{get_service_name(context)}.#{get_operation(context)}"
56
95
  end
57
96
 
@@ -14,6 +14,8 @@ module OpenTelemetry
14
14
  install do |_config|
15
15
  require_relative 'handler'
16
16
  require_relative 'services'
17
+ require_relative 'message_attribute_setter'
18
+ require_relative 'messaging_helper'
17
19
  require_relative 'db_helper'
18
20
 
19
21
  add_plugin(Seahorse::Client::Base, *loaded_constants)
@@ -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,70 @@
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 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]
18
+
19
+ if topic_arn || target_arn
20
+ arn = topic_arn || target_arn
21
+ begin
22
+ arn.split(':')[-1]
23
+ rescue StandardError
24
+ 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 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
+ }
48
+
49
+ sqs_attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if operation == 'ReceiveMessage'
50
+
51
+ sqs_attributes
52
+ end
53
+
54
+ def get_sns_attributes(context, operation)
55
+ sns_attributes = {
56
+ SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sns'
57
+ }
58
+
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
63
+
64
+ sns_attributes
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ 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.1'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
@@ -237,16 +237,18 @@ files:
237
237
  - lib/opentelemetry/instrumentation/aws_sdk/db_helper.rb
238
238
  - lib/opentelemetry/instrumentation/aws_sdk/handler.rb
239
239
  - lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
240
+ - lib/opentelemetry/instrumentation/aws_sdk/message_attribute_setter.rb
241
+ - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
240
242
  - lib/opentelemetry/instrumentation/aws_sdk/services.rb
241
243
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
242
244
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
243
245
  licenses:
244
246
  - Apache-2.0
245
247
  metadata:
246
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.0/file.CHANGELOG.html
248
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.1/file.CHANGELOG.html
247
249
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/aws_sdk
248
250
  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
251
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-aws_sdk/v0.1.1
250
252
  post_install_message:
251
253
  rdoc_options: []
252
254
  require_paths: