1
- import type { ServerRuntimeClientOptions } from '@sentry/core' ;
2
- import {
3
- getIntegrationsToSetup ,
4
- initAndBind ,
5
- Integrations as CoreIntegrations ,
6
- SDK_VERSION ,
7
- ServerRuntimeClient ,
8
- } from '@sentry/core' ;
9
- import type { Options } from '@sentry/types' ;
10
- import { createStackParser , GLOBAL_OBJ , nodeStackLineParser , stackParserFromStackParserOptions } from '@sentry/utils' ;
1
+ import { SDK_VERSION } from '@sentry/core' ;
2
+ import type { VercelEdgeOptions } from '@sentry/vercel-edge' ;
3
+ import { init as vercelEdgeInit } from '@sentry/vercel-edge' ;
11
4
12
- import { getVercelEnv } from '../common/getVercelEnv' ;
13
- import { setAsyncLocalStorageAsyncContextStrategy } from './asyncLocalStorageAsyncContextStrategy' ;
14
- import { makeEdgeTransport } from './transport' ;
15
-
16
- const nodeStackParser = createStackParser ( nodeStackLineParser ( ) ) ;
17
-
18
- export const defaultIntegrations = [ new CoreIntegrations . InboundFilters ( ) , new CoreIntegrations . FunctionToString ( ) ] ;
19
-
20
- export type EdgeOptions = Options ;
5
+ export type EdgeOptions = VercelEdgeOptions ;
21
6
22
7
/** Inits the Sentry NextJS SDK on the Edge Runtime. */
23
- export function init ( options : EdgeOptions = { } ) : void {
24
- setAsyncLocalStorageAsyncContextStrategy ( ) ;
25
-
26
- if ( options . defaultIntegrations === undefined ) {
27
- options . defaultIntegrations = defaultIntegrations ;
28
- }
29
-
30
- if ( options . dsn === undefined && process . env . SENTRY_DSN ) {
31
- options . dsn = process . env . SENTRY_DSN ;
32
- }
33
-
34
- if ( options . tracesSampleRate === undefined && process . env . SENTRY_TRACES_SAMPLE_RATE ) {
35
- const tracesSampleRate = parseFloat ( process . env . SENTRY_TRACES_SAMPLE_RATE ) ;
36
- if ( isFinite ( tracesSampleRate ) ) {
37
- options . tracesSampleRate = tracesSampleRate ;
38
- }
39
- }
40
-
41
- if ( options . release === undefined ) {
42
- const detectedRelease = getSentryRelease ( ) ;
43
- if ( detectedRelease !== undefined ) {
44
- options . release = detectedRelease ;
45
- } else {
46
- // If release is not provided, then we should disable autoSessionTracking
47
- options . autoSessionTracking = false ;
48
- }
49
- }
50
-
51
- options . environment =
52
- options . environment || process . env . SENTRY_ENVIRONMENT || getVercelEnv ( false ) || process . env . NODE_ENV ;
53
-
54
- if ( options . autoSessionTracking === undefined && options . dsn !== undefined ) {
55
- options . autoSessionTracking = true ;
56
- }
57
-
58
- if ( options . instrumenter === undefined ) {
59
- options . instrumenter = 'sentry' ;
60
- }
61
-
62
- const clientOptions : ServerRuntimeClientOptions = {
63
- ...options ,
64
- stackParser : stackParserFromStackParserOptions ( options . stackParser || nodeStackParser ) ,
65
- integrations : getIntegrationsToSetup ( options ) ,
66
- transport : options . transport || makeEdgeTransport ,
67
- } ;
68
-
69
- clientOptions . _metadata = clientOptions . _metadata || { } ;
70
- clientOptions . _metadata . sdk = clientOptions . _metadata . sdk || {
8
+ export function init ( options : VercelEdgeOptions = { } ) : void {
9
+ options . _metadata = options . _metadata || { } ;
10
+ options . _metadata . sdk = options . _metadata . sdk || {
71
11
name : 'sentry.javascript.nextjs' ,
72
12
packages : [
73
13
{
@@ -78,45 +18,7 @@ export function init(options: EdgeOptions = {}): void {
78
18
version : SDK_VERSION ,
79
19
} ;
80
20
81
- clientOptions . platform = 'edge' ;
82
- clientOptions . runtime = { name : 'edge' } ;
83
- clientOptions . serverName = process . env . SENTRY_NAME ;
84
-
85
- initAndBind ( ServerRuntimeClient , clientOptions ) ;
86
-
87
- // TODO?: Sessiontracking
88
- }
89
-
90
- /**
91
- * Returns a release dynamically from environment variables.
92
- */
93
- export function getSentryRelease ( fallback ?: string ) : string | undefined {
94
- // Always read first as Sentry takes this as precedence
95
- if ( process . env . SENTRY_RELEASE ) {
96
- return process . env . SENTRY_RELEASE ;
97
- }
98
-
99
- // This supports the variable that sentry-webpack-plugin injects
100
- if ( GLOBAL_OBJ . SENTRY_RELEASE && GLOBAL_OBJ . SENTRY_RELEASE . id ) {
101
- return GLOBAL_OBJ . SENTRY_RELEASE . id ;
102
- }
103
-
104
- return (
105
- // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
106
- process . env . GITHUB_SHA ||
107
- // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
108
- process . env . COMMIT_REF ||
109
- // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
110
- process . env . VERCEL_GIT_COMMIT_SHA ||
111
- process . env . VERCEL_GITHUB_COMMIT_SHA ||
112
- process . env . VERCEL_GITLAB_COMMIT_SHA ||
113
- process . env . VERCEL_BITBUCKET_COMMIT_SHA ||
114
- // Zeit (now known as Vercel)
115
- process . env . ZEIT_GITHUB_COMMIT_SHA ||
116
- process . env . ZEIT_GITLAB_COMMIT_SHA ||
117
- process . env . ZEIT_BITBUCKET_COMMIT_SHA ||
118
- fallback
119
- ) ;
21
+ vercelEdgeInit ( options ) ;
120
22
}
121
23
122
24
/**
@@ -126,7 +28,8 @@ export function withSentryConfig<T>(exportedUserNextConfig: T): T {
126
28
return exportedUserNextConfig ;
127
29
}
128
30
129
- export * from '@sentry/core' ;
31
+ export * from '@sentry/vercel-edge' ;
32
+ export { Span , Transaction } from '@sentry/core' ;
130
33
131
34
// eslint-disable-next-line import/export
132
35
export * from '../common' ;
0 commit comments