Class: OpenTelemetry::Instrumentation::AwsSdk::Handler

Inherits:
Seahorse::Client::Handler
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/aws_sdk/handler.rb

Overview

Generates Spans for all interactions with AwsSdk

Instance Method Summary collapse

Instance Method Details

#call(context) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/opentelemetry/instrumentation/aws_sdk/handler.rb', line 12

def call(context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  return super unless context

  service_name = context.client.class.api.['serviceId'] || context.client.class.to_s.split('::')[1]
  operation = context.operation&.name
  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'

  tracer.in_span("#{service_name}.#{operation}", attributes: attributes, kind: OpenTelemetry::Trace::SpanKind::CLIENT) do |span|
    if instrumentation_config[:suppress_internal_instrumentation]
      OpenTelemetry::Common::Utilities.untraced { super }
    else
      super
    end.tap do |response|
      if (err = response.error)
        span.record_exception(err)
        span.status = Trace::Status.error(err)
      end
    end
  end
end