File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 11import { mkdir , writeFile } from 'node:fs/promises'
22import { dirname } from 'node:path'
33
4- import { PluginContext } from './plugin-context.js '
4+ import type { Span } from '@opentelemetry/api '
55
6- export const setSkewProtection = async ( ctx : PluginContext ) => {
6+ import type { PluginContext } from './plugin-context.js'
7+
8+ export const setSkewProtection = async ( ctx : PluginContext , span : Span ) => {
79 if ( ! process . env . DEPLOY_ID || process . env . DEPLOY_ID === '0' ) {
10+ // We can't proceed without a valid DEPLOY_ID, this should only be the case for CLI deploys
11+ span . setAttribute ( 'skewProtection' , 'off-no-valid-deploy-id' )
812 return
913 }
1014
11- console . log ( '[Next Runtime] Setting up Next.js Skew Protection' )
15+ if ( ctx . featureFlags ?. [ 'next-runtime-skew-protection' ] ) {
16+ console . log ( 'Setting up Next.js Skew Protection' )
17+ span . setAttribute ( 'skewProtection' , 'ff-opt-in' )
18+ } else if (
19+ process . env . NETLIFY_NEXT_PLUGIN_SKEW_PROTECTION === 'true' ||
20+ process . env . NETLIFY_NEXT_PLUGIN_SKEW_PROTECTION === '1'
21+ ) {
22+ console . log (
23+ 'Setting up Next.js Skew Protection due to NETLIFY_NEXT_PLUGIN_SKEW_PROTECTION environment variable' ,
24+ )
25+ span . setAttribute ( 'skewProtection' , 'env-var-opt-in' )
26+ } else {
27+ span . setAttribute ( 'skewProtection' , 'off' )
28+ return
29+ }
1230
1331 process . env . NEXT_DEPLOYMENT_ID = process . env . DEPLOY_ID
1432
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
5050 return
5151 }
5252
53- await tracer . withActiveSpan ( 'onPreBuild' , async ( ) => {
53+ await tracer . withActiveSpan ( 'onPreBuild' , async ( span ) => {
5454 // Enable Next.js standalone mode at build time
5555 process . env . NEXT_PRIVATE_STANDALONE = 'true'
5656 const ctx = new PluginContext ( options )
@@ -63,7 +63,7 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
6363 } else {
6464 await restoreBuildCache ( ctx )
6565 }
66- await setSkewProtection ( ctx )
66+ await setSkewProtection ( ctx , span )
6767 } )
6868}
6969
You can’t perform that action at this time.
0 commit comments