Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: ship instrumentation file in functions bundle (#1726)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lukasholzer committed Apr 22, 2024
1 parent f8b965c commit 849af1d
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 19 deletions.
230 changes: 219 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@babel/parser": "^7.22.5",
"@babel/types": "7.23.6",
"@netlify/binary-info": "^1.0.0",
"@netlify/serverless-functions-api": "^1.16.2",
"@netlify/serverless-functions-api": "^1.17.0",
"@vercel/nft": "^0.23.0",
"archiver": "^6.0.0",
"common-path-prefix": "^3.0.0",
Expand Down
3 changes: 3 additions & 0 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const defaultFlags = {

// fixes symlinks in included files
zisi_fix_symlinks: false,

// Adds the `___netlify-telemetry.mjs` file to the function bundle.
zisi_add_instrumentation_loader: true,
} as const

export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>
Expand Down
16 changes: 16 additions & 0 deletions src/runtimes/node/utils/entry_file.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { readFileSync } from 'fs'
import { createRequire } from 'module'
import { basename, extname, resolve } from 'path'

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

export const ENTRY_FILE_NAME = '___netlify-entry-point'
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs'
export const TELEMETRY_FILE_NAME = '___netlify-telemetry.mjs'

const require = createRequire(import.meta.url)

export interface EntryFile {
contents: string
Expand Down Expand Up @@ -153,6 +158,17 @@ const getEntryFileName = ({
return `${basename(filename, extname(filename))}${extension}`
}

export const getTelemetryFile = (): EntryFile => {
// TODO: switch with import.meta.resolve once we drop support for Node 16.x
const filePath = require.resolve('@netlify/serverless-functions-api/instrumentation.js')
const contents = readFileSync(filePath, 'utf8')

return {
contents,
filename: TELEMETRY_FILE_NAME,
}
}

export const getEntryFile = ({
commonPrefix,
featureFlags,
Expand Down

1 comment on commit 849af1d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 1.3s
  • largeDepsNft: 5.5s
  • largeDepsZisi: 10.2s

Please sign in to comment.