Skip to content

Commit 65b1a4a

Browse files
authored
Merge branch 'v9' into cg-v9backport-rr-flush-requesthandler
2 parents 68b30af + 54576cf commit 65b1a4a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

dev-packages/e2e-tests/test-applications/nextjs-14/tests/generation-functions.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ test('Should send a transaction and an error event for a faulty generateMetadata
4242
});
4343

4444
const errorEventPromise = waitForError('nextjs-14', errorEvent => {
45-
return errorEvent?.exception?.values?.[0]?.value === 'generateMetadata Error';
45+
return (
46+
errorEvent?.exception?.values?.[0]?.value === 'generateMetadata Error' &&
47+
errorEvent.transaction === 'Page.generateMetadata (/generation-functions)'
48+
);
4649
});
4750

4851
await page.goto(`/generation-functions?metadataTitle=${testTitle}&shouldThrowInGenerateMetadata=1`);
4952

5053
const errorEvent = await errorEventPromise;
5154
const transactionEvent = await transactionPromise;
5255

53-
expect(errorEvent.transaction).toBe('Page.generateMetadata (/generation-functions)');
54-
5556
// Assert that isolation scope works properly
5657
expect(errorEvent.tags?.['my-isolated-tag']).toBe(true);
5758
expect(errorEvent.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import {
1212
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
1313
setCapturedScopesOnSpan,
1414
setHttpStatus,
15+
vercelWaitUntil,
1516
winterCGHeadersToDict,
1617
withIsolationScope,
1718
withScope,
1819
} from '@sentry/core';
1920
import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils';
2021
import type { RouteHandlerContext } from './types';
22+
import { flushSafelyWithTimeout } from './utils/responseEnd';
2123
import { commonObjectToIsolationScope } from './utils/tracingUtils';
2224

2325
/**
@@ -92,6 +94,9 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
9294
});
9395
}
9496
},
97+
() => {
98+
vercelWaitUntil(flushSafelyWithTimeout());
99+
},
95100
);
96101

97102
try {

packages/node/src/integrations/tracing/openai/instrumentation.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@ export class SentryOpenAiInstrumentation extends InstrumentationBase<Instrumenta
8383
}
8484
}
8585

86-
const isESM = Object.prototype.toString.call(exports) === '[object Module]';
87-
if (isESM) {
86+
// Constructor replacement - handle read-only properties
87+
// The OpenAI property might have only a getter, so use defineProperty
88+
try {
8889
exports.OpenAI = WrappedOpenAI;
89-
return exports;
90+
} catch (error) {
91+
// If direct assignment fails, override the property descriptor
92+
Object.defineProperty(exports, 'OpenAI', {
93+
value: WrappedOpenAI,
94+
writable: true,
95+
configurable: true,
96+
enumerable: true,
97+
});
9098
}
91-
92-
return { ...exports, OpenAI: WrappedOpenAI };
99+
return exports;
93100
}
94101
}

0 commit comments

Comments
 (0)