@@ -9,51 +9,34 @@ module Instrumentation
99 module AwsSdk
1010 # Generates Spans for all interactions with AwsSdk
1111 class Handler < Seahorse ::Client ::Handler
12- def call ( context )
13- span_name = get_span_name ( context )
14- attributes = get_span_attributes ( context )
12+ def call ( context ) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
13+ return super unless context
1514
16- tracer . in_span ( span_name , kind : OpenTelemetry :: Trace :: SpanKind :: CLIENT , attributes : attributes ) do | span |
17- execute = proc {
18- super ( context ) . tap do | response |
19- if ( err = response . error )
20- span . record_exception ( err )
21- span . status = Trace ::Status . error ( err )
22- end
23- end
24- }
15+ service_name = context . client . class . api . metadata [ 'serviceId' ] || context . client . class . to_s . split ( '::' ) [ 1 ]
16+ operation = context . operation &. name
17+ attributes = {
18+ 'aws.region' => context . config . region ,
19+ OpenTelemetry :: SemanticConventions :: Trace :: RPC_SYSTEM => 'aws-api' ,
20+ OpenTelemetry :: SemanticConventions :: Trace ::RPC_METHOD => operation ,
21+ OpenTelemetry :: SemanticConventions :: Trace :: RPC_SERVICE => service_name
22+ }
23+ attributes [ SemanticConventions :: Trace :: DB_SYSTEM ] = 'dynamodb' if service_name == 'DynamoDB'
2524
25+ tracer . in_span ( "#{ service_name } .#{ operation } " , attributes : attributes , kind : OpenTelemetry ::Trace ::SpanKind ::CLIENT ) do |span |
2626 if instrumentation_config [ :suppress_internal_instrumentation ]
27- OpenTelemetry ::Common ::Utilities . untraced ( & execute )
27+ OpenTelemetry ::Common ::Utilities . untraced { super }
2828 else
29- execute . call
29+ super
30+ end . tap do |response |
31+ if ( err = response . error )
32+ span . record_exception ( err )
33+ span . status = Trace ::Status . error ( err )
34+ end
3035 end
3136 end
3237 end
3338
34- def get_span_attributes ( context )
35- span_attributes = {
36- 'aws.region' => context . config . region ,
37- OpenTelemetry ::SemanticConventions ::Trace ::RPC_SYSTEM => 'aws-api' ,
38- OpenTelemetry ::SemanticConventions ::Trace ::RPC_METHOD => get_operation ( context ) ,
39- OpenTelemetry ::SemanticConventions ::Trace ::RPC_SERVICE => get_service_name ( context )
40- }
41-
42- db_attributes = DbHelper . get_db_attributes ( context , get_service_name ( context ) , get_operation ( context ) )
43- span_attributes . merge ( db_attributes )
44- end
45-
46- def get_service_name ( context )
47- context &.client . class . api . metadata [ 'serviceId' ] || context &.client . class . to_s . split ( '::' ) [ 1 ]
48- end
49-
50- def get_operation ( context )
51- context &.operation &.name
52- end
53-
54- def get_span_name ( context )
55- "#{ get_service_name ( context ) } .#{ get_operation ( context ) } "
56- end
39+ private
5740
5841 def tracer
5942 AwsSdk ::Instrumentation . instance . tracer
0 commit comments