Skip to content

Commit 31a52ec

Browse files
author
Lukas Holzer
authored
feat: ship instrumentation file in functions bundle (netlify/zip-it-and-ship-it#1726)
* feat: ship instrumentation file in functions bundle * chore: update serverless functions api * chore: fix tests * chore: latest pr feedback * chore: add test for bundler none * chore: update naming * chore: fix windows
1 parent 48d9f23 commit 31a52ec

File tree

8 files changed

+365
-19
lines changed

8 files changed

+365
-19
lines changed

packages/zip-it-and-ship-it/package-lock.json

Lines changed: 219 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/zip-it-and-ship-it/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@babel/parser": "^7.22.5",
5858
"@babel/types": "7.23.6",
5959
"@netlify/binary-info": "^1.0.0",
60-
"@netlify/serverless-functions-api": "^1.16.2",
60+
"@netlify/serverless-functions-api": "^1.17.0",
6161
"@vercel/nft": "^0.23.0",
6262
"archiver": "^6.0.0",
6363
"common-path-prefix": "^3.0.0",

packages/zip-it-and-ship-it/src/feature_flags.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const defaultFlags = {
2929

3030
// fixes symlinks in included files
3131
zisi_fix_symlinks: false,
32+
33+
// Adds the `___netlify-telemetry.mjs` file to the function bundle.
34+
zisi_add_instrumentation_loader: true,
3235
} as const
3336

3437
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>

packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { readFileSync } from 'fs'
2+
import { createRequire } from 'module'
13
import { basename, extname, resolve } from 'path'
24

35
import type { FeatureFlags } from '../../../feature_flags.js'
@@ -15,6 +17,9 @@ import { normalizeFilePath } from './normalize_path.js'
1517

1618
export const ENTRY_FILE_NAME = '___netlify-entry-point'
1719
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs'
20+
export const TELEMETRY_FILE_NAME = '___netlify-telemetry.mjs'
21+
22+
const require = createRequire(import.meta.url)
1823

1924
export interface EntryFile {
2025
contents: string
@@ -153,6 +158,17 @@ const getEntryFileName = ({
153158
return `${basename(filename, extname(filename))}${extension}`
154159
}
155160

161+
export const getTelemetryFile = (): EntryFile => {
162+
// TODO: switch with import.meta.resolve once we drop support for Node 16.x
163+
const filePath = require.resolve('@netlify/serverless-functions-api/instrumentation.js')
164+
const contents = readFileSync(filePath, 'utf8')
165+
166+
return {
167+
contents,
168+
filename: TELEMETRY_FILE_NAME,
169+
}
170+
}
171+
156172
export const getEntryFile = ({
157173
commonPrefix,
158174
featureFlags,

0 commit comments

Comments
 (0)