Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): add plugin version to tracing errors #5417

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/build/src/error/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ type GroupFunction = ({ location }: { location: ErrorLocation }) => string
export type TitleFunction = ({ location }: { location: ErrorLocation }) => string

export type ErrorInfo = {
plugin?: any
plugin?: PluginInfo
tsConfig?: any
location: ErrorLocation
}

type PluginInfo = {
packageName: string
pluginPackageJson: {
version?: string
}
}

export type BuildCommandLocation = {
buildCommand: string
buildCommandOrigin: string
Expand Down Expand Up @@ -191,6 +198,15 @@ const errorLocationToTracingAttributes = function (location: ErrorLocation): Att
return {}
}

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,
}
}

/**
* Given a BuildError, extract the relevant trace attributes to add to the on-going Span
*/
Expand All @@ -204,6 +220,7 @@ export const buildErrorToTracingAttributes = function (error: BuildError | Basic
return {
...attributes,
...errorLocationToTracingAttributes(error.errorInfo?.location),
...pluginDataToTracingAttributes(error.errorInfo?.plugin),
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/build/tests/error/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,39 @@ const testMatrixAttributeTracing = [
},
{
description: 'plugin error',
input: {
errorInfo: {
location: {
event: 'test-event',
packageName: 'test-package',
loadedFrom: 'test-loaded-from',
origin: 'test-origin',
},
plugin: {
packageName: 'test-package',
pluginPackageJson: {
version: '1.2.1',
},
},
},
severity: 'error',
type: 'plugin-error',
locationType: 'plugin-error-location-type',
},
expects: {
'build.error.severity': 'error',
'build.error.type': 'plugin-error',
'build.error.location.type': 'plugin-error-location-type',
'build.error.location.plugin.event': 'test-event',
'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.name': 'test-package',
'build.error.plugin.version': '1.2.1',
},
},
{
description: 'plugin error without plugin info',
input: {
errorInfo: {
location: {
Expand Down
Loading