lib/opentelemetry/instrumentation/aws_sdk/handler.rb in opentelemetry-instrumentation-aws_sdk-0.6.0 vs lib/opentelemetry/instrumentation/aws_sdk/handler.rb in opentelemetry-instrumentation-aws_sdk-0.7.0
- old
+ new
@@ -5,30 +5,27 @@
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
module Instrumentation
module AwsSdk
- # Generates Spans for all interactions with AwsSdk
+ # This handler supports specifically supports V2 and V3
+ # prior to Observability support released on 2024-09-03.
class Handler < Seahorse::Client::Handler
def call(context)
return super unless context
- service_id = service_name(context)
- operation = context.operation&.name
- client_method = "#{service_id}.#{operation}"
+ service_id = HandlerHelper.service_id(context, legacy: true)
+ client_method = HandlerHelper.client_method(service_id, context)
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)
+ HandlerHelper.span_name(context, client_method, service_id, legacy: true),
+ attributes: HandlerHelper.span_attributes(context, client_method, service_id, legacy: true),
+ kind: HandlerHelper.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
+ MessagingHelper.inject_context_if_supported(context, client_method, service_id)
- if instrumentation_config[:suppress_internal_instrumentation]
+ if HandlerHelper.instrumentation_config[:suppress_internal_instrumentation]
OpenTelemetry::Common::Utilities.untraced { super }
else
super
end.tap do |response|
span.set_attribute(
@@ -46,50 +43,9 @@
private
def tracer
AwsSdk::Instrumentation.instance.tracer
- end
-
- def instrumentation_config
- AwsSdk::Instrumentation.instance.config
- end
-
- def service_name(context)
- # Support aws-sdk v2.0.x, which 'metadata' has a setter method only
- return context.client.class.to_s.split('::')[1] if ::Seahorse::Model::Api.instance_method(:metadata).parameters.length.positive?
-
- context.client.class.api.metadata['serviceId'] || context.client.class.to_s.split('::')[1]
- end
-
- def span_kind(client_method, service_id)
- case service_id
- when 'SQS', 'SNS'
- MessagingHelper.span_kind(client_method)
- else
- OpenTelemetry::Trace::SpanKind::CLIENT
- end
- end
-
- def span_name(context, client_method, service_id)
- case service_id
- when 'SQS', 'SNS'
- MessagingHelper.legacy_span_name(context, client_method)
- else
- client_method
- end
- end
-
- 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