Skip to content

Commit

Permalink
Instrument function builds properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed May 17, 2024
1 parent 3fd0f2b commit b29123d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ const config: PlaywrightTestConfig = {
{
command: `PORT=${port} pnpm dev`,
port: port,
stdout: 'pipe',
stderr: 'pipe',
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page
const httpServerTransactionPromise = waitForTransaction('create-remix-app-express-vite-dev', transactionEvent => {
return (
transactionEvent.type === 'transaction' &&
transactionEvent.contexts?.trace?.op === 'http.server' &&
transactionEvent.contexts?.trace?.op === 'http' &&
transactionEvent.tags?.['sentry_test'] === testTag
);
});
Expand All @@ -33,18 +33,21 @@ test('Sends two linked transactions (server & client) to Sentry', async ({ page

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

const pageLoadTraceId = pageloadTransaction.contexts?.trace?.trace_id;
const pageLoadSpanId = pageloadTransaction.contexts?.trace?.span_id;
const pageLoadParentSpanId = pageloadTransaction.contexts?.trace?.parent_span_id;

expect(httpServerTransaction.transaction).toBe('routes/_index');
expect(httpServerTransaction.transaction).toBe('GET http://localhost:3030/');
expect(pageloadTransaction.transaction).toBe('routes/_index');

expect(httpServerTraceId).toBeDefined();
expect(httpServerSpanId).toBeDefined();

expect(pageLoadTraceId).toEqual(httpServerTraceId);
expect(pageLoadParentSpanId).toEqual(httpServerSpanId);
expect(pageLoadParentSpanId).toEqual(loaderSpanId);
expect(pageLoadSpanId).not.toEqual(httpServerSpanId);
});
29 changes: 15 additions & 14 deletions packages/remix/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
fill,
isNodeEnv,
isPrimitive,
isThenable,
loadModule,
logger,
objectify,
Expand Down Expand Up @@ -416,25 +415,27 @@ function instrumentBuildCallback(build: ServerBuild): ServerBuild {
*/
export function instrumentBuild(
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>),
): ServerBuild | Promise<ServerBuild> {
): ServerBuild | (() => ServerBuild | Promise<ServerBuild>) {
if (typeof build === 'function') {
const resolvedBuild = build();
return function () {
const resolvedBuild = build();

if (isThenable(resolvedBuild)) {
return resolvedBuild.then(build => {
FUTURE_FLAGS = getFutureFlagsServer(build);
if (resolvedBuild instanceof Promise) {
return resolvedBuild.then(build => {
FUTURE_FLAGS = getFutureFlagsServer(build);

return instrumentBuildCallback(build);
});
} else {
FUTURE_FLAGS = getFutureFlagsServer(resolvedBuild);
return instrumentBuildCallback(build);
});
} else {
FUTURE_FLAGS = getFutureFlagsServer(resolvedBuild);

return instrumentBuildCallback(resolvedBuild);
}
return instrumentBuildCallback(resolvedBuild);
}
};
} else {
FUTURE_FLAGS = getFutureFlagsServer(build as ServerBuild);
FUTURE_FLAGS = getFutureFlagsServer(build);

return instrumentBuildCallback(build as ServerBuild);
return instrumentBuildCallback(build);
}
}

Expand Down

0 comments on commit b29123d

Please sign in to comment.