From e0e7e3ed11249b585e2e11f9fc20d7d2f47923d3 Mon Sep 17 00:00:00 2001 From: mrickard Date: Wed, 23 Oct 2024 14:38:39 -0400 Subject: [PATCH 1/2] feat: Added cloud.resource_id and cloud.platform to agent attributes for Lambda traces Signed-off-by: mrickard --- lib/serverless/aws-lambda.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/serverless/aws-lambda.js b/lib/serverless/aws-lambda.js index 3d3d2843e1..8df11be080 100644 --- a/lib/serverless/aws-lambda.js +++ b/lib/serverless/aws-lambda.js @@ -249,7 +249,9 @@ class AwsLambda { _getAwsAgentAttributes(event, context) { const attributes = { 'aws.lambda.arn': context.invokedFunctionArn, - 'aws.requestId': context.awsRequestId + 'aws.requestId': context.awsRequestId, + 'cloud.resource_id': context.invokedFunctionArn, + 'cloud.platform': 'aws_lambda' } const eventSourceInfo = this._detectEventType(event) From 78068429f03c419ce4bee321f876a4e9ea8d2f65 Mon Sep 17 00:00:00 2001 From: mrickard Date: Wed, 23 Oct 2024 15:38:20 -0400 Subject: [PATCH 2/2] feat: Added unit tests for cloud properties Signed-off-by: mrickard --- test/unit/serverless/aws-lambda.test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/unit/serverless/aws-lambda.test.js b/test/unit/serverless/aws-lambda.test.js index 2fd3772379..bd59dd60f2 100644 --- a/test/unit/serverless/aws-lambda.test.js +++ b/test/unit/serverless/aws-lambda.test.js @@ -25,6 +25,8 @@ const LAMBDA_ARN = 'aws.lambda.arn' const COLDSTART = 'aws.lambda.coldStart' const EVENTSOURCE_ARN = 'aws.lambda.eventSource.arn' const EVENTSOURCE_TYPE = 'aws.lambda.eventSource.eventType' +const PLATFORM = 'cloud.platform' +const RESOURCE_ID = 'cloud.resource_id' function getMetrics(agent) { return agent.metrics._metrics @@ -62,7 +64,8 @@ test('AwsLambda.patchLambdaHandler', async (t) => { functionVersion: 'TestVersion', invokedFunctionArn: 'arn:test:function', memoryLimitInMB: '128', - awsRequestId: 'testid' + awsRequestId: 'testid', + platform: 'aws_lambda' } ctx.nr.stubCallback = () => {} @@ -624,7 +627,8 @@ test('AwsLambda.patchLambdaHandler', async (t) => { assert.equal(txTrace[REQ_ID], stubContext.awsRequestId) assert.equal(txTrace[LAMBDA_ARN], stubContext.invokedFunctionArn) assert.equal(txTrace[COLDSTART], true) - + assert.equal(txTrace[PLATFORM], stubContext.platform) + assert.equal(txTrace[RESOURCE_ID], stubContext.invokedFunctionArn) end() }