@@ -20,6 +20,7 @@ const {
20
20
ATTR_DB_STATEMENT ,
21
21
ATTR_DB_SYSTEM ,
22
22
ATTR_GRPC_STATUS_CODE ,
23
+ ATTR_FAAS_INVOKED_PROVIDER ,
23
24
ATTR_FULL_URL ,
24
25
ATTR_HTTP_HOST ,
25
26
ATTR_HTTP_METHOD ,
@@ -56,6 +57,12 @@ test.beforeEach((ctx) => {
56
57
const agent = helper . instrumentMockedAgent ( {
57
58
feature_flag : {
58
59
opentelemetry_bridge : true
60
+ } ,
61
+ // for AWS entity linking tests
62
+ cloud : {
63
+ aws : {
64
+ account_id : 123456789123
65
+ }
59
66
}
60
67
} )
61
68
const api = helper . getAgentApi ( )
@@ -289,14 +296,14 @@ test('client span(db) is bridge accordingly(statement test)', (t, end) => {
289
296
const metrics = tx . metrics . scoped [ tx . name ]
290
297
assert . equal ( metrics [ 'Datastore/statement/postgresql/test/select' ] . callCount , 1 )
291
298
const unscopedMetrics = tx . metrics . unscoped
292
- ; [
299
+ ; [
293
300
'Datastore/all' ,
294
301
'Datastore/allWeb' ,
295
302
'Datastore/postgresql/all' ,
296
303
'Datastore/postgresql/allWeb' ,
297
304
'Datastore/operation/postgresql/select' ,
298
305
'Datastore/statement/postgresql/test/select' ,
299
- `Datastore/instance/postgresql/${ expectedHost } /5436`
306
+ `Datastore/instance/postgresql/${ expectedHost } /5436`
300
307
] . forEach ( ( expectedMetric ) => {
301
308
assert . equal ( unscopedMetrics [ expectedMetric ] . callCount , 1 )
302
309
} )
@@ -338,13 +345,13 @@ test('client span(db) is bridged accordingly(operation test)', (t, end) => {
338
345
const metrics = tx . metrics . scoped [ tx . name ]
339
346
assert . equal ( metrics [ 'Datastore/operation/redis/hset' ] . callCount , 1 )
340
347
const unscopedMetrics = tx . metrics . unscoped
341
- ; [
348
+ ; [
342
349
'Datastore/all' ,
343
350
'Datastore/allWeb' ,
344
351
'Datastore/redis/all' ,
345
352
'Datastore/redis/allWeb' ,
346
353
'Datastore/operation/redis/hset' ,
347
- `Datastore/instance/redis/${ expectedHost } /5436`
354
+ `Datastore/instance/redis/${ expectedHost } /5436`
348
355
] . forEach ( ( expectedMetric ) => {
349
356
assert . equal ( unscopedMetrics [ expectedMetric ] . callCount , 1 )
350
357
} )
@@ -808,6 +815,81 @@ test('Span errors are not added on transaction when span status code is not erro
808
815
} )
809
816
} )
810
817
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
+
811
893
function setupDtHeaders ( agent ) {
812
894
agent . config . trusted_account_key = 1
813
895
agent . config . primary_application_id = 2
0 commit comments