File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -582,6 +582,15 @@ describe("extractTraceContext", () => {
582
582
source : Source . Event ,
583
583
} ) ;
584
584
} ) ;
585
+ it ( "returns an empty context when headers are null" , ( ) => {
586
+ const result = extractTraceContext (
587
+ {
588
+ headers : null ,
589
+ } ,
590
+ { } as Context ,
591
+ ) ;
592
+ expect ( result ) . toEqual ( undefined ) ;
593
+ } ) ;
585
594
it ( "returns trace read from event with the extractor as the highest priority" , ( ) => {
586
595
process . env [ "_X_AMZN_TRACE_ID" ] = "Root=1-5ce31dc2-2c779014b90ce44db5e03875;Parent=0b11cc4230d3e09e;Sampled=1" ;
587
596
Original file line number Diff line number Diff line change @@ -287,11 +287,11 @@ export function readTraceFromHTTPEvent(event: any): TraceContext | undefined {
287
287
}
288
288
289
289
export function readTraceFromEvent ( event : any ) : TraceContext | undefined {
290
- if ( typeof event !== "object" ) {
290
+ if ( ! event || typeof event !== "object" ) {
291
291
return ;
292
292
}
293
293
294
- if ( typeof event . headers === "object" ) {
294
+ if ( event . headers !== null && typeof event . headers === "object" ) {
295
295
return readTraceFromHTTPEvent ( event ) ;
296
296
}
297
297
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export interface HTTPError {
14
14
statusCode ?: number ;
15
15
}
16
16
export function isHTTPError ( error : any ) : error is HTTPError {
17
- return typeof error === "object" && Object . values ( HTTPErrorType ) . includes ( error . type ) ;
17
+ return typeof error === "object" && error !== null && Object . values ( HTTPErrorType ) . includes ( error . type ) ;
18
18
}
19
19
20
20
export function post < T > ( url : URL , body : T , options ?: Partial < RequestOptions > ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments