Skip to content

Commit 36e7f6e

Browse files
committed
feat: add opt-in mechanisms via FF and env var
1 parent 2da0b5c commit 36e7f6e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/build/skew-protection.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import { mkdir, writeFile } from 'node:fs/promises'
22
import { 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

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)