Skip to content

Commit 8932a0c

Browse files
committed
fix astro stuff
1 parent 1387cf7 commit 8932a0c

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clean": "rimraf tmp node_modules && yarn clean:test-applications && yarn clean:pnpm",
1717
"ci:build-matrix": "ts-node ./lib/getTestMatrix.ts",
1818
"ci:build-matrix-optional": "ts-node ./lib/getTestMatrix.ts --optional=true",
19-
"clean:test-applications": "rimraf --glob test-applications/**/{node_modules,dist,build,.next,.nuxt,.sveltekit,.react-router,pnpm-lock.yaml,.last-run.json,test-results}",
19+
"clean:test-applications": "rimraf --glob test-applications/**/{node_modules,dist,build,.next,.nuxt,.sveltekit,.react-router,.astro,pnpm-lock.yaml,.last-run.json,test-results}",
2020
"clean:pnpm": "pnpm store prune"
2121
},
2222
"devDependencies": {

dev-packages/e2e-tests/test-applications/astro-5/tests/tracing.dynamic.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ test.describe('tracing in dynamically rendered (ssr) routes', () => {
6262
});
6363

6464
expect(serverPageRequestTxn).toMatchObject({
65-
breadcrumbs: expect.any(Array),
6665
contexts: {
6766
app: expect.any(Object),
6867
cloud_resource: expect.any(Object),

packages/node/src/integrations/http/SentryHttpInstrumentation.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,25 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
114114
this._onOutgoingRequestFinish(request, response);
115115
});
116116

117+
// When an error happens, we still want to have a breadcrumb
118+
// In this case, `http.client.response.finish` is not triggered
119+
subscribe('http.client.request.error', data => {
120+
const request = (data as { request: http.ClientRequest }).request;
121+
// there is no response object here, we only have access to request & error :(
122+
123+
this._onOutgoingRequestFinish(request, undefined);
124+
});
125+
117126
return [];
118127
}
119128

120129
/**
121130
* This is triggered when an outgoing request finishes.
122131
* It has access to the final request and response objects.
123132
*/
124-
private _onOutgoingRequestFinish(request: http.ClientRequest, response: http.IncomingMessage): void {
133+
private _onOutgoingRequestFinish(request: http.ClientRequest, response?: http.IncomingMessage): void {
134+
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling outgoing request finish');
135+
125136
const _breadcrumbs = this.getConfig().breadcrumbs;
126137
const breadCrumbsEnabled = typeof _breadcrumbs === 'undefined' ? true : _breadcrumbs;
127138
const options = getRequestOptions(request);
@@ -148,6 +159,8 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
148159
return;
149160
}
150161

162+
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching server.emit');
163+
151164
// eslint-disable-next-line @typescript-eslint/no-this-alias
152165
const instrumentation = this;
153166
const { ignoreIncomingRequestBody } = instrumentation.getConfig();
@@ -159,7 +172,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
159172
return target.apply(thisArg, args);
160173
}
161174

162-
DEBUG_BUILD && logger.log('http instrumentation for incoming request');
175+
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'isolating incoming request');
163176

164177
const isolationScope = getIsolationScope().clone();
165178
const request = args[1] as http.IncomingMessage;
@@ -222,10 +235,10 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
222235
}
223236

224237
/** Add a breadcrumb for outgoing requests. */
225-
function addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage): void {
238+
function addRequestBreadcrumb(request: http.ClientRequest, response: http.IncomingMessage | undefined): void {
226239
const data = getBreadcrumbData(request);
227240

228-
const statusCode = response.statusCode;
241+
const statusCode = response?.statusCode;
229242
const level = getBreadcrumbLogLevelFromHttpStatusCode(statusCode);
230243

231244
addBreadcrumb(
@@ -281,6 +294,8 @@ function patchRequestToCaptureBody(req: http.IncomingMessage, isolationScope: Sc
281294
let bodyByteLength = 0;
282295
const chunks: Buffer[] = [];
283296

297+
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Patching request.on');
298+
284299
/**
285300
* We need to keep track of the original callbacks, in order to be able to remove listeners again.
286301
* Since `off` depends on having the exact same function reference passed in, we need to be able to map
@@ -294,11 +309,8 @@ function patchRequestToCaptureBody(req: http.IncomingMessage, isolationScope: Sc
294309
apply: (target, thisArg, args: Parameters<typeof req.on>) => {
295310
const [event, listener, ...restArgs] = args;
296311

297-
if (DEBUG_BUILD) {
298-
logger.log(INSTRUMENTATION_NAME, 'Patching request.on', event);
299-
}
300-
301312
if (event === 'data') {
313+
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling request.on', event);
302314
const callback = new Proxy(listener, {
303315
apply: (target, thisArg, args: Parameters<typeof listener>) => {
304316
try {

0 commit comments

Comments
 (0)