@@ -20,6 +20,7 @@ const {
2020 ATTR_DB_STATEMENT ,
2121 ATTR_DB_SYSTEM ,
2222 ATTR_GRPC_STATUS_CODE ,
23+ ATTR_FAAS_INVOKED_PROVIDER ,
2324 ATTR_FULL_URL ,
2425 ATTR_HTTP_HOST ,
2526 ATTR_HTTP_METHOD ,
@@ -56,6 +57,12 @@ test.beforeEach((ctx) => {
5657 const agent = helper . instrumentMockedAgent ( {
5758 feature_flag : {
5859 opentelemetry_bridge : true
60+ } ,
61+ // for AWS entity linking tests
62+ cloud : {
63+ aws : {
64+ account_id : 123456789123
65+ }
5966 }
6067 } )
6168 const api = helper . getAgentApi ( )
@@ -289,14 +296,14 @@ test('client span(db) is bridge accordingly(statement test)', (t, end) => {
289296 const metrics = tx . metrics . scoped [ tx . name ]
290297 assert . equal ( metrics [ 'Datastore/statement/postgresql/test/select' ] . callCount , 1 )
291298 const unscopedMetrics = tx . metrics . unscoped
292- ; [
299+ ; [
293300 'Datastore/all' ,
294301 'Datastore/allWeb' ,
295302 'Datastore/postgresql/all' ,
296303 'Datastore/postgresql/allWeb' ,
297304 'Datastore/operation/postgresql/select' ,
298305 'Datastore/statement/postgresql/test/select' ,
299- `Datastore/instance/postgresql/${ expectedHost } /5436`
306+ `Datastore/instance/postgresql/${ expectedHost } /5436`
300307 ] . forEach ( ( expectedMetric ) => {
301308 assert . equal ( unscopedMetrics [ expectedMetric ] . callCount , 1 )
302309 } )
@@ -338,13 +345,13 @@ test('client span(db) is bridged accordingly(operation test)', (t, end) => {
338345 const metrics = tx . metrics . scoped [ tx . name ]
339346 assert . equal ( metrics [ 'Datastore/operation/redis/hset' ] . callCount , 1 )
340347 const unscopedMetrics = tx . metrics . unscoped
341- ; [
348+ ; [
342349 'Datastore/all' ,
343350 'Datastore/allWeb' ,
344351 'Datastore/redis/all' ,
345352 'Datastore/redis/allWeb' ,
346353 'Datastore/operation/redis/hset' ,
347- `Datastore/instance/redis/${ expectedHost } /5436`
354+ `Datastore/instance/redis/${ expectedHost } /5436`
348355 ] . forEach ( ( expectedMetric ) => {
349356 assert . equal ( unscopedMetrics [ expectedMetric ] . callCount , 1 )
350357 } )
@@ -808,6 +815,81 @@ test('Span errors are not added on transaction when span status code is not erro
808815 } )
809816} )
810817
818+ test ( 'aws dynamodb span has correct entity linking attributes' , ( t , end ) => {
819+ const { agent, tracer } = t . nr
820+ const attributes = {
821+ [ ATTR_DB_NAME ] : 'test-db' ,
822+ [ ATTR_DB_SYSTEM ] : DB_SYSTEM_VALUES . DYNAMODB ,
823+ [ ATTR_DB_STATEMENT ] : 'select foo from test-table where foo = "bar"' ,
824+ 'aws.region' : 'us-east-1' ,
825+ 'aws.dynamodb.table_names' : [ 'test-table' ]
826+ }
827+ helper . runInTransaction ( agent , ( tx ) => {
828+ tx . name = 'db-test'
829+ tracer . startActiveSpan ( 'db-test' , { kind : otel . SpanKind . CLIENT , attributes } , ( span ) => {
830+ const segment = agent . tracer . getSegment ( )
831+ span . end ( )
832+ const duration = hrTimeToMilliseconds ( span . duration )
833+ assert . equal ( duration , segment . getDurationInMillis ( ) )
834+ tx . end ( )
835+ const attrs = segment . getAttributes ( )
836+ assert . equal ( attrs [ 'cloud.resource_id' ] , 'arn:aws:dynamodb:us-east-1:123456789123:table/test-table' )
837+ end ( )
838+ } )
839+ } )
840+ } )
841+
842+ test ( 'aws lambda span has correct entity linking attributes' , ( t , end ) => {
843+ const { agent, tracer } = t . nr
844+ // see: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/semantic_conventions/faas.md#example "Span A"
845+ const attributes = {
846+ 'faas.invoked_name' : 'test-function' ,
847+ [ ATTR_FAAS_INVOKED_PROVIDER ] : 'aws' ,
848+ 'faas.invoked_region' : 'us-east-1'
849+ }
850+ helper . runInTransaction ( agent , ( tx ) => {
851+ tx . name = 'lambda-test'
852+ tracer . startActiveSpan ( 'lambda-test' , { kind : otel . SpanKind . CLIENT , attributes } , ( span ) => {
853+ const segment = agent . tracer . getSegment ( )
854+ span . end ( )
855+ const duration = hrTimeToMilliseconds ( span . duration )
856+ assert . equal ( duration , segment . getDurationInMillis ( ) )
857+ tx . end ( )
858+ const attrs = segment . getAttributes ( )
859+ assert . equal ( attrs [ 'cloud.resource_id' ] , 'arn:aws:lambda:us-east-1:123456789123:function:test-function' )
860+ assert . equal ( attrs [ 'cloud.platform' ] , 'aws_lambda' )
861+ end ( )
862+ } )
863+ } )
864+ } )
865+
866+ test ( 'aws sqs span has correct entity linking attributes' , ( t , end ) => {
867+ const { agent, tracer } = t . nr
868+ // see: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/b520d048465d9b3dfdf275976010c989d2a78a2c/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts#L62
869+ const attributes = {
870+ 'rpc.service' : 'sqs' ,
871+ [ ATTR_MESSAGING_DESTINATION_KIND ] : MESSAGING_SYSTEM_KIND_VALUES . QUEUE ,
872+ [ ATTR_MESSAGING_DESTINATION ] : 'test-queue' ,
873+ 'aws.region' : 'us-east-1'
874+ }
875+ helper . runInTransaction ( agent , ( tx ) => {
876+ tx . name = 'sqs-test'
877+ tracer . startActiveSpan ( 'sqs-test' , { kind : otel . SpanKind . PRODUCER , attributes } , ( span ) => {
878+ const segment = agent . tracer . getSegment ( )
879+ span . end ( )
880+ const duration = hrTimeToMilliseconds ( span . duration )
881+ assert . equal ( duration , segment . getDurationInMillis ( ) )
882+ tx . end ( )
883+ const attrs = segment . getAttributes ( )
884+ assert . equal ( attrs [ 'cloud.account.id' ] , agent . config . cloud . aws . account_id )
885+ assert . equal ( attrs [ 'cloud.region' ] , 'us-east-1' )
886+ assert . equal ( attrs [ 'messaging.destination.name' ] , 'test-queue' )
887+ assert . equal ( attrs [ 'messaging.system' ] , 'aws_sqs' )
888+ end ( )
889+ } )
890+ } )
891+ } )
892+
811893function setupDtHeaders ( agent ) {
812894 agent . config . trusted_account_key = 1
813895 agent . config . primary_application_id = 2
0 commit comments