Skip to content

fix(node): Don't leak __span property into breadcrumbs #14798

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 3 commits into from
Dec 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('Should trace outgoing fetch requests inside middleware and create breadcru
expect.arrayContaining([
{
category: 'fetch',
data: { __span: expect.any(String), method: 'GET', status_code: 200, url: 'http://localhost:3030/' },
data: { method: 'GET', status_code: 200, url: 'http://localhost:3030/' },
timestamp: expect.any(Number),
type: 'http',
},
Expand Down
21 changes: 13 additions & 8 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,12 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
return;
}

const breadcrumbData: FetchBreadcrumbData = {
method: handlerData.fetchData.method,
url: handlerData.fetchData.url,
};

if (handlerData.error) {
const data: FetchBreadcrumbData = handlerData.fetchData;
const hint: FetchBreadcrumbHint = {
data: handlerData.error,
input: handlerData.args,
Expand All @@ -298,30 +302,31 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
level: 'error',
type: 'http',
},
hint,
);
} else {
const response = handlerData.response as Response | undefined;
const data: FetchBreadcrumbData = {
...handlerData.fetchData,
status_code: response && response.status,
};

breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;
breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;
breadcrumbData.status_code = response && response.status;

const hint: FetchBreadcrumbHint = {
input: handlerData.args,
response,
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
const level = getBreadcrumbLogLevelFromHttpStatusCode(breadcrumbData.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
type: 'http',
level,
},
Expand Down
24 changes: 15 additions & 9 deletions packages/cloudflare/src/integrations/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
return;
}

const breadcrumbData: FetchBreadcrumbData = {
method: handlerData.fetchData.method,
url: handlerData.fetchData.url,
};

if (handlerData.error) {
const data = handlerData.fetchData;
const hint: FetchBreadcrumbHint = {
data: handlerData.error,
input: handlerData.args,
Expand All @@ -136,29 +140,31 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
level: 'error',
type: 'http',
},
hint,
);
} else {
const data: FetchBreadcrumbData = {
...handlerData.fetchData,
status_code: handlerData.response && handlerData.response.status,
};
const response = handlerData.response as Response | undefined;

breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;
breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;
breadcrumbData.status_code = response && response.status;

const hint: FetchBreadcrumbHint = {
input: handlerData.args,
response: handlerData.response,
response,
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
const level = getBreadcrumbLogLevelFromHttpStatusCode(breadcrumbData.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
type: 'http',
level,
},
Expand Down
1 change: 0 additions & 1 deletion packages/cloudflare/test/integrations/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ describe('WinterCGFetch instrumentation', () => {
method: 'POST',
status_code: 201,
url: 'http://my-website.com/',
__span: expect.any(String),
},
type: 'http',
},
Expand Down
21 changes: 13 additions & 8 deletions packages/deno/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
return;
}

const breadcrumbData: FetchBreadcrumbData = {
method: handlerData.fetchData.method,
url: handlerData.fetchData.url,
};

if (handlerData.error) {
const data: FetchBreadcrumbData = handlerData.fetchData;
const hint: FetchBreadcrumbHint = {
data: handlerData.error,
input: handlerData.args,
Expand All @@ -163,30 +167,31 @@ function _getFetchBreadcrumbHandler(client: Client): (handlerData: HandlerDataFe
addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
level: 'error',
type: 'http',
},
hint,
);
} else {
const response = handlerData.response as Response | undefined;
const data: FetchBreadcrumbData = {
...handlerData.fetchData,
status_code: response && response.status,
};

breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;
breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;
breadcrumbData.status_code = response && response.status;

const hint: FetchBreadcrumbHint = {
input: handlerData.args,
response,
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
const level = getBreadcrumbLogLevelFromHttpStatusCode(breadcrumbData.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
type: 'http',
level,
},
Expand Down
24 changes: 15 additions & 9 deletions packages/vercel-edge/src/integrations/wintercg-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
return;
}

const breadcrumbData: FetchBreadcrumbData = {
method: handlerData.fetchData.method,
url: handlerData.fetchData.url,
};

if (handlerData.error) {
const data = handlerData.fetchData;
const hint: FetchBreadcrumbHint = {
data: handlerData.error,
input: handlerData.args,
Expand All @@ -142,29 +146,31 @@ function createBreadcrumb(handlerData: HandlerDataFetch): void {
addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
level: 'error',
type: 'http',
},
hint,
);
} else {
const data: FetchBreadcrumbData = {
...handlerData.fetchData,
status_code: handlerData.response && handlerData.response.status,
};
const response = handlerData.response as Response | undefined;

breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;
breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;
breadcrumbData.status_code = response && response.status;

const hint: FetchBreadcrumbHint = {
input: handlerData.args,
response: handlerData.response,
response,
startTimestamp,
endTimestamp,
};
const level = getBreadcrumbLogLevelFromHttpStatusCode(data.status_code);
const level = getBreadcrumbLogLevelFromHttpStatusCode(breadcrumbData.status_code);

addBreadcrumb(
{
category: 'fetch',
data,
data: breadcrumbData,
type: 'http',
level,
},
Expand Down
1 change: 0 additions & 1 deletion packages/vercel-edge/test/wintercg-fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ describe('WinterCGFetch instrumentation', () => {
method: 'POST',
status_code: 201,
url: 'http://my-website.com/',
__span: expect.any(String),
},
type: 'http',
},
Expand Down
Loading