Skip to content

Commit

Permalink
feat(build): Add trace attribute to track builds failing from Netlify…
Browse files Browse the repository at this point in the history
… maintained extensions (#5914)

* feat(build): track netlify owned extensions

* feat: add if plugin is maintained by netlify

* fix: move adding new plugin attribute to where the others are set

* fix: update netlify maintained extension names

* chore: cleanup

* chore: remove unused trace attribute

* chore: add debug logs

* update console.log

* chore: log integrations

* fix: fix debug log

* chore: add extension author to trace

* fix: add auth and slug to trace correctly

* chore: add slug and author to trace

* chore: add debug logs

* chore: add extensionMetadata to attributes

* chore: clean up

* fix: fix unused var error

* chore: add types for extension metadata

* chore: remove debug log

* chore: update test

---------

Co-authored-by: NikAiyer <[email protected]>
  • Loading branch information
YujohnNattrass and NikAiyer authored Dec 11, 2024
1 parent c22be64 commit 7e99c26
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/build/src/error/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ type PluginInfo = {
pluginPackageJson: {
version?: string
}
extensionMetadata?: {
slug: string
name: string
version: string
has_build: boolean
has_connector: boolean
author?: string
}
}

export type BuildCommandLocation = {
Expand Down Expand Up @@ -201,9 +209,12 @@ const errorLocationToTracingAttributes = function (location: ErrorLocation): Att
const pluginDataToTracingAttributes = function (pluginInfo?: PluginInfo): Attributes {
const pluginAttributePrefix = `${buildErrorAttributePrefix}.plugin`
if (typeof pluginInfo === 'undefined') return {}

return {
[`${pluginAttributePrefix}.name`]: pluginInfo?.packageName,
[`${pluginAttributePrefix}.version`]: pluginInfo?.pluginPackageJson?.version,
[`${pluginAttributePrefix}.extensionAuthor`]: pluginInfo?.extensionMetadata?.author,
[`${pluginAttributePrefix}.extensionSlug`]: pluginInfo?.extensionMetadata?.slug,
}
}

Expand Down
18 changes: 16 additions & 2 deletions packages/build/src/plugins/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ const loadAllPlugins = measureDuration(tLoadAllPlugins, 'load_plugins')
// Retrieve plugin steps for one plugin.
// Do it by executing the plugin `load` event handler.
const loadPlugin = async function (
{ packageName, pluginPackageJson, pluginPackageJson: { version } = {}, pluginPath, inputs, loadedFrom, origin },
{
packageName,
pluginPackageJson,
pluginPackageJson: { version } = {},
pluginPath,
inputs,
loadedFrom,
origin,
integration,
},
{ childProcesses, index, packageJson, logs, debug, verbose, netlifyConfig, featureFlags, systemLog },
) {
const { childProcess } = childProcesses[index]
Expand All @@ -97,6 +106,7 @@ const loadPlugin = async function (
origin,
pluginPackageJson,
childProcess,
extensionMetadata: integration,
}))
return pluginSteps
} catch (error) {
Expand All @@ -106,7 +116,11 @@ const loadPlugin = async function (
}

addErrorInfo(error, {
plugin: { packageName, pluginPackageJson },
plugin: {
packageName,
pluginPackageJson,
extensionMetadata: integration,
},
location: { event: loadEvent, packageName, loadedFrom, origin },
})
addPluginLoadErrorStatus({ error, packageName, version, debug })
Expand Down
3 changes: 2 additions & 1 deletion packages/build/src/steps/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const firePluginStep = async function ({
featureFlags,
debug,
verbose,
extensionMetadata,
}) {
const standardStreams = getStandardStreams(outputFlusher)
const listeners = pipePluginOutput(childProcess, logs, standardStreams)
Expand Down Expand Up @@ -103,7 +104,7 @@ export const firePluginStep = async function ({
const errorType = getPluginErrorType(newError, loadedFrom, packageName)
addErrorInfo(newError, {
...errorType,
plugin: { pluginPackageJson, packageName },
plugin: { pluginPackageJson, packageName, extensionMetadata },
location: { event, packageName, loadedFrom, origin },
})
return { newError }
Expand Down
4 changes: 4 additions & 0 deletions packages/build/src/steps/run_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const runStep = async function ({
userNodeVersion,
explicitSecretKeys,
edgeFunctionsBootstrapURL,
extensionMetadata,
}) {
// Add relevant attributes to the upcoming span context
const attributes: StepExecutionAttributes = {
Expand Down Expand Up @@ -144,6 +145,7 @@ export const runStep = async function ({
durationNs,
metrics,
} = await fireStep({
extensionMetadata,
defaultConfig,
event,
childProcess,
Expand Down Expand Up @@ -349,6 +351,7 @@ const tFireStep = function ({
explicitSecretKeys,
edgeFunctionsBootstrapURL,
deployId,
extensionMetadata,
}) {
if (coreStep !== undefined) {
return fireCoreStep({
Expand Down Expand Up @@ -414,5 +417,6 @@ const tFireStep = function ({
featureFlags,
debug,
verbose,
extensionMetadata,
})
}
2 changes: 2 additions & 0 deletions packages/build/src/steps/run_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const runSteps = async function ({
event,
childProcess,
packageName,
extensionMetadata,
coreStep,
coreStepId,
coreStepName,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const runSteps = async function ({
event,
childProcess,
packageName,
extensionMetadata,
coreStep,
coreStepId,
coreStepName,
Expand Down
6 changes: 6 additions & 0 deletions packages/build/tests/error/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ const testMatrixAttributeTracing = [
pluginPackageJson: {
version: '1.2.1',
},
extensionMetadata: {
slug: 'test-extension-slug',
author: 'test-extension-author',
},
},
},
severity: 'error',
Expand All @@ -159,6 +163,8 @@ const testMatrixAttributeTracing = [
'build.error.location.plugin.package_name': 'test-package',
'build.error.location.plugin.loaded_from': 'test-loaded-from',
'build.error.location.plugin.origin': 'test-origin',
'build.error.plugin.extensionAuthor': 'test-extension-author',
'build.error.plugin.extensionSlug': 'test-extension-slug',
'build.error.plugin.name': 'test-package',
'build.error.plugin.version': '1.2.1',
},
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/types/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type Integration = {
dev?: {
path: string
}
author?: string
}

0 comments on commit 7e99c26

Please sign in to comment.