@@ -19,47 +19,32 @@ import {
1919 IResource ,
2020 Resource ,
2121 ResourceAttributes ,
22- ResourceDetectionConfig ,
2322} from '@opentelemetry/resources' ;
24- import {
25- SEMRESATTRS_CLOUD_PROVIDER ,
26- SEMRESATTRS_CLOUD_PLATFORM ,
27- SEMRESATTRS_CLOUD_REGION ,
28- SEMRESATTRS_FAAS_VERSION ,
29- SEMRESATTRS_FAAS_NAME ,
30- CLOUDPROVIDERVALUES_AWS ,
31- CLOUDPLATFORMVALUES_AWS_LAMBDA ,
32- } from '@opentelemetry/semantic-conventions' ;
3323
3424/**
3525 * The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda
3626 * and return a {@link Resource} populated with data about the environment.
3727 * Returns an empty Resource if detection fails.
3828 */
3929export class AwsLambdaDetectorSync implements DetectorSync {
40- detect ( _config ?: ResourceDetectionConfig ) : IResource {
30+ detect ( ) : IResource {
31+ const awsRegion = process . env . AWS_REGION ;
4132 const functionName = process . env . AWS_LAMBDA_FUNCTION_NAME ;
42- if ( ! functionName ) {
43- return Resource . empty ( ) ;
44- }
45-
4633 const functionVersion = process . env . AWS_LAMBDA_FUNCTION_VERSION ;
47- const region = process . env . AWS_REGION ;
34+ const logGroupName = process . env . AWS_LAMBDA_LOG_GROUP_NAME ;
35+ const logStreamName = process . env . AWS_LAMBDA_LOG_STREAM_NAME ;
36+ const memorySize = process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE as string ;
4837
4938 const attributes : ResourceAttributes = {
50- [ SEMRESATTRS_CLOUD_PROVIDER ] : String ( CLOUDPROVIDERVALUES_AWS ) ,
51- [ SEMRESATTRS_CLOUD_PLATFORM ] : String ( CLOUDPLATFORMVALUES_AWS_LAMBDA ) ,
39+ 'aws.log.group.names' : [ logGroupName ] ,
40+ 'cloud.provider' : 'aws' ,
41+ 'cloud.platform' : 'aws_lambda' ,
42+ 'cloud.region' : awsRegion ,
43+ 'faas.name' : functionName ,
44+ 'faas.version' : functionVersion ,
45+ 'faas.instance' : logStreamName ,
46+ 'faas.max_memory' : parseInt ( memorySize ) * 1024 * 1024 ,
5247 } ;
53- if ( region ) {
54- attributes [ SEMRESATTRS_CLOUD_REGION ] = region ;
55- }
56-
57- if ( functionName ) {
58- attributes [ SEMRESATTRS_FAAS_NAME ] = functionName ;
59- }
60- if ( functionVersion ) {
61- attributes [ SEMRESATTRS_FAAS_VERSION ] = functionVersion ;
62- }
6348
6449 return new Resource ( attributes ) ;
6550 }
0 commit comments