@@ -43,6 +43,8 @@ async function buildLambdaLayer(): Promise<void> {
4343 'build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless/dist/awslambda-auto.js' ,
4444 ) ;
4545
46+ replaceSDKSource ( ) ;
47+
4648 const zipFilename = `sentry-node-serverless-${ version } .zip` ;
4749 console . log ( `Creating final layer zip file ${ zipFilename } .` ) ;
4850 // need to preserve the symlink above with -y
@@ -178,3 +180,30 @@ function buildPackageJson(): void {
178180 const packageJsonPath = './build/aws/dist-serverless/nodejs/package.json' ;
179181 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
180182}
183+
184+ function replaceSDKSource ( ) : void {
185+ console . log ( 'Replacing SDK source.' ) ;
186+
187+ const envFiles = [
188+ './build/aws/dist-serverless/nodejs/node_modules/@sentry/core/build/cjs/utils/env.js' ,
189+ './build/aws/dist-serverless/nodejs/node_modules/@sentry/core/build/esm/utils/env.js' ,
190+ ] ;
191+
192+ for ( const envFile of envFiles ) {
193+ try {
194+ let content = fs . readFileSync ( envFile , 'utf-8' ) ;
195+
196+ // Replace the line marked with __SENTRY_SDK_SOURCE__ comment
197+ // Change from 'npm' to 'aws-lambda-layer' to identify that this is the AWS Lambda layer
198+ content = content . replace (
199+ "/* __SENTRY_SDK_SOURCE__ */ return 'npm';" ,
200+ "/* __SENTRY_SDK_SOURCE__ */ return 'aws-lambda-layer';" ,
201+ ) ;
202+
203+ fs . writeFileSync ( envFile , content ) ;
204+ console . log ( `Updated SDK source in ${ envFile } ` ) ;
205+ } catch {
206+ console . warn ( `Warning: Could not update SDK source in ${ envFile } ` ) ;
207+ }
208+ }
209+ }
0 commit comments