Skip to content

Commit 0c65a39

Browse files
committed
chore: use original fetch for sending spans
1 parent e603858 commit 0c65a39

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/lambda-layer/lib/utils/httpSpansAgent.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { SQSClient, SendMessageCommand } = require("@aws-sdk/client-sqs");
2+
const { FetchHttpHandler } = require("@smithy/fetch-http-handler");
23

34
/*
45
* This module handles sending spans to an SQS queue.
@@ -12,9 +13,14 @@ exports.HttpSpansAgent = (() => {
1213
let sqsClient;
1314

1415
const initAgent = () => {
15-
sqsClient = new SQSClient({
16-
region: process.env.AUTO_TRACE_QUEUE_REGION || "eu-west-1",
17-
});
16+
try {
17+
sqsClient = new SQSClient({
18+
region: process.env.AUTO_TRACE_QUEUE_REGION || "eu-west-1",
19+
requestHandler: new FetchHttpHandler({}),
20+
});
21+
} catch (error) {
22+
console.warn("Error initializing SQS client:", error);
23+
}
1824
};
1925

2026
const cleanSessionInstance = () => {
@@ -37,6 +43,19 @@ exports.HttpSpansAgent = (() => {
3743
},
3844
MessageBody: JSON.stringify(requestBody),
3945
});
46+
47+
// This is a workaround to avoid the fetch function being overridden
48+
// @ts-ignore
49+
if (fetch && fetch.__originalFetch) {
50+
const wrappedFetch = fetch;
51+
// @ts-ignore
52+
fetch = wrappedFetch.__originalFetch;
53+
setTimeout(() => {
54+
// @ts-ignore
55+
fetch = wrappedFetch;
56+
}, 1);
57+
}
58+
4059
await sqsClient.send(command);
4160
} catch (error) {
4261
console.warn("Error sending trace spans:", error);

packages/lambda-layer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"@aws-sdk/client-sqs": "^3.777.0",
2222
"@lumigo/tracer": "^1.107.1",
23+
"@smithy/fetch-http-handler": "^5.0.2",
2324
"axios": "^1.8.4",
2425
"node-fetch": "^3.3.2"
2526
},

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9520,6 +9520,7 @@ __metadata:
95209520
dependencies:
95219521
"@aws-sdk/client-sqs": "npm:^3.777.0"
95229522
"@lumigo/tracer": "npm:^1.107.1"
9523+
"@smithy/fetch-http-handler": "npm:^5.0.2"
95239524
"@types/jest": "npm:^29.5.14"
95249525
axios: "npm:^1.8.4"
95259526
esbuild: "npm:^0.25.1"

0 commit comments

Comments
 (0)