1414use OpenTelemetry \API \Trace \StatusCode ;
1515use OpenTelemetry \Context \Context ;
1616use function OpenTelemetry \Instrumentation \hook ;
17+ use OpenTelemetry \SemConv \TraceAttributes ;
1718
1819final class AwsSdkInstrumentation
1920{
@@ -38,22 +39,22 @@ public static function register(): void
3839 AwsClient $ c ,
3940 array $ params ,
4041 string $ class ,
41- string $ func ,
42- ?string $ file ,
43- ?int $ line
42+ string $ function ,
43+ ?string $ filename ,
44+ ?int $ lineno
4445 ) use ($ inst ) {
4546 $ cmd = $ params [0 ];
4647 $ builder = $ inst ->tracer ()
4748 ->spanBuilder ("{$ c ->getApi ()->getServiceName ()}. {$ cmd ->getName ()}" )
4849 ->setSpanKind (SpanKind::KIND_CLIENT )
49- ->setAttribute (' rpc.system ' , 'aws-api ' )
50- ->setAttribute (' rpc.method ' , $ cmd ->getName ())
51- ->setAttribute (' rpc.service ' , $ c ->getApi ()->getServiceName ())
52- ->setAttribute (' aws.region ' , $ c ->getRegion ())
53- ->setAttribute (' code.function ' , $ func )
54- ->setAttribute (' code.namespace ' , $ class )
55- ->setAttribute (' code.filepath ' , $ file )
56- ->setAttribute (' code.line_number ' , $ line );
50+ ->setAttribute (TraceAttributes:: RPC_SYSTEM , 'aws-api ' )
51+ ->setAttribute (TraceAttributes:: RPC_METHOD , $ cmd ->getName ())
52+ ->setAttribute (TraceAttributes:: RPC_SERVICE , $ c ->getApi ()->getServiceName ())
53+ ->setAttribute (TraceAttributes:: CLOUD_REGION , $ c ->getRegion ())
54+ ->setAttribute (TraceAttributes:: CODE_FUNCTION_NAME , $ function )
55+ ->setAttribute (TraceAttributes:: CODE_NAMESPACE , $ class )
56+ ->setAttribute (TraceAttributes:: CODE_FILEPATH , $ filename )
57+ ->setAttribute (TraceAttributes:: CODE_LINE_NUMBER , $ lineno );
5758
5859 $ span = $ builder ->startSpan ();
5960 Context::storage ()->attach ($ span ->storeInContext (Context::getCurrent ()));
@@ -72,12 +73,12 @@ public static function register(): void
7273 $ scope ->detach ();
7374
7475 if ($ result instanceof ResultInterface && isset ($ result ['@metadata ' ])) {
75- $ span ->setAttribute (' http.status_code ' , $ result ['@metadata ' ]['statusCode ' ]);
76- $ span ->setAttribute (' aws.requestId ' , $ result ['@metadata ' ]['headers ' ]['x-amz-request-id ' ]);
76+ $ span ->setAttribute (TraceAttributes:: HTTP_RESPONSE_STATUS_CODE , $ result ['@metadata ' ]['statusCode ' ]);
77+ $ span ->setAttribute (TraceAttributes:: AWS_REQUEST_ID , $ result ['@metadata ' ]['headers ' ]['x-amz-request-id ' ]);
7778 }
7879 if ($ ex ) {
7980 if ($ ex instanceof AwsException && $ ex ->getAwsRequestId () !== null ) {
80- $ span ->setAttribute (' aws.requestId ' , $ ex ->getAwsRequestId ());
81+ $ span ->setAttribute (TraceAttributes:: AWS_REQUEST_ID , $ ex ->getAwsRequestId ());
8182 }
8283 $ span ->recordException ($ ex );
8384 $ span ->setStatus (StatusCode::STATUS_ERROR , $ ex ->getMessage ());
0 commit comments