Skip to content

feat(node): Ensure tracePropagationTargets are respected #11285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-packages/browser-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"devDependencies": {
"@types/glob": "8.0.0",
"@types/node": "^14.6.4",
"@types/node": "^14.18.0",
"@types/pako": "^2.0.0",
"glob": "8.0.3"
},
Expand Down
8 changes: 5 additions & 3 deletions dev-packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
},
"devDependencies": {
"@types/glob": "8.0.0",
"@types/node": "^14.6.4",
"@types/node": "^14.18.0",
"dotenv": "16.0.3",
"esbuild": "0.20.0",
"glob": "8.0.3",
"ts-node": "10.9.1",
"yaml": "2.2.2"
"yaml": "2.2.2",
"rimraf": "^3.0.2"
},
"volta": {
"node": "18.18.0",
"yarn": "1.22.19"
"yarn": "1.22.19",
"pnpm": "8.15.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const http = require('http');

const app = fastify();
const port = 3030;
const port2 = 3040;

Sentry.setupFastifyErrorHandler(app);

Expand All @@ -17,20 +18,22 @@ app.get('/test-param/:param', function (req, res) {
res.send({ paramWas: req.params.param });
});

app.get('/test-inbound-headers', function (req, res) {
app.get('/test-inbound-headers/:id', function (req, res) {
const headers = req.headers;

res.send({ headers });
res.send({ headers, id: req.params.id });
});

app.get('/test-outgoing-http', async function (req, res) {
const data = await makeHttpRequest('http://localhost:3030/test-inbound-headers');
app.get('/test-outgoing-http/:id', async function (req, res) {
const id = req.params.id;
const data = await makeHttpRequest(`http://localhost:3030/test-inbound-headers/${id}`);

res.send(data);
});

app.get('/test-outgoing-fetch', async function (req, res) {
const response = await fetch('http://localhost:3030/test-inbound-headers');
app.get('/test-outgoing-fetch/:id', async function (req, res) {
const id = req.params.id;
const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`);
const data = await response.json();

res.send(data);
Expand All @@ -56,8 +59,48 @@ app.get('/test-exception', async function (req, res) {
throw new Error('This is an exception');
});

app.get('/test-outgoing-fetch-external-allowed', async function (req, res) {
const fetchResponse = await fetch(`http://localhost:${port2}/external-allowed`);
const data = await fetchResponse.json();

res.send(data);
});

app.get('/test-outgoing-fetch-external-disallowed', async function (req, res) {
const fetchResponse = await fetch(`http://localhost:${port2}/external-disallowed`);
const data = await fetchResponse.json();

res.send(data);
});

app.get('/test-outgoing-http-external-allowed', async function (req, res) {
const data = await makeHttpRequest(`http://localhost:${port2}/external-allowed`);
res.send(data);
});

app.get('/test-outgoing-http-external-disallowed', async function (req, res) {
const data = await makeHttpRequest(`http://localhost:${port2}/external-disallowed`);
res.send(data);
});

app.listen({ port: port });

// A second app so we can test header propagation between external URLs
const app2 = fastify();
app2.get('/external-allowed', function (req, res) {
const headers = req.headers;

res.send({ headers, route: '/external-allowed' });
});

app2.get('/external-disallowed', function (req, res) {
const headers = req.headers;

res.send({ headers, route: '/external-disallowed' });
});

app2.listen({ port: port2 });

function makeHttpRequest(url) {
return new Promise(resolve => {
const data = [];
Expand All @@ -67,9 +110,16 @@ function makeHttpRequest(url) {
httpRes.on('data', chunk => {
data.push(chunk);
});
httpRes.on('error', error => {
resolve({ error: error.message, url });
});
httpRes.on('end', () => {
const json = JSON.parse(Buffer.concat(data).toString());
resolve(json);
try {
const json = JSON.parse(Buffer.concat(data).toString());
resolve(json);
} catch {
resolve({ data: Buffer.concat(data).toString(), url });
}
});
})
.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Sentry.init({
integrations: [],
tracesSampleRate: 1,
tunnel: 'http://localhost:3031/', // proxy server
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
});
Loading