diff --git a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts index 4b85f44bdc..229dfb911c 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetectorSync.ts @@ -19,17 +19,7 @@ import { IResource, Resource, ResourceAttributes, - ResourceDetectionConfig, } from '@opentelemetry/resources'; -import { - SEMRESATTRS_CLOUD_PROVIDER, - SEMRESATTRS_CLOUD_PLATFORM, - SEMRESATTRS_CLOUD_REGION, - SEMRESATTRS_FAAS_VERSION, - SEMRESATTRS_FAAS_NAME, - CLOUDPROVIDERVALUES_AWS, - CLOUDPLATFORMVALUES_AWS_LAMBDA, -} from '@opentelemetry/semantic-conventions'; /** * The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda @@ -37,29 +27,24 @@ import { * Returns an empty Resource if detection fails. */ export class AwsLambdaDetectorSync implements DetectorSync { - detect(_config?: ResourceDetectionConfig): IResource { + detect(): IResource { + const awsRegion = process.env.AWS_REGION; const functionName = process.env.AWS_LAMBDA_FUNCTION_NAME; - if (!functionName) { - return Resource.empty(); - } - const functionVersion = process.env.AWS_LAMBDA_FUNCTION_VERSION; - const region = process.env.AWS_REGION; + const logGroupName = process.env.AWS_LAMBDA_LOG_GROUP_NAME; + const logStreamName = process.env.AWS_LAMBDA_LOG_STREAM_NAME; + const memorySize = process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE as string; const attributes: ResourceAttributes = { - [SEMRESATTRS_CLOUD_PROVIDER]: String(CLOUDPROVIDERVALUES_AWS), - [SEMRESATTRS_CLOUD_PLATFORM]: String(CLOUDPLATFORMVALUES_AWS_LAMBDA), + 'aws.log.group.names': [logGroupName], + 'cloud.provider': 'aws', + 'cloud.platform': 'aws_lambda', + 'cloud.region': awsRegion, + 'faas.name': functionName, + 'faas.version': functionVersion, + 'faas.instance': logStreamName, + 'faas.max_memory': parseInt(memorySize) * 1024 * 1024, }; - if (region) { - attributes[SEMRESATTRS_CLOUD_REGION] = region; - } - - if (functionName) { - attributes[SEMRESATTRS_FAAS_NAME] = functionName; - } - if (functionVersion) { - attributes[SEMRESATTRS_FAAS_VERSION] = functionVersion; - } return new Resource(attributes); } diff --git a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsLambdaDetectorSync.test.ts b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsLambdaDetectorSync.test.ts index e849dc436f..d1745655a4 100644 --- a/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsLambdaDetectorSync.test.ts +++ b/detectors/node/opentelemetry-resource-detector-aws/test/detectors/AwsLambdaDetectorSync.test.ts @@ -35,9 +35,12 @@ describe('awsLambdaDetectorSync', () => { describe('on lambda', () => { it('fills resource', async () => { + process.env.AWS_REGION = 'us-east-1'; process.env.AWS_LAMBDA_FUNCTION_NAME = 'name'; process.env.AWS_LAMBDA_FUNCTION_VERSION = 'v1'; - process.env.AWS_REGION = 'us-east-1'; + process.env.AWS_LAMBDA_LOG_GROUP_NAME = '/aws/lambda/name'; + process.env.AWS_LAMBDA_LOG_STREAM_NAME = '2024/03/14/[$LATEST]123456'; + process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '128'; const resource = awsLambdaDetectorSync.detect(); @@ -48,6 +51,17 @@ describe('awsLambdaDetectorSync', () => { assert.strictEqual(resource.attributes['faas.name'], 'name'); assert.strictEqual(resource.attributes['faas.version'], 'v1'); + assert.strictEqual( + resource.attributes['faas.instance'], + '2024/03/14/[$LATEST]123456' + ); + assert.strictEqual( + resource.attributes['faas.max_memory'], + 128 * 1024 * 1024 + ); + assert.deepStrictEqual(resource.attributes['aws.log.group.names'], [ + '/aws/lambda/name', + ]); }); });