Skip to content

Commit b0e66dd

Browse files
authored
feat!: no longer inline telemetry file into zip as telemetry is now handled directly within the updated serverless-functions-api package (#6287)
1 parent 6c23028 commit b0e66dd

File tree

8 files changed

+21774
-226
lines changed

8 files changed

+21774
-226
lines changed

package-lock.json

Lines changed: 21772 additions & 5 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
@@ -44,7 +44,7 @@
4444
"@babel/parser": "^7.22.5",
4545
"@babel/types": "7.27.1",
4646
"@netlify/binary-info": "^1.0.0",
47-
"@netlify/serverless-functions-api": "^1.41.2",
47+
"@netlify/serverless-functions-api": "2.0.2",
4848
"@vercel/nft": "0.27.7",
4949
"archiver": "^7.0.0",
5050
"common-path-prefix": "^3.0.0",

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export const defaultFlags = {
2727
// If multiple glob stars are in includedFiles, fail the build instead of warning.
2828
zisi_esbuild_fail_double_glob: false,
2929

30-
// Adds the `___netlify-telemetry.mjs` file to the function bundle.
31-
zisi_add_instrumentation_loader: true,
32-
3330
// Dynamically import the function handler.
3431
zisi_dynamic_import_function_handler: false,
3532
} as const

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

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

53
import type { FeatureFlags } from '../../../feature_flags.js'
@@ -19,29 +17,12 @@ export const ENTRY_FILE_NAME = '___netlify-entry-point'
1917
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs'
2018
export const BOOTSTRAP_VERSION_FILE_NAME = '___netlify-bootstrap-version'
2119
export const METADATA_FILE_NAME = '___netlify-metadata.json'
22-
export const TELEMETRY_FILE_NAME = '___netlify-telemetry.mjs'
23-
24-
const require = createRequire(import.meta.url)
2520

2621
export interface EntryFile {
2722
contents: string
2823
filename: string
2924
}
3025

31-
/**
32-
* A minimal implementation of kebab-case.
33-
* It is used to transform the generator name into a service name for the telemetry file.
34-
* As DataDog has a special handling for the service name, we need to make sure it is kebab-case.
35-
*/
36-
export const kebabCase = (input: string): string =>
37-
input
38-
.replace(/([a-z])([A-Z])/g, '$1 $2')
39-
.replace(/[@#//$\s_\\.-]+/g, ' ')
40-
.trim()
41-
.toLowerCase()
42-
.split(' ')
43-
.join('-')
44-
4526
const getEntryFileContents = (
4627
mainPath: string,
4728
moduleFormat: string,
@@ -180,40 +161,6 @@ const getEntryFileName = ({
180161
return `${basename(filename, extname(filename))}${extension}`
181162
}
182163

183-
export const getTelemetryFile = (generator?: string): EntryFile => {
184-
// TODO: switch with import.meta.resolve once we drop support for Node 16.x
185-
const filePath = require.resolve('@netlify/serverless-functions-api/instrumentation.js')
186-
let serviceName: string | undefined
187-
let serviceVersion: string | undefined
188-
189-
if (generator) {
190-
// the generator can be something like: `@netlify/[email protected]`
191-
// following the convention of name@version but it must not have a version.
192-
// split the generator by the @ sign to separate name and version.
193-
// pop the last part (the version) and join the rest with a @ again.
194-
const versionSepPos = generator.lastIndexOf('@')
195-
if (versionSepPos > 1) {
196-
const name = generator.substring(0, versionSepPos)
197-
const version = generator.substring(versionSepPos + 1)
198-
serviceVersion = version
199-
serviceName = kebabCase(name)
200-
} else {
201-
serviceName = kebabCase(generator)
202-
}
203-
}
204-
205-
const contents = `
206-
var SERVICE_NAME = ${JSON.stringify(serviceName)};
207-
var SERVICE_VERSION = ${JSON.stringify(serviceVersion)};
208-
${readFileSync(filePath, 'utf8')}
209-
`
210-
211-
return {
212-
contents,
213-
filename: TELEMETRY_FILE_NAME,
214-
}
215-
}
216-
217164
export const getEntryFile = ({
218165
commonPrefix,
219166
featureFlags,

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
conflictsWithEntryFile,
2828
EntryFile,
2929
getEntryFile,
30-
getTelemetryFile,
3130
isNamedLikeEntryFile,
3231
} from './entry_file.js'
3332
import { getMetadataFile } from './metadata_file.js'
@@ -112,20 +111,14 @@ const createDirectory = async function ({
112111
userNamespace,
113112
runtimeAPIVersion,
114113
})
115-
const { contents: telemetryContents, filename: telemetryFilename } = getTelemetryFile()
116114
const functionFolder = join(destFolder, basename(filename, extension))
117115

118116
// Deleting the functions directory in case it exists before creating it.
119117
await rm(functionFolder, { recursive: true, force: true, maxRetries: 3 })
120118
await mkdir(functionFolder, { recursive: true })
121119

122120
// Writing entry files.
123-
await Promise.all([
124-
writeFile(join(functionFolder, entryFilename), entryContents),
125-
featureFlags.zisi_add_instrumentation_loader
126-
? writeFile(join(functionFolder, telemetryFilename), telemetryContents)
127-
: Promise.resolve(),
128-
])
121+
await writeFile(join(functionFolder, entryFilename), entryContents)
129122

130123
if (runtimeAPIVersion === 2) {
131124
addBootstrapFile(srcFiles, aliases)
@@ -199,7 +192,6 @@ const createZipArchive = async function ({
199192
rewrites,
200193
runtimeAPIVersion,
201194
srcFiles,
202-
generator,
203195
}: ZipNodeParameters) {
204196
const destPath = join(destFolder, `${basename(filename, extension)}.zip`)
205197
const { archive, output } = startZip(destPath)
@@ -246,11 +238,6 @@ const createZipArchive = async function ({
246238

247239
addEntryFileToZip(archive, entryFile)
248240
}
249-
const telemetryFile = getTelemetryFile(generator)
250-
251-
if (featureFlags.zisi_add_instrumentation_loader === true) {
252-
addEntryFileToZip(archive, telemetryFile)
253-
}
254241

255242
if (runtimeAPIVersion === 2) {
256243
const bootstrapPath = addBootstrapFile(srcFiles, aliases)

packages/zip-it-and-ship-it/tests/symlinked_included_files.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ test.skipIf(platform() === 'win32')('Symlinked directories from `includedFiles`
5959
expect(await readDirWithType(unzippedPath)).toEqual({
6060
'___netlify-bootstrap.mjs': false,
6161
'___netlify-entry-point.mjs': false,
62-
'___netlify-telemetry.mjs': false,
6362
'___netlify-metadata.json': false,
6463
'function.mjs': false,
6564
[join('node_modules/.pnpm/crazy-dep/package.json')]: false,
@@ -109,7 +108,6 @@ test('preserves multiple symlinks that link to the same target', async () => {
109108
expect(await readDirWithType(join(tmpDir, 'function'))).toEqual({
110109
'___netlify-bootstrap.mjs': false,
111110
'___netlify-entry-point.mjs': false,
112-
'___netlify-telemetry.mjs': false,
113111
'function.mjs': false,
114112
['node_modules/.pnpm/[email protected]/node_modules/is-even'.replace(/\//g, sep)]: true,
115113
['node_modules/.pnpm/[email protected]/node_modules/is-even-or-odd/index.js'.replace(/\//g, sep)]: false,
@@ -153,7 +151,6 @@ test('symlinks in subdir of `includedFiles` are copied over successfully', async
153151
expect(await readDirWithType(join(tmpDir, 'function'))).toEqual({
154152
'___netlify-bootstrap.mjs': false,
155153
'___netlify-entry-point.mjs': false,
156-
'___netlify-telemetry.mjs': false,
157154
'function.cjs': false,
158155
[join('subproject/node_modules/.bin/cli.js')]: true,
159156
[join('subproject/node_modules/tool/cli.js')]: false,

packages/zip-it-and-ship-it/tests/telemetry.test.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)