Skip to content

Commit

Permalink
fix(node): Don't leak __span property into breadcrumbs (#14798)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Dec 19, 2024
1 parent 6038628 commit 9308877
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 37 deletions.
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

0 comments on commit 9308877

Please sign in to comment.