File tree 2 files changed +19
-0
lines changed
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
+ }
1
13
import { Utility } from '@aws-lambda-powertools/commons' ;
2
14
import type {
3
15
AsyncHandler ,
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ describe('Class: Tracer', () => {
59
59
} ) ;
60
60
61
61
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
+
62
69
it ( 'instantiates with default settings when no option is passed' , ( ) => {
63
70
// Prepare & Act
64
71
const tracer = new Tracer ( undefined ) ;
You can’t perform that action at this time.
0 commit comments