File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * If the AWS_XRAY_CONTEXT_MISSING environment variable is not set, we set it to IGNORE_ERROR.
3+ *
4+ * This is to prevent the AWS X-Ray SDK from logging errors when using top-level await features that make HTTP requests.
5+ * For example, when using the Parameters utility to fetch parameters during the initialization of the Lambda handler - See #2046
6+ */
7+ if (
8+ process . env . AWS_XRAY_CONTEXT_MISSING === '' ||
9+ process . env . AWS_XRAY_CONTEXT_MISSING === undefined
10+ ) {
11+ process . env . AWS_XRAY_CONTEXT_MISSING = 'IGNORE_ERROR' ;
12+ }
113import { Utility } from '@aws-lambda-powertools/commons' ;
214import type {
315 AsyncHandler ,
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ describe('Class: Tracer', () => {
5959 } ) ;
6060
6161 describe ( 'Method: constructor' , ( ) => {
62+ it ( 'sets the AWS_XRAY_CONTEXT_MISSING environment variable to IGNORE_ERROR when it is not set' , ( ) => {
63+ // We are setting the environment variable as a side effect of importing the module, setting it within the Tracer would
64+ // require introducing async code to the constructor, which is not a good practice, in order to lazy load the AWS X-Ray SDK for Node.js
65+ // on demand. Between that option, and setting it as a side effect of importing the module, the latter is the better option.
66+ expect ( process . env . AWS_XRAY_CONTEXT_MISSING ) . toBe ( 'IGNORE_ERROR' ) ;
67+ } ) ;
68+
6269 it ( 'instantiates with default settings when no option is passed' , ( ) => {
6370 // Prepare & Act
6471 const tracer = new Tracer ( undefined ) ;
You can’t perform that action at this time.
0 commit comments