Skip to content

Commit 1ba4e89

Browse files
committed
Instrument function builds properly.
1 parent bcf21c4 commit 1ba4e89

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/playwright.config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ const config: PlaywrightTestConfig = {
5959
{
6060
command: `PORT=${port} pnpm dev`,
6161
port: port,
62-
stdout: 'pipe',
63-
stderr: 'pipe',
6462
},
6563
],
6664
};

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/tests/behaviour-server.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
1010
const httpServerTransactionPromise = waitForTransaction('create-remix-app-express-vite-dev', transactionEvent => {
1111
return (
1212
transactionEvent.type === 'transaction' &&
13-
transactionEvent.contexts?.trace?.op === 'http.server' &&
13+
transactionEvent.contexts?.trace?.op === 'http' &&
1414
transactionEvent.tags?.['sentry_test'] === testTag
1515
);
1616
});
@@ -33,18 +33,21 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
3333

3434
const httpServerTraceId = httpServerTransaction.contexts?.trace?.trace_id;
3535
const httpServerSpanId = httpServerTransaction.contexts?.trace?.span_id;
36+
const loaderSpanId = httpServerTransaction.spans.find(
37+
span => span.data && span.data['code.function'] === 'loader',
38+
)?.span_id;
3639

3740
const pageLoadTraceId = pageloadTransaction.contexts?.trace?.trace_id;
3841
const pageLoadSpanId = pageloadTransaction.contexts?.trace?.span_id;
3942
const pageLoadParentSpanId = pageloadTransaction.contexts?.trace?.parent_span_id;
4043

41-
expect(httpServerTransaction.transaction).toBe('routes/_index');
44+
expect(httpServerTransaction.transaction).toBe('GET http://localhost:3030/');
4245
expect(pageloadTransaction.transaction).toBe('routes/_index');
4346

4447
expect(httpServerTraceId).toBeDefined();
4548
expect(httpServerSpanId).toBeDefined();
4649

4750
expect(pageLoadTraceId).toEqual(httpServerTraceId);
48-
expect(pageLoadParentSpanId).toEqual(httpServerSpanId);
51+
expect(pageLoadParentSpanId).toEqual(loaderSpanId);
4952
expect(pageLoadSpanId).not.toEqual(httpServerSpanId);
5053
});

packages/remix/src/utils/instrumentServer.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
fill,
1818
isNodeEnv,
1919
isPrimitive,
20-
isThenable,
2120
loadModule,
2221
logger,
2322
objectify,
@@ -416,25 +415,27 @@ function instrumentBuildCallback(build: ServerBuild): ServerBuild {
416415
*/
417416
export function instrumentBuild(
418417
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>),
419-
): ServerBuild | Promise<ServerBuild> {
418+
): ServerBuild | (() => ServerBuild | Promise<ServerBuild>) {
420419
if (typeof build === 'function') {
421-
const resolvedBuild = build();
420+
return function () {
421+
const resolvedBuild = build();
422422

423-
if (isThenable(resolvedBuild)) {
424-
return resolvedBuild.then(build => {
425-
FUTURE_FLAGS = getFutureFlagsServer(build);
423+
if (resolvedBuild instanceof Promise) {
424+
return resolvedBuild.then(build => {
425+
FUTURE_FLAGS = getFutureFlagsServer(build);
426426

427-
return instrumentBuildCallback(build);
428-
});
429-
} else {
430-
FUTURE_FLAGS = getFutureFlagsServer(resolvedBuild);
427+
return instrumentBuildCallback(build);
428+
});
429+
} else {
430+
FUTURE_FLAGS = getFutureFlagsServer(resolvedBuild);
431431

432-
return instrumentBuildCallback(resolvedBuild);
433-
}
432+
return instrumentBuildCallback(resolvedBuild);
433+
}
434+
};
434435
} else {
435-
FUTURE_FLAGS = getFutureFlagsServer(build as ServerBuild);
436+
FUTURE_FLAGS = getFutureFlagsServer(build);
436437

437-
return instrumentBuildCallback(build as ServerBuild);
438+
return instrumentBuildCallback(build);
438439
}
439440
}
440441

0 commit comments

Comments
 (0)