Skip to content

Commit 5042dfe

Browse files
committed
fix(mastra): Fold in review nits on the constructor hook and test flush
Use the shared channel helper, document why createRequire needs a dummy filename, and drop redundant Sentry.flush from scenarios.
1 parent 1c544d9 commit 5042dfe

6 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎dev-packages/node-integration-tests/suites/tracing/mastra/scenario-auto.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ async function run() {
6565
});
6666

6767
await mastra.observability.shutdown();
68-
await Sentry.flush(2000);
6968
provider.close();
7069
}
7170

‎dev-packages/node-integration-tests/suites/tracing/mastra/scenario-community-exporter.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ async function run() {
7979
});
8080

8181
await mastra.observability.shutdown();
82-
await Sentry.flush(2000);
8382
provider.close();
8483
}
8584

‎dev-packages/node-integration-tests/suites/tracing/mastra/scenario-tools.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ async function run() {
9696
});
9797

9898
await mastra.observability.shutdown();
99-
await Sentry.flush(2000);
10099
provider.close();
101100
}
102101

‎dev-packages/node-integration-tests/suites/tracing/mastra/scenario-workflow.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ async function run() {
4141
});
4242

4343
await mastra.observability.shutdown();
44-
await Sentry.flush(2000);
4544
}
4645

4746
run();

‎dev-packages/node-integration-tests/suites/tracing/mastra/scenario.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ async function run() {
7575
});
7676

7777
await mastra.observability.shutdown();
78-
await Sentry.flush(2000);
7978
provider.close();
8079
}
8180

‎packages/server-utils/src/integrations/mastra.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DEBUG_BUILD } from '../debug-build';
1515
import { CHANNELS } from '../orchestrion/channels';
1616
import { mastraModuleNames } from '../orchestrion/config/mastra';
1717
import { invokeOrchestrionInstrumentation } from '../orchestrion/instrumentation';
18+
import { safeChannelCallback } from '../tracing-channel';
1819

1920
export interface MastraOptions extends MastraExporterOptions {
2021
/**
@@ -59,12 +60,10 @@ const _mastraIntegration = ((options: MastraOptions = {}) => {
5960

6061
function instrumentMastra(options: MastraOptions): void {
6162
diagnosticsChannel.tracingChannel<ConstructorChannelContext>(CHANNELS.MASTRA_CONSTRUCTOR).end.subscribe(message => {
62-
try {
63+
safeChannelCallback(() => {
6364
const { self } = message as ConstructorChannelContext;
6465
attachExporter(self, options);
65-
} catch (error) {
66-
DEBUG_BUILD && debug.error('[instrumentation:mastra] failed to register the Sentry exporter', error);
67-
}
66+
});
6867
});
6968
}
7069

@@ -159,8 +158,15 @@ function warnAboutCommunityExporter(): void {
159158
});
160159
}
161160

161+
// `createRequire` treats its argument as a filename and resolves from `dirname(that)`.
162+
// Passing cwd itself would look in cwd's parent, so this dummy file (never loaded) keeps
163+
// resolution rooted at the app directory.
164+
function cwdRequireParent(): string {
165+
return join(process.cwd(), 'noop.js');
166+
}
167+
162168
function appRequire(): ReturnType<typeof createRequire> {
163-
return createRequire(join(process.cwd(), 'noop.js'));
169+
return createRequire(cwdRequireParent());
164170
}
165171

166172
/**
@@ -205,7 +211,7 @@ function loadMastraObservability(): Record<string, unknown> {
205211
} catch {
206212
// cwd is not the app, or `@mastra/core` is ESM-only and not in the CJS resolver.
207213
}
208-
parents.add(join(process.cwd(), 'noop.js'));
214+
parents.add(cwdRequireParent());
209215

210216
for (const parent of parents) {
211217
const observability = tryRequireObservability(parent);

0 commit comments

Comments
 (0)