123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { inboundFiltersIntegration, functionToStringIntegration, linkedErrorsIntegration, requestDataIntegration, getIntegrationsToSetup, initAndBind } from '@sentry/core';
- import { createStackParser, nodeStackLineParser, stackParserFromStackParserOptions, GLOBAL_OBJ } from '@sentry/utils';
- import { setAsyncLocalStorageAsyncContextStrategy } from './async.js';
- import { VercelEdgeClient } from './client.js';
- import { winterCGFetchIntegration } from './integrations/wintercg-fetch.js';
- import { makeEdgeTransport } from './transports/index.js';
- import { getVercelEnv } from './utils/vercel.js';
- const nodeStackParser = createStackParser(nodeStackLineParser());
- /** @deprecated Use `getDefaultIntegrations(options)` instead. */
- const defaultIntegrations = [
- inboundFiltersIntegration(),
- functionToStringIntegration(),
- linkedErrorsIntegration(),
- winterCGFetchIntegration(),
- ];
- /** Get the default integrations for the browser SDK. */
- function getDefaultIntegrations(options) {
- return [
- // eslint-disable-next-line deprecation/deprecation
- ...defaultIntegrations,
- ...(options.sendDefaultPii ? [requestDataIntegration()] : []),
- ];
- }
- /** Inits the Sentry NextJS SDK on the Edge Runtime. */
- function init(options = {}) {
- setAsyncLocalStorageAsyncContextStrategy();
- if (options.defaultIntegrations === undefined) {
- options.defaultIntegrations = getDefaultIntegrations(options);
- }
- if (options.dsn === undefined && process.env.SENTRY_DSN) {
- options.dsn = process.env.SENTRY_DSN;
- }
- if (options.tracesSampleRate === undefined && process.env.SENTRY_TRACES_SAMPLE_RATE) {
- const tracesSampleRate = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE);
- if (isFinite(tracesSampleRate)) {
- options.tracesSampleRate = tracesSampleRate;
- }
- }
- if (options.release === undefined) {
- const detectedRelease = getSentryRelease();
- if (detectedRelease !== undefined) {
- options.release = detectedRelease;
- } else {
- // If release is not provided, then we should disable autoSessionTracking
- options.autoSessionTracking = false;
- }
- }
- options.environment =
- options.environment || process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV;
- if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
- options.autoSessionTracking = true;
- }
- if (options.instrumenter === undefined) {
- options.instrumenter = 'sentry';
- }
- const clientOptions = {
- ...options,
- stackParser: stackParserFromStackParserOptions(options.stackParser || nodeStackParser),
- integrations: getIntegrationsToSetup(options),
- transport: options.transport || makeEdgeTransport,
- };
- initAndBind(VercelEdgeClient, clientOptions);
- }
- /**
- * Returns a release dynamically from environment variables.
- */
- function getSentryRelease(fallback) {
- // Always read first as Sentry takes this as precedence
- if (process.env.SENTRY_RELEASE) {
- return process.env.SENTRY_RELEASE;
- }
- // This supports the variable that sentry-webpack-plugin injects
- if (GLOBAL_OBJ.SENTRY_RELEASE && GLOBAL_OBJ.SENTRY_RELEASE.id) {
- return GLOBAL_OBJ.SENTRY_RELEASE.id;
- }
- return (
- // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
- process.env.GITHUB_SHA ||
- // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
- process.env.VERCEL_GIT_COMMIT_SHA ||
- process.env.VERCEL_GITHUB_COMMIT_SHA ||
- process.env.VERCEL_GITLAB_COMMIT_SHA ||
- process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
- // Zeit (now known as Vercel)
- process.env.ZEIT_GITHUB_COMMIT_SHA ||
- process.env.ZEIT_GITLAB_COMMIT_SHA ||
- process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
- fallback
- );
- }
- export { defaultIntegrations, getDefaultIntegrations, getSentryRelease, init };
- //# sourceMappingURL=sdk.js.map
|