@@ -22,6 +22,7 @@ describe('init', () => {
2222 // Clean up environment variables between tests
2323 delete process . env . http_proxy ;
2424 delete process . env . no_proxy ;
25+ delete process . env . SENTRY_LAYER_EXTENSION ;
2526 } ) ;
2627
2728 describe ( 'Lambda extension setup' , ( ) => {
@@ -386,4 +387,173 @@ describe('init', () => {
386387 ) ;
387388 } ) ;
388389 } ) ;
390+
391+ describe ( 'SENTRY_LAYER_EXTENSION environment variable' , ( ) => {
392+ test ( 'should enable useLayerExtension when SENTRY_LAYER_EXTENSION=true' , ( ) => {
393+ process . env . SENTRY_LAYER_EXTENSION = 'true' ;
394+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
395+ const options : AwsServerlessOptions = { } ;
396+
397+ init ( options ) ;
398+
399+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
400+ expect . objectContaining ( {
401+ useLayerExtension : true ,
402+ tunnel : 'http://localhost:9000/envelope' ,
403+ } ) ,
404+ ) ;
405+ } ) ;
406+
407+ test ( 'should disable useLayerExtension when SENTRY_LAYER_EXTENSION=false' , ( ) => {
408+ process . env . SENTRY_LAYER_EXTENSION = 'false' ;
409+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
410+ const options : AwsServerlessOptions = { } ;
411+
412+ init ( options ) ;
413+
414+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
415+ expect . objectContaining ( {
416+ useLayerExtension : false ,
417+ } ) ,
418+ ) ;
419+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
420+ expect . not . objectContaining ( {
421+ tunnel : expect . any ( String ) ,
422+ } ) ,
423+ ) ;
424+ } ) ;
425+
426+ test ( 'should support various truthy values (1, yes, on)' , ( ) => {
427+ const truthyValues = [ '1' , 'yes' , 'on' , 'y' , 't' ] ;
428+
429+ truthyValues . forEach ( value => {
430+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
431+ process . env . SENTRY_LAYER_EXTENSION = value ;
432+
433+ init ( { } ) ;
434+
435+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
436+ expect . objectContaining ( {
437+ useLayerExtension : true ,
438+ } ) ,
439+ ) ;
440+ } ) ;
441+ } ) ;
442+
443+ test ( 'should support various falsy values (0, no, off)' , ( ) => {
444+ const falsyValues = [ '0' , 'no' , 'off' , 'n' , 'f' ] ;
445+
446+ falsyValues . forEach ( value => {
447+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
448+ process . env . SENTRY_LAYER_EXTENSION = value ;
449+
450+ init ( { } ) ;
451+
452+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
453+ expect . objectContaining ( {
454+ useLayerExtension : false ,
455+ } ) ,
456+ ) ;
457+ } ) ;
458+ } ) ;
459+
460+ test ( 'should fall back to default behavior when SENTRY_LAYER_EXTENSION is not set' , ( ) => {
461+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
462+ const options : AwsServerlessOptions = { } ;
463+
464+ init ( options ) ;
465+
466+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
467+ expect . objectContaining ( {
468+ useLayerExtension : true ,
469+ tunnel : 'http://localhost:9000/envelope' ,
470+ } ) ,
471+ ) ;
472+ } ) ;
473+
474+ test ( 'should fall back to default behavior when SENTRY_LAYER_EXTENSION has invalid value' , ( ) => {
475+ process . env . SENTRY_LAYER_EXTENSION = 'invalid' ;
476+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
477+ const options : AwsServerlessOptions = { } ;
478+
479+ init ( options ) ;
480+
481+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
482+ expect . objectContaining ( {
483+ useLayerExtension : true ,
484+ tunnel : 'http://localhost:9000/envelope' ,
485+ } ) ,
486+ ) ;
487+ } ) ;
488+
489+ test ( 'should prioritize explicit option over environment variable' , ( ) => {
490+ process . env . SENTRY_LAYER_EXTENSION = 'true' ;
491+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
492+ const options : AwsServerlessOptions = {
493+ useLayerExtension : false ,
494+ } ;
495+
496+ init ( options ) ;
497+
498+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
499+ expect . objectContaining ( {
500+ useLayerExtension : false ,
501+ } ) ,
502+ ) ;
503+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
504+ expect . not . objectContaining ( {
505+ tunnel : expect . any ( String ) ,
506+ } ) ,
507+ ) ;
508+ } ) ;
509+
510+ test ( 'should respect environment variable when explicit option is not provided' , ( ) => {
511+ process . env . SENTRY_LAYER_EXTENSION = 'false' ;
512+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
513+ const options : AwsServerlessOptions = { } ;
514+
515+ init ( options ) ;
516+
517+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
518+ expect . objectContaining ( {
519+ useLayerExtension : false ,
520+ } ) ,
521+ ) ;
522+ } ) ;
523+
524+ test ( 'should enable useLayerExtension via env var even with proxy when explicitly set' , ( ) => {
525+ process . env . http_proxy = 'http://proxy.example.com:8080' ;
526+ process . env . SENTRY_LAYER_EXTENSION = 'true' ;
527+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
528+ const options : AwsServerlessOptions = { } ;
529+
530+ init ( options ) ;
531+
532+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
533+ expect . objectContaining ( {
534+ useLayerExtension : true ,
535+ tunnel : 'http://localhost:9000/envelope' ,
536+ } ) ,
537+ ) ;
538+ } ) ;
539+
540+ test ( 'should disable useLayerExtension via env var even without proxy' , ( ) => {
541+ process . env . SENTRY_LAYER_EXTENSION = 'false' ;
542+ mockGetSDKSource . mockReturnValue ( 'aws-lambda-layer' ) ;
543+ const options : AwsServerlessOptions = { } ;
544+
545+ init ( options ) ;
546+
547+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
548+ expect . objectContaining ( {
549+ useLayerExtension : false ,
550+ } ) ,
551+ ) ;
552+ expect ( mockInitWithoutDefaultIntegrations ) . toHaveBeenCalledWith (
553+ expect . not . objectContaining ( {
554+ tunnel : expect . any ( String ) ,
555+ } ) ,
556+ ) ;
557+ } ) ;
558+ } ) ;
389559} ) ;
0 commit comments