@sentry/nextjs
Version:
Official Sentry SDK for Next.js
54 lines (51 loc) • 2.23 kB
JavaScript
import { debug, flush, getAsyncContextStrategy, getMainCarrier, GLOBAL_OBJ, getClient } from '@sentry/core';
import { vercelWaitUntil } from '@sentry/core/server';
import { DEBUG_BUILD } from '../debug-build.js';
async function flushSafelyWithTimeout() {
try {
DEBUG_BUILD && debug.log("Flushing events...");
await flush(2e3);
DEBUG_BUILD && debug.log("Done flushing events");
} catch (e) {
DEBUG_BUILD && debug.log("Error while flushing events:\n", e);
}
}
function waitUntil(task) {
if (isCloudflareWaitUntilAvailable()) {
cloudflareWaitUntil(task);
return;
}
vercelWaitUntil(task);
}
function _getOpenNextCloudflareContext() {
const openNextCloudflareContextSymbol = /* @__PURE__ */ Symbol.for("__cloudflare-context__");
return GLOBAL_OBJ[openNextCloudflareContextSymbol]?.ctx;
}
function cloudflareWaitUntil(task) {
_getOpenNextCloudflareContext()?.waitUntil(task);
}
function isCloudflareWaitUntilAvailable() {
return typeof _getOpenNextCloudflareContext()?.waitUntil === "function";
}
function markAsyncContextOwnedByNextjsCloudflare() {
getAsyncContextStrategy(getMainCarrier())._sentryNextjsCloudflare = true;
}
function isAsyncContextOwnedByNextjsCloudflare() {
const strategy = getAsyncContextStrategy(getMainCarrier());
return !!strategy._sentryNextjsCloudflare;
}
function isAsyncContextOwnedByCloudflare() {
const strategy = getAsyncContextStrategy(getMainCarrier());
const asyncLocalStorage = strategy.getTracingChannelBinding?.()?.asyncLocalStorage;
return isAsyncContextOwnedByNextjsCloudflare() || !strategy.withActiveSpan && asyncLocalStorage?.getStore() !== void 0 && GLOBAL_OBJ.navigator?.userAgent === "Cloudflare-Workers";
}
function setCloudflareWorkerRelease(release) {
var _a;
(_a = GLOBAL_OBJ)._sentryRelease ?? (_a._sentryRelease = release);
const options = getClient()?.getOptions();
if (options && !options.release) {
options.release = release;
}
}
export { cloudflareWaitUntil, flushSafelyWithTimeout, isAsyncContextOwnedByCloudflare, isAsyncContextOwnedByNextjsCloudflare, isCloudflareWaitUntilAvailable, markAsyncContextOwnedByNextjsCloudflare, setCloudflareWorkerRelease, waitUntil };
//# sourceMappingURL=responseEnd.js.map