From 7fb750c2de3bc6ee6895976e13769ae04539ba90 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 5 Sep 2024 09:53:59 -0700 Subject: [PATCH 1/8] feat: All V3 services emit traces --- .../aws_sdk/instrumentation.rb | 35 +++++++++++++++++-- ...ntelemetry-instrumentation-aws_sdk.gemspec | 8 +++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index 07b4075f2..6173074b2 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -10,10 +10,11 @@ module AwsSdk # Instrumentation class that detects and installs the AwsSdk instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base MINIMUM_VERSION = Gem::Version.new('2.0.0') + CURRENT_MAJOR_VERSION = Gem::Version.new('3.0.0') install do |_config| require_dependencies - add_plugin(Seahorse::Client::Base, *loaded_constants) + add_plugins(Seahorse::Client::Base, *loaded_constants) end present do @@ -46,14 +47,42 @@ def require_dependencies require_relative 'messaging_helper' end - def add_plugin(*targets) + def add_plugins(*targets) targets.each { |klass| klass.add_plugin(AwsSdk::Plugin) } end def loaded_constants + if gem_version >= CURRENT_MAJOR_VERSION + load_v3_constants + else + load_legacy_constants + end + end + + def load_v3_constants + ::Aws.constants.each_with_object([]) do |c, constants| + m = ::Aws.const_get(c) + next unless unloaded_service?(c, m) + + begin + constants << m.const_get(:Client) + rescue StandardError => e + OpenTelemetry.logger.warn("Constant could not be loaded: #{e}") + end + end + end + + def unloaded_service?(constant, service_module) + !::Aws.autoload?(constant) && + service_module.is_a?(Module) && + service_module.const_defined?(:Client) && + (service_module.const_get(:Client).superclass == Seahorse::Client::Base) + end + + def load_legacy_constants # Cross-check services against loaded AWS constants # Module#const_get can return a constant from ancestors when there's a miss. - # If this conincidentally matches another constant, it will attempt to patch + # If this coincidentally matches another constant, it will attempt to patch # the wrong constant, resulting in patch failure. available_services = ::Aws.constants & SERVICES.map(&:to_sym) available_services.each_with_object([]) do |service, constants| diff --git a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec index 01415e31c..4fba14c34 100644 --- a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec +++ b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |spec| spec.license = 'Apache-2.0' spec.files = Dir.glob('lib/**/*.rb') + - Dir.glob('*.md') + - ['LICENSE', '.yardopts'] + Dir.glob('*.md') + + ['LICENSE', '.yardopts'] spec.require_paths = ['lib'] spec.required_ruby_version = '>= 3.0' @@ -29,6 +29,10 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' + spec.add_development_dependency 'aws-sdk-dynamodb' + spec.add_development_dependency 'aws-sdk-s3' + spec.add_development_dependency 'aws-sdk-sns' + spec.add_development_dependency 'aws-sdk-sqs' spec.add_development_dependency 'bundler', '~> 2.4' spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1' From 32c0aa829cb8ccd3e54afffc9315ff6a1a9e1309 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 5 Sep 2024 09:56:26 -0700 Subject: [PATCH 2/8] refactor: Clean up Handler and MessageHelper --- .../instrumentation/aws_sdk/handler.rb | 84 ++++++++----------- .../aws_sdk/messaging_helper.rb | 62 ++++++++++++-- ...ntelemetry-instrumentation-aws_sdk.gemspec | 3 +- 3 files changed, 95 insertions(+), 54 deletions(-) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler.rb index a973adeb5..c0b040956 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/handler.rb @@ -9,36 +9,32 @@ module Instrumentation module AwsSdk # Generates Spans for all interactions with AwsSdk class Handler < Seahorse::Client::Handler - SQS_SEND_MESSAGE = 'SQS.SendMessage' - SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch' - SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage' - SNS_PUBLISH = 'SNS.Publish' - def call(context) return super unless context - service_name = service_name(context) + service_id = service_name(context) operation = context.operation&.name - client_method = "#{service_name}.#{operation}" - attributes = { - 'aws.region' => context.config.region, - OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api', - OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => operation, - OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_name - } - attributes[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_name == 'DynamoDB' - MessagingHelper.apply_sqs_attributes(attributes, context, client_method) if service_name == 'SQS' - MessagingHelper.apply_sns_attributes(attributes, context, client_method) if service_name == 'SNS' + client_method = "#{service_id}.#{operation}" + + tracer.in_span( + span_name(context, client_method, service_id), + attributes: attributes(context, client_method, service_id, operation), + kind: span_kind(client_method, service_id) + ) do |span| + if instrumentation_config[:inject_messaging_context] && + %w[SQS SNS].include?(service_id) + MessagingHelper.inject_context(context, client_method) + end - tracer.in_span(span_name(context, client_method), attributes: attributes, kind: span_kind(client_method)) do |span| - inject_context(context, client_method) if instrumentation_config[:suppress_internal_instrumentation] OpenTelemetry::Common::Utilities.untraced { super } else super end.tap do |response| - span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, - context.http_response.status_code) + span.set_attribute( + OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, + context.http_response.status_code + ) if (err = response.error) span.record_exception(err) @@ -65,48 +61,40 @@ def service_name(context) context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1] end - SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze - def inject_context(context, client_method) - return unless SEND_MESSAGE_CLIENT_METHODS.include? client_method - return unless instrumentation_config[:inject_messaging_context] - - if client_method == SQS_SEND_MESSAGE_BATCH - context.params[:entries].each do |entry| - entry[:message_attributes] ||= {} - OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter) - end + def span_kind(client_method, service_id) + case service_id + when 'SQS', 'SNS' + MessagingHelper.span_kind(client_method) else - context.params[:message_attributes] ||= {} - OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter) + OpenTelemetry::Trace::SpanKind::CLIENT end end - def span_kind(client_method) - case client_method - when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH - OpenTelemetry::Trace::SpanKind::PRODUCER - when SQS_RECEIVE_MESSAGE - OpenTelemetry::Trace::SpanKind::CONSUMER + def span_name(context, client_method, service_id) + case service_id + when 'SQS', 'SNS' + MessagingHelper.legacy_span_name(context, client_method) else - OpenTelemetry::Trace::SpanKind::CLIENT + client_method end end - def span_name(context, client_method) - case client_method - when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH - "#{MessagingHelper.queue_name(context)} publish" - when SQS_RECEIVE_MESSAGE - "#{MessagingHelper.queue_name(context)} receive" - else - client_method + def attributes(context, client_method, service_id, operation) + { + 'aws.region' => context.config.region, + OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'aws-api', + OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => operation, + OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_id + }.tap do |attrs| + attrs[SemanticConventions::Trace::DB_SYSTEM] = 'dynamodb' if service_id == 'DynamoDB' + MessagingHelper.apply_span_attributes(context, attrs, client_method, service_id) if %w[SQS SNS].include?(service_id) end end end # A Seahorse::Client::Plugin that enables instrumentation for all AWS services class Plugin < Seahorse::Client::Plugin - def add_handlers(handlers, config) + def add_handlers(handlers, _config) # run before Seahorse::Client::Plugin::ParamValidator (priority 50) handlers.add Handler, step: :validate, priority: 49 end diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb index e6fb8d0e4..7e9225cac 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb @@ -7,9 +7,15 @@ module OpenTelemetry module Instrumentation module AwsSdk - # MessagingHelper class provides methods for calculating messaging span attributes + # An utility class to help SQS/SNS-related span attributes/context injection class MessagingHelper class << self + SQS_SEND_MESSAGE = 'SQS.SendMessage' + SQS_SEND_MESSAGE_BATCH = 'SQS.SendMessageBatch' + SQS_RECEIVE_MESSAGE = 'SQS.ReceiveMessage' + SNS_PUBLISH = 'SNS.Publish' + SEND_MESSAGE_CLIENT_METHODS = [SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH].freeze + def queue_name(context) topic_arn = context.params[:topic_arn] target_arn = context.params[:target_arn] @@ -28,19 +34,65 @@ def queue_name(context) 'unknown' end + def legacy_span_name(context, client_method) + case client_method + when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH + "#{MessagingHelper.queue_name(context)} publish" + when SQS_RECEIVE_MESSAGE + "#{MessagingHelper.queue_name(context)} receive" + else + client_method + end + end + + # def apply_span_attributes(attrs, context, service_id, client_method) + def apply_span_attributes(context, attrs, client_method, service_id) + case service_id + when 'SQS' + apply_sqs_attributes(attrs, context, client_method) + when 'SNS' + apply_sns_attributes(attrs, context, client_method) + end + end + + def span_kind(client_method) + case client_method + when SQS_SEND_MESSAGE, SQS_SEND_MESSAGE_BATCH, SNS_PUBLISH + OpenTelemetry::Trace::SpanKind::PRODUCER + when SQS_RECEIVE_MESSAGE + OpenTelemetry::Trace::SpanKind::CONSUMER + else + OpenTelemetry::Trace::SpanKind::CLIENT + end + end + + def inject_context(context, client_method) + return unless SEND_MESSAGE_CLIENT_METHODS.include?(client_method) + + if client_method == SQS_SEND_MESSAGE_BATCH + context.params[:entries].each do |entry| + entry[:message_attributes] ||= {} + OpenTelemetry.propagation.inject(entry[:message_attributes], setter: MessageAttributeSetter) + end + else + context.params[:message_attributes] ||= {} + OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter) + end + end + + private + def apply_sqs_attributes(attributes, context, client_method) attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs' attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue' attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context) attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url] if context.params[:queue_url] - - attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage' + attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == SQS_RECEIVE_MESSAGE end def apply_sns_attributes(attributes, context, client_method) attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns' - - return unless client_method == 'SNS.Publish' + return unless client_method == SNS_PUBLISH attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic' attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context) diff --git a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec index 4fba14c34..83cac55c6 100644 --- a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec +++ b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec @@ -19,7 +19,8 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/open-telemetry/opentelemetry-ruby-contrib' spec.license = 'Apache-2.0' - spec.files = Dir.glob('lib/**/*.rb') + + spec.files = + Dir.glob('lib/**/*.rb') + Dir.glob('*.md') + ['LICENSE', '.yardopts'] spec.require_paths = ['lib'] From bbb8d49e8fcce80afc3331a67d6f20d93c931335 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 5 Sep 2024 11:29:52 -0700 Subject: [PATCH 3/8] Revise based on feedback --- .../aws_sdk/instrumentation.rb | 35 +---- .../aws_sdk/messaging_helper.rb | 1 - .../instrumentation/aws_sdk/services.rb | 121 ------------------ 3 files changed, 4 insertions(+), 153 deletions(-) delete mode 100644 instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/services.rb diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index 6173074b2..c58114d92 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -10,11 +10,10 @@ module AwsSdk # Instrumentation class that detects and installs the AwsSdk instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base MINIMUM_VERSION = Gem::Version.new('2.0.0') - CURRENT_MAJOR_VERSION = Gem::Version.new('3.0.0') install do |_config| require_dependencies - add_plugins(Seahorse::Client::Base, *loaded_constants) + add_plugins(Seahorse::Client::Base, *loaded_service_clients) end present do @@ -42,7 +41,6 @@ def gem_version def require_dependencies require_relative 'handler' - require_relative 'services' require_relative 'message_attributes' require_relative 'messaging_helper' end @@ -51,18 +49,10 @@ def add_plugins(*targets) targets.each { |klass| klass.add_plugin(AwsSdk::Plugin) } end - def loaded_constants - if gem_version >= CURRENT_MAJOR_VERSION - load_v3_constants - else - load_legacy_constants - end - end - - def load_v3_constants + def loaded_service_clients ::Aws.constants.each_with_object([]) do |c, constants| m = ::Aws.const_get(c) - next unless unloaded_service?(c, m) + next unless loaded_service?(c, m) begin constants << m.const_get(:Client) @@ -72,29 +62,12 @@ def load_v3_constants end end - def unloaded_service?(constant, service_module) + def loaded_service?(constant, service_module) !::Aws.autoload?(constant) && service_module.is_a?(Module) && service_module.const_defined?(:Client) && (service_module.const_get(:Client).superclass == Seahorse::Client::Base) end - - def load_legacy_constants - # Cross-check services against loaded AWS constants - # Module#const_get can return a constant from ancestors when there's a miss. - # If this coincidentally matches another constant, it will attempt to patch - # the wrong constant, resulting in patch failure. - available_services = ::Aws.constants & SERVICES.map(&:to_sym) - available_services.each_with_object([]) do |service, constants| - next if ::Aws.autoload?(service) - - begin - constants << ::Aws.const_get(service, false).const_get(:Client, false) - rescue StandardError => e - OpenTelemetry.logger.warn("Constant could not be loaded: #{e}") - end - end - end end end end diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb index 7e9225cac..27064aa74 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb @@ -45,7 +45,6 @@ def legacy_span_name(context, client_method) end end - # def apply_span_attributes(attrs, context, service_id, client_method) def apply_span_attributes(context, attrs, client_method, service_id) case service_id when 'SQS' diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/services.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/services.rb deleted file mode 100644 index d0bacb75f..000000000 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/services.rb +++ /dev/null @@ -1,121 +0,0 @@ -# frozen_string_literal: true - -module OpenTelemetry - module Instrumentation - # rubocop:disable Metrics/ModuleLength: - module AwsSdk - SERVICES = %w[ - ACM - APIGateway - AppStream - ApplicationAutoScaling - ApplicationDiscoveryService - Athena - AutoScaling - Batch - Budgets - CloudDirectory - CloudFormation - CloudFront - CloudHSM - CloudHSMV2 - CloudSearch - CloudSearchDomain - CloudTrail - CloudWatch - CloudWatchEvents - CloudWatchLogs - CodeBuild - CodeCommit - CodeDeploy - CodePipeline - CodeStar - CognitoIdentity - CognitoIdentityProvider - CognitoSync - ConfigService - CostandUsageReportService - DAX - DataPipeline - DatabaseMigrationService - DeviceFarm - DirectConnect - DirectoryService - DynamoDB - DynamoDBStreams - EC2 - ECR - ECS - EFS - EMR - ElastiCache - ElasticBeanstalk - ElasticLoadBalancing - ElasticLoadBalancingV2 - ElasticTranscoder - ElasticsearchService - EventBridge - Firehose - GameLift - Glacier - Glue - Greengrass - Health - IAM - ImportExport - Inspector - IoT - IoTDataPlane - KMS - Kinesis - KinesisAnalytics - Lambda - LambdaPreview - Lex - LexModelBuildingService - Lightsail - MTurk - MachineLearning - MarketplaceCommerceAnalytics - MarketplaceEntitlementService - MarketplaceMetering - MigrationHub - Mobile - OpsWorks - OpsWorksCM - Organizations - Pinpoint - Polly - RDS - Redshift - Rekognition - ResourceGroupsTaggingAPI - Route53 - Route53Domains - S3 - SES - SMS - SNS - SQS - SSM - STS - SWF - ServiceCatalog - Schemas - Shield - SimpleDB - Snowball - States - StorageGateway - Support - Textract - WAF - WAFRegional - WorkDocs - WorkSpaces - XRay - ].freeze - end - # rubocop:enable Metrics/ModuleLength: - end -end From 5f91b942c7de5bfc6814c7ec8a48829930f65a89 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 5 Sep 2024 14:36:22 -0700 Subject: [PATCH 4/8] Fix CI --- .../aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec index 83cac55c6..2bf5088f7 100644 --- a/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec +++ b/instrumentation/aws_sdk/opentelemetry-instrumentation-aws_sdk.gemspec @@ -30,10 +30,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1' spec.add_development_dependency 'appraisal', '~> 2.5' - spec.add_development_dependency 'aws-sdk-dynamodb' - spec.add_development_dependency 'aws-sdk-s3' - spec.add_development_dependency 'aws-sdk-sns' - spec.add_development_dependency 'aws-sdk-sqs' spec.add_development_dependency 'bundler', '~> 2.4' spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1' From f954824fb1153229a92296c4e163bc25ecd162e1 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Fri, 6 Sep 2024 10:43:48 -0700 Subject: [PATCH 5/8] Correctly handle V2 service clients --- .../opentelemetry/instrumentation/aws_sdk/instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index c58114d92..5fed9fd3a 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -66,7 +66,7 @@ def loaded_service?(constant, service_module) !::Aws.autoload?(constant) && service_module.is_a?(Module) && service_module.const_defined?(:Client) && - (service_module.const_get(:Client).superclass == Seahorse::Client::Base) + (service_module.const_get(:Client).superclass == Seahorse::Client::Base || Aws::Client) end end end From ef15a172ab1a32c79d972b60ccdceda31fdf949e Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 12 Sep 2024 09:23:55 -0700 Subject: [PATCH 6/8] Add comments --- .../opentelemetry/instrumentation/aws_sdk/instrumentation.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index 5fed9fd3a..80162e3b7 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -62,6 +62,11 @@ def loaded_service_clients end end + # This check does the following: + # 1 - Checks if the service client is autoload or not + # 2 - Validates whether if is a service client + # note that Seahorse::Client::Base is a superclass for V3 clients + # but for V2, it is Aws::Client def loaded_service?(constant, service_module) !::Aws.autoload?(constant) && service_module.is_a?(Module) && From 029dca26ad75654c8adc6afeac8add0726374be9 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 12 Sep 2024 13:13:33 -0700 Subject: [PATCH 7/8] Fix loaded_service check --- .../opentelemetry/instrumentation/aws_sdk/instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index 80162e3b7..917066992 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -71,7 +71,7 @@ def loaded_service?(constant, service_module) !::Aws.autoload?(constant) && service_module.is_a?(Module) && service_module.const_defined?(:Client) && - (service_module.const_get(:Client).superclass == Seahorse::Client::Base || Aws::Client) + [Seahorse::Client::Base, Aws::Client].include?(service_module.const_get(:Client).superclass) end end end From 4fc85388c35bf7b1d001510d077546933c6e3449 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Thu, 12 Sep 2024 21:10:34 -0700 Subject: [PATCH 8/8] Fix loaded_service check to be compatible with V3 --- .../opentelemetry/instrumentation/aws_sdk/instrumentation.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb index 917066992..928b9b98e 100644 --- a/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb +++ b/instrumentation/aws_sdk/lib/opentelemetry/instrumentation/aws_sdk/instrumentation.rb @@ -71,7 +71,8 @@ def loaded_service?(constant, service_module) !::Aws.autoload?(constant) && service_module.is_a?(Module) && service_module.const_defined?(:Client) && - [Seahorse::Client::Base, Aws::Client].include?(service_module.const_get(:Client).superclass) + (service_module.const_get(:Client).superclass == Seahorse::Client::Base || + service_module.const_get(:Client).superclass == Aws::Client) end end end