opentelemetry-instrumentation-aws_sdk 0.5.3 → 0.6.0

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: 85fcbab6e35379902d9ff9d2bcb50f9676ea0a1cffbc861c507a36fefa83e1cc
4
- data.tar.gz: b922cfc56f13ddf9876c7168158199ebf9cd07b64e8717fa5309f6cf3f525145
3
+ metadata.gz: 05256cef329eccec85d4d6732b402aa9c1be08fa39da455cee3ed43d4b0ed9c7
4
+ data.tar.gz: d4f05d032386bdbabfb064e051757a02fc27b75947594bb89211b311abb54446
5
5
  SHA512:
6
- metadata.gz: 262b4f67c08bf114d01c39e572ad28cf54f518c5147133cdb78bb26c6de71c63feeb649a516aa5e847d7d85e3dea39f50c80b323051591a38c28001df6d0e215
7
- data.tar.gz: 6084a2f559ab16135b7aadbccc267b353e6cab1f9db5106b23913d4763ae29ba95cf5ec1acb951248e906fc5868d6cf7abc5b13ca6361367cb9e4efef7e1b23f
6
+ metadata.gz: 7dada29094deea482504658785d9b13ce16d2e8d4198d0c08b64c378618cda70d30744ece8a0b59a12df3a39f18a23ca9f93c1b3186ea51e53e4a6c03e887127
7
+ data.tar.gz: 379d073b4f1d46dce866fdd15a85677cc7f436b82c608a40731f4a716222fda9b3774fecf0264679046f79b1cf71179398a7c555c7815f8f35e5ce461784eb73
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Release History: opentelemetry-instrumentation-aws_sdk
2
2
 
3
+ ### v0.6.0 / 2024-09-19
4
+
5
+ * ADDED: All AWS services emit traces
6
+
7
+ ### v0.5.4 / 2024-07-23
8
+
9
+ * DOCS: Add cspell to CI
10
+
3
11
  ### v0.5.3 / 2024-07-02
4
12
 
5
13
  * DOCS: Fix CHANGELOGs to reflect a past breaking change
@@ -10,7 +18,7 @@
10
18
 
11
19
  ### v0.5.1 / 2024-02-08
12
20
 
13
- * FIXED: Return nil for non-existant key in AwsSdk::MessageAttributeGetter
21
+ * FIXED: Return nil for non-existent key in AwsSdk::MessageAttributeGetter
14
22
 
15
23
  ### v0.5.0 / 2023-09-07
16
24
 
data/README.md CHANGED
@@ -6,7 +6,7 @@ The OpenTelemetry `aws-sdk` gem is a community maintained instrumentation for [a
6
6
 
7
7
  Install the gem using:
8
8
 
9
- ```
9
+ ```console
10
10
  gem install opentelemetry-instrumentation-aws_sdk
11
11
  ```
12
12
 
@@ -49,7 +49,7 @@ This will run SNS publish command, printing OpenTelemetry traces to the console
49
49
 
50
50
  The `opentelemetry-instrumentation-aws_sdk` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
51
51
 
52
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
52
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
53
53
 
54
54
  ## License
55
55
 
@@ -61,4 +61,5 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
61
61
  [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
62
62
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
63
63
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
64
+ [slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
64
65
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -9,36 +9,32 @@ 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
-
17
12
  def call(context)
18
13
  return super unless context
19
14
 
20
- service_name = service_name(context)
15
+ service_id = service_name(context)
21
16
  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'
17
+ client_method = "#{service_id}.#{operation}"
18
+
19
+ tracer.in_span(
20
+ span_name(context, client_method, service_id),
21
+ attributes: attributes(context, client_method, service_id, operation),
22
+ kind: span_kind(client_method, service_id)
23
+ ) do |span|
24
+ if instrumentation_config[:inject_messaging_context] &&
25
+ %w[SQS SNS].include?(service_id)
26
+ MessagingHelper.inject_context(context, client_method)
27
+ end
32
28
 
33
- tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(client_method)) do |span|
34
- inject_context(context, client_method)
35
29
  if instrumentation_config[:suppress_internal_instrumentation]
36
30
  OpenTelemetry::Common::Utilities.untraced { super }
37
31
  else
38
32
  super
39
33
  end.tap do |response|
40
- span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE,
41
- context.http_response.status_code)
34
+ span.set_attribute(
35
+ OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE,
36
+ context.http_response.status_code
37
+ )
42
38
 
43
39
  if (err = response.error)
44
40
  span.record_exception(err)
@@ -65,48 +61,40 @@ module OpenTelemetry
65
61
  context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
66
62
  end
67
63
 
68
- SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze
69
- def inject_context(context, client_method)
70
- return unless SEND_MESSAGE_CLIENT_METHODS.include? client_method
71
- return unless instrumentation_config[:inject_messaging_context]
72
-
73
- if client_method == SQS_SEND_MESSAGE_BATCH
74
- context.params[:entries].each do |entry|
75
- entry[:message_attributes] ||= {}
76
- OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
77
- end
64
+ def span_kind(client_method, service_id)
65
+ case service_id
66
+ when 'SQS', 'SNS'
67
+ MessagingHelper.span_kind(client_method)
78
68
  else
79
- context.params[:message_attributes] ||= {}
80
- OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
69
+ OpenTelemetry::Trace::SpanKind::CLIENT
81
70
  end
82
71
  end
83
72
 
84
- def span_kind(client_method)
85
- case client_method
86
- when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
87
- OpenTelemetry::Trace::SpanKind::PRODUCER
88
- when SQS_RECEIVE_MESSAGE
89
- OpenTelemetry::Trace::SpanKind::CONSUMER
73
+ def span_name(context, client_method, service_id)
74
+ case service_id
75
+ when 'SQS', 'SNS'
76
+ MessagingHelper.legacy_span_name(context, client_method)
90
77
  else
91
- OpenTelemetry::Trace::SpanKind::CLIENT
78
+ client_method
92
79
  end
93
80
  end
94
81
 
95
- def span_name(context, client_method)
96
- case client_method
97
- when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
98
- "#{MessagingHelper.queue_name(context)} publish"
99
- when SQS_RECEIVE_MESSAGE
100
- "#{MessagingHelper.queue_name(context)} receive"
101
- else
102
- client_method
82
+ def attributes(context, client_method, service_id, operation)
83
+ {
84
+ 'aws.region' => context.config.region,
85
+ OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api',
86
+ OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => operation,
87
+ OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_id
88
+ }.tap do |attrs|
89
+ attrs[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_id == 'DynamoDB'
90
+ MessagingHelper.apply_span_attributes(context, attrs, client_method, service_id) if %w[SQS SNS].include?(service_id)
103
91
  end
104
92
  end
105
93
  end
106
94
 
107
95
  # A Seahorse::Client::Plugin that enables instrumentation for all AWS services
108
96
  class Plugin < Seahorse::Client::Plugin
109
- def add_handlers(handlers, config)
97
+ def add_handlers(handlers, _config)
110
98
  # run before Seahorse::Client::Plugin::ParamValidator (priority 50)
111
99
  handlers.add Handler, step: :validate, priority: 49
112
100
  end
@@ -13,7 +13,7 @@ module OpenTelemetry
13
13
 
14
14
  install do |_config|
15
15
  require_dependencies
16
- add_plugin(Seahorse::Client::Base, *loaded_constants)
16
+ add_plugins(Seahorse::Client::Base, *loaded_service_clients)
17
17
  end
18
18
 
19
19
  present do
@@ -41,31 +41,39 @@ module OpenTelemetry
41
41
 
42
42
  def require_dependencies
43
43
  require_relative 'handler'
44
- require_relative 'services'
45
44
  require_relative 'message_attributes'
46
45
  require_relative 'messaging_helper'
47
46
  end
48
47
 
49
- def add_plugin(*targets)
48
+ def add_plugins(*targets)
50
49
  targets.each { |klass| klass.add_plugin(AwsSdk::Plugin) }
51
50
  end
52
51
 
53
- def loaded_constants
54
- # Cross-check services against loaded AWS constants
55
- # Module#const_get can return a constant from ancestors when there's a miss.
56
- # If this conincidentally matches another constant, it will attempt to patch
57
- # the wrong constant, resulting in patch failure.
58
- available_services = ::Aws.constants & SERVICES.map(&:to_sym)
59
- available_services.each_with_object([]) do |service, constants|
60
- next if ::Aws.autoload?(service)
52
+ def loaded_service_clients
53
+ ::Aws.constants.each_with_object([]) do |c, constants|
54
+ m = ::Aws.const_get(c)
55
+ next unless loaded_service?(c, m)
61
56
 
62
57
  begin
63
- constants << ::Aws.const_get(service, false).const_get(:Client, false)
58
+ constants << m.const_get(:Client)
64
59
  rescue StandardError => e
65
60
  OpenTelemetry.logger.warn("Constant could not be loaded: #{e}")
66
61
  end
67
62
  end
68
63
  end
64
+
65
+ # This check does the following:
66
+ # 1 - Checks if the service client is autoload or not
67
+ # 2 - Validates whether if is a service client
68
+ # note that Seahorse::Client::Base is a superclass for V3 clients
69
+ # but for V2, it is Aws::Client
70
+ def loaded_service?(constant, service_module)
71
+ !::Aws.autoload?(constant) &&
72
+ service_module.is_a?(Module) &&
73
+ service_module.const_defined?(:Client) &&
74
+ (service_module.const_get(:Client).superclass == Seahorse::Client::Base ||
75
+ service_module.const_get(:Client).superclass == Aws::Client)
76
+ end
69
77
  end
70
78
  end
71
79
  end
@@ -7,9 +7,15 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- # MessagingHelper class provides methods for calculating messaging span attributes
10
+ # An utility class to help SQS/SNS-related span attributes/context injection
11
11
  class MessagingHelper
12
12
  class << self
13
+ SQS_SEND_MESSAGE = 'SQS.SendMessage'
14
+ SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch'
15
+ SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage'
16
+ SNS_PUBLISH = 'SNS.Publish'
17
+ SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze
18
+
13
19
  def queue_name(context)
14
20
  topic_arn = context.params[:topic_arn]
15
21
  target_arn = context.params[:target_arn]
@@ -28,19 +34,64 @@ module OpenTelemetry
28
34
  'unknown'
29
35
  end
30
36
 
37
+ def legacy_span_name(context, client_method)
38
+ case client_method
39
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
40
+ "#{MessagingHelper.queue_name(context)} publish"
41
+ when SQS_RECEIVE_MESSAGE
42
+ "#{MessagingHelper.queue_name(context)} receive"
43
+ else
44
+ client_method
45
+ end
46
+ end
47
+
48
+ def apply_span_attributes(context, attrs, client_method, service_id)
49
+ case service_id
50
+ when 'SQS'
51
+ apply_sqs_attributes(attrs, context, client_method)
52
+ when 'SNS'
53
+ apply_sns_attributes(attrs, context, client_method)
54
+ end
55
+ end
56
+
57
+ def span_kind(client_method)
58
+ case client_method
59
+ when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH
60
+ OpenTelemetry::Trace::SpanKind::PRODUCER
61
+ when SQS_RECEIVE_MESSAGE
62
+ OpenTelemetry::Trace::SpanKind::CONSUMER
63
+ else
64
+ OpenTelemetry::Trace::SpanKind::CLIENT
65
+ end
66
+ end
67
+
68
+ def inject_context(context, client_method)
69
+ return unless SEND_MESSAGE_CLIENT_METHODS.include?(client_method)
70
+
71
+ if client_method == SQS_SEND_MESSAGE_BATCH
72
+ context.params[:entries].each do |entry|
73
+ entry[:message_attributes] ||= {}
74
+ OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter)
75
+ end
76
+ else
77
+ context.params[:message_attributes] ||= {}
78
+ OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
79
+ end
80
+ end
81
+
82
+ private
83
+
31
84
  def apply_sqs_attributes(attributes, context, client_method)
32
85
  attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
33
86
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
34
87
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
35
88
  attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url] if context.params[:queue_url]
36
-
37
- attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
89
+ attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == SQS_RECEIVE_MESSAGE
38
90
  end
39
91
 
40
92
  def apply_sns_attributes(attributes, context, client_method)
41
93
  attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'
42
-
43
- return unless client_method == 'SNS.Publish'
94
+ return unless client_method == SNS_PUBLISH
44
95
 
45
96
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
46
97
  attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module AwsSdk
10
- VERSION = '0.5.3'
10
+ VERSION = '0.6.0'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-aws_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 1.64.0
159
+ version: 1.66.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 1.64.0
166
+ version: 1.66.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rubocop-performance
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -238,16 +238,15 @@ files:
238
238
  - lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb
239
239
  - lib/opentelemetry/instrumentation/aws_sdk/message_attributes.rb
240
240
  - lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
241
- - lib/opentelemetry/instrumentation/aws_sdk/services.rb
242
241
  - lib/opentelemetry/instrumentation/aws_sdk/version.rb
243
242
  homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
244
243
  licenses:
245
244
  - Apache-2.0
246
245
  metadata:
247
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.5.3/file/CHANGELOG.md
246
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.6.0/file/CHANGELOG.md
248
247
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/aws_sdk
249
248
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
250
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.5.3
249
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-aws_sdk/0.6.0
251
250
  post_install_message:
252
251
  rdoc_options: []
253
252
  require_paths:
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenTelemetry
4
- module Instrumentation
5
- # rubocop:disable Metrics/ModuleLength:
6
- module AwsSdk
7
- SERVICES = %w[
8
- ACM
9
- APIGateway
10
- AppStream
11
- ApplicationAutoScaling
12
- ApplicationDiscoveryService
13
- Athena
14
- AutoScaling
15
- Batch
16
- Budgets
17
- CloudDirectory
18
- CloudFormation
19
- CloudFront
20
- CloudHSM
21
- CloudHSMV2
22
- CloudSearch
23
- CloudSearchDomain
24
- CloudTrail
25
- CloudWatch
26
- CloudWatchEvents
27
- CloudWatchLogs
28
- CodeBuild
29
- CodeCommit
30
- CodeDeploy
31
- CodePipeline
32
- CodeStar
33
- CognitoIdentity
34
- CognitoIdentityProvider
35
- CognitoSync
36
- ConfigService
37
- CostandUsageReportService
38
- DAX
39
- DataPipeline
40
- DatabaseMigrationService
41
- DeviceFarm
42
- DirectConnect
43
- DirectoryService
44
- DynamoDB
45
- DynamoDBStreams
46
- EC2
47
- ECR
48
- ECS
49
- EFS
50
- EMR
51
- ElastiCache
52
- ElasticBeanstalk
53
- ElasticLoadBalancing
54
- ElasticLoadBalancingV2
55
- ElasticTranscoder
56
- ElasticsearchService
57
- EventBridge
58
- Firehose
59
- GameLift
60
- Glacier
61
- Glue
62
- Greengrass
63
- Health
64
- IAM
65
- ImportExport
66
- Inspector
67
- IoT
68
- IoTDataPlane
69
- KMS
70
- Kinesis
71
- KinesisAnalytics
72
- Lambda
73
- LambdaPreview
74
- Lex
75
- LexModelBuildingService
76
- Lightsail
77
- MTurk
78
- MachineLearning
79
- MarketplaceCommerceAnalytics
80
- MarketplaceEntitlementService
81
- MarketplaceMetering
82
- MigrationHub
83
- Mobile
84
- OpsWorks
85
- OpsWorksCM
86
- Organizations
87
- Pinpoint
88
- Polly
89
- RDS
90
- Redshift
91
- Rekognition
92
- ResourceGroupsTaggingAPI
93
- Route53
94
- Route53Domains
95
- S3
96
- SES
97
- SMS
98
- SNS
99
- SQS
100
- SSM
101
- STS
102
- SWF
103
- ServiceCatalog
104
- Schemas
105
- Shield
106
- SimpleDB
107
- Snowball
108
- States
109
- StorageGateway
110
- Support
111
- Textract
112
- WAF
113
- WAFRegional
114
- WorkDocs
115
- WorkSpaces
116
- XRay
117
- ].freeze
118
- end
119
- # rubocop:enable Metrics/ModuleLength:
120
- end
121
- end