From 10ddf2167e115b2a0a968df18f401349a7dfa0e1 Mon Sep 17 00:00:00 2001 From: Francine Lucca <40550942+francinelucca@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:09:03 -0500 Subject: [PATCH] feat: add new keys to element and dependency metrics (#169) * feat: add new keys to element and dependency metrics * fix: pull in npm and jsx attributes from @ibm/telemetry-attributes-js --- package-lock.json | 7 + package.json | 1 + src/main/scopes/jsx/jsx-scope-attributes.ts | 22 --- src/main/scopes/jsx/jsx-scope.ts | 23 ++- src/main/scopes/jsx/metrics/element-metric.ts | 38 +++- .../scopes/npm/metrics/dependency-metric.ts | 54 +++--- src/main/scopes/npm/npm-scope-attributes.ts | 36 ---- src/main/scopes/npm/npm-scope.ts | 16 +- .../__snapshots__/jsx-scope.e2e.test.ts.snap | 12 ++ .../scopes/jsx/metrics/element-metric.test.ts | 170 ++++++++++++++--- .../__snapshots__/npm-scope.e2e.test.ts.snap | 28 +-- .../npm/metrics/dependency-metric.test.ts | 180 ++++++++++-------- 12 files changed, 363 insertions(+), 224 deletions(-) delete mode 100644 src/main/scopes/jsx/jsx-scope-attributes.ts delete mode 100644 src/main/scopes/npm/npm-scope-attributes.ts diff --git a/package-lock.json b/package-lock.json index ef8db57e..2f28585c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@commitlint/cli": "^17.8.1", "@commitlint/config-conventional": "^17.8.1", + "@ibm/telemetry-attributes-js": "^2.0.0", "@ibm/telemetry-config-schema": "^0.3.0", "@opentelemetry/api": "^1.7.0", "@opentelemetry/exporter-metrics-otlp-http": "^0.46.0", @@ -1032,6 +1033,12 @@ "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", "dev": true }, + "node_modules/@ibm/telemetry-attributes-js": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@ibm/telemetry-attributes-js/-/telemetry-attributes-js-2.0.0.tgz", + "integrity": "sha512-7Xg6FtPKO/khBqXTTjDkXGDza3QtP5i3RHt/ds0M3jpVPXgSCB5i0d+xPxma3zaZ+aQyYUXE5rSzWRY8kIYVWQ==", + "dev": true + }, "node_modules/@ibm/telemetry-config-schema": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@ibm/telemetry-config-schema/-/telemetry-config-schema-0.3.0.tgz", diff --git a/package.json b/package.json index 6ef7c248..cd1e607f 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "devDependencies": { "@commitlint/cli": "^17.8.1", "@commitlint/config-conventional": "^17.8.1", + "@ibm/telemetry-attributes-js": "^2.0.0", "@ibm/telemetry-config-schema": "^0.3.0", "@opentelemetry/api": "^1.7.0", "@opentelemetry/exporter-metrics-otlp-http": "^0.46.0", diff --git a/src/main/scopes/jsx/jsx-scope-attributes.ts b/src/main/scopes/jsx/jsx-scope-attributes.ts deleted file mode 100644 index 525e20a8..00000000 --- a/src/main/scopes/jsx/jsx-scope-attributes.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright IBM Corp. 2023, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ -export const JsxScopeAttributes = Object.freeze({ - // - // Attributes relating to a jsx element - // - NAME: 'jsx.element.name', - MODULE_SPECIFIER: 'jsx.element.module.specifier', - ATTRIBUTE_NAMES: 'jsx.element.attributes.names', - ATTRIBUTE_VALUES: 'jsx.element.attributes.values', - - // - // Attributes relating to a jsx element's invoker - // - INVOKER_PACKAGE_RAW: 'jsx.element.invoker.package.raw', - INVOKER_PACKAGE_NAME: 'jsx.element.invoker.package.name', - INVOKER_PACKAGE_OWNER: 'jsx.element.invoker.package.owner' -}) diff --git a/src/main/scopes/jsx/jsx-scope.ts b/src/main/scopes/jsx/jsx-scope.ts index 00edb44c..912a18b8 100644 --- a/src/main/scopes/jsx/jsx-scope.ts +++ b/src/main/scopes/jsx/jsx-scope.ts @@ -13,6 +13,7 @@ import { Scope } from '../../core/scope.js' import { EmptyScopeError } from '../../exceptions/empty-scope.error.js' import { getDirectoryPrefix } from '../npm/get-directory-prefix.js' import { getPackageData } from '../npm/get-package-data.js' +import { PackageData } from '../npm/interfaces.js' import { AllImportMatcher } from './import-matchers/all-import-matcher.js' import { NamedImportMatcher } from './import-matchers/named-import-matcher.js' import { RenamedImportMatcher } from './import-matchers/renamed-import-matcher.js' @@ -71,9 +72,9 @@ export class JsxScope extends Scope { for (const sourceFile of sourceFiles) { if (this.runSync) { - await this.captureFileMetrics(sourceFile, instrumentedPackage.name, importMatchers) + await this.captureFileMetrics(sourceFile, instrumentedPackage, importMatchers) } else { - promises.push(this.captureFileMetrics(sourceFile, instrumentedPackage.name, importMatchers)) + promises.push(this.captureFileMetrics(sourceFile, instrumentedPackage, importMatchers)) } } @@ -85,18 +86,19 @@ export class JsxScope extends Scope { * in the supplied SourceFile node. * * @param sourceFile - The sourcefile node to generate metrics for. - * @param instrumentedPackageName - Name of the instrumented package to capture metrics for. + * @param instrumentedPackage - Name and version of the instrumented package + * to capture metrics for. * @param importMatchers - Matchers instances to use for import-element matching. */ async captureFileMetrics( sourceFile: ts.SourceFile, - instrumentedPackageName: string, + instrumentedPackage: PackageData, importMatchers: JsxElementImportMatcher[] ) { const accumulator = new JsxElementAccumulator() this.processFile(accumulator, sourceFile) - this.removeIrrelevantImports(accumulator, instrumentedPackageName) + this.removeIrrelevantImports(accumulator, instrumentedPackage.name) this.resolveElementImports(accumulator, importMatchers) await this.resolveInvokers(accumulator, sourceFile.fileName) @@ -108,7 +110,16 @@ export class JsxScope extends Scope { return } - this.capture(new ElementMetric(jsxElement, jsxImport, invoker, this.config, this.logger)) + this.capture( + new ElementMetric( + jsxElement, + jsxImport, + invoker, + instrumentedPackage, + this.config, + this.logger + ) + ) }) } diff --git a/src/main/scopes/jsx/metrics/element-metric.ts b/src/main/scopes/jsx/metrics/element-metric.ts index 18b70f3d..4b8650e6 100644 --- a/src/main/scopes/jsx/metrics/element-metric.ts +++ b/src/main/scopes/jsx/metrics/element-metric.ts @@ -4,6 +4,7 @@ * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +import { JsxScopeAttributes, NpmScopeAttributes } from '@ibm/telemetry-attributes-js' import { type ConfigSchema } from '@ibm/telemetry-config-schema' import { Attributes } from '@opentelemetry/api' @@ -13,8 +14,8 @@ import { deNull } from '../../../core/de-null.js' import { type Logger } from '../../../core/log/logger.js' import { PackageDetailsProvider } from '../../../core/package-details-provider.js' import { ScopeMetric } from '../../../core/scope-metric.js' +import { PackageData } from '../../npm/interfaces.js' import { type JsxElement, type JsxElementAttribute, type JsxImport } from '../interfaces.js' -import { JsxScopeAttributes } from '../jsx-scope-attributes.js' /** * JSX scope metric that generates a jsx.element individual metric for a given element. @@ -26,6 +27,7 @@ export class ElementMetric extends ScopeMetric { private readonly invoker: string | undefined private readonly allowedAttributeNames: string[] private readonly allowedAttributeStringValues: string[] + private readonly instrumentedPackage: PackageData /** * Constructs a JsxElementMetric. @@ -33,6 +35,7 @@ export class ElementMetric extends ScopeMetric { * @param jsxElement - Object containing name and version to extract data to generate metric from. * @param matchingImport - Import that matched the provided JsxElement in the file. * @param invoker - Name of the package that invoked the JsxElement. + * @param instrumentedPackage - Data (name and version) pertaining to instrumented package. * @param config - Determines which attributes name and values to collect for. * @param logger - Logger instance. */ @@ -40,6 +43,7 @@ export class ElementMetric extends ScopeMetric { jsxElement: JsxElement, matchingImport: JsxImport, invoker: string | undefined, + instrumentedPackage: PackageData, config: ConfigSchema, logger: Logger ) { @@ -47,6 +51,7 @@ export class ElementMetric extends ScopeMetric { this.jsxElement = jsxElement this.matchingImport = matchingImport this.invoker = invoker + this.instrumentedPackage = instrumentedPackage this.allowedAttributeNames = config.collect.jsx?.elements?.allowedAttributeNames ?? [] this.allowedAttributeStringValues = @@ -82,6 +87,20 @@ export class ElementMetric extends ScopeMetric { this.allowedAttributeStringValues ) + const packageDetailsProvider = new PackageDetailsProvider(this.logger) + + const { + owner: instrumentedOwner, + name: instrumentedName, + major: instrumentedMajor, + minor: instrumentedMinor, + patch: instrumentedPatch, + preRelease: instrumentedPreRelease + } = packageDetailsProvider.getPackageDetails( + this.instrumentedPackage.name, + this.instrumentedPackage.version + ) + let metricData: Attributes = { [JsxScopeAttributes.NAME]: this.jsxElement.name, [JsxScopeAttributes.MODULE_SPECIFIER]: this.matchingImport.path, @@ -91,7 +110,15 @@ export class ElementMetric extends ScopeMetric { ), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: this.invoker, [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: invokingPackageDetails?.owner, - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: invokingPackageDetails?.name + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: invokingPackageDetails?.name, + [NpmScopeAttributes.INSTRUMENTED_RAW]: this.instrumentedPackage.name, + [NpmScopeAttributes.INSTRUMENTED_OWNER]: instrumentedOwner, + [NpmScopeAttributes.INSTRUMENTED_NAME]: instrumentedName, + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: this.instrumentedPackage.version, + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: instrumentedMajor?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: instrumentedMinor?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: instrumentedPatch?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: instrumentedPreRelease?.join('.') } // Handle renamed elements @@ -105,7 +132,12 @@ export class ElementMetric extends ScopeMetric { metricData = hash(metricData, [ JsxScopeAttributes.INVOKER_PACKAGE_RAW, JsxScopeAttributes.INVOKER_PACKAGE_OWNER, - JsxScopeAttributes.INVOKER_PACKAGE_NAME + JsxScopeAttributes.INVOKER_PACKAGE_NAME, + NpmScopeAttributes.INSTRUMENTED_RAW, + NpmScopeAttributes.INSTRUMENTED_OWNER, + NpmScopeAttributes.INSTRUMENTED_NAME, + NpmScopeAttributes.INSTRUMENTED_VERSION_RAW, + NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE ]) return metricData diff --git a/src/main/scopes/npm/metrics/dependency-metric.ts b/src/main/scopes/npm/metrics/dependency-metric.ts index efa7e85c..ebb85fd8 100644 --- a/src/main/scopes/npm/metrics/dependency-metric.ts +++ b/src/main/scopes/npm/metrics/dependency-metric.ts @@ -4,19 +4,18 @@ * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +import { NpmScopeAttributes } from '@ibm/telemetry-attributes-js' import { Attributes } from '@opentelemetry/api' import { hash } from '../../../core/anonymize/hash.js' import { type Logger } from '../../../core/log/logger.js' import { PackageDetailsProvider } from '../../../core/package-details-provider.js' import { ScopeMetric } from '../../../core/scope-metric.js' -import { NpmScopeAttributes } from '../npm-scope-attributes.js' +import { PackageData } from '../interfaces.js' export interface DependencyData { rawName: string rawVersion: string - installerRawName: string - installerRawVersion: string isInstrumented: 'true' | 'false' } @@ -27,16 +26,19 @@ export class DependencyMetric extends ScopeMetric { public override name = 'npm.dependency' as const private readonly data: DependencyData + private readonly instrumentedPackage: PackageData /** * Constructs a DependencyMetric. * * @param data - Object containing name and version to extract data to generate metric from. + * @param instrumentedPackage - Data (name and version) pertaining to instrumented package. * @param logger - The logger instance to use. */ - public constructor(data: DependencyData, logger: Logger) { + public constructor(data: DependencyData, instrumentedPackage: PackageData, logger: Logger) { super(logger) this.data = data + this.instrumentedPackage = instrumentedPackage } /** @@ -51,35 +53,35 @@ export class DependencyMetric extends ScopeMetric { packageDetailsProvider.getPackageDetails(this.data.rawName, this.data.rawVersion) const { - owner: installerOwner, - name: installerName, - major: installerMajor, - minor: installerMinor, - patch: installerPatch, - preRelease: installerPreRelease + owner: instrumentedOwner, + name: instrumentedName, + major: instrumentedMajor, + minor: instrumentedMinor, + patch: instrumentedPatch, + preRelease: instrumentedPreRelease } = packageDetailsProvider.getPackageDetails( - this.data.installerRawName, - this.data.installerRawVersion + this.instrumentedPackage.name, + this.instrumentedPackage.version ) const metricData: Attributes = { [NpmScopeAttributes.RAW]: this.data.rawName, [NpmScopeAttributes.OWNER]: owner, [NpmScopeAttributes.NAME]: name, - [NpmScopeAttributes.INSTRUMENTED]: this.data.isInstrumented, + [NpmScopeAttributes.IS_INSTRUMENTED]: this.data.isInstrumented, [NpmScopeAttributes.VERSION_RAW]: this.data.rawVersion, [NpmScopeAttributes.VERSION_MAJOR]: major?.toString(), [NpmScopeAttributes.VERSION_MINOR]: minor?.toString(), [NpmScopeAttributes.VERSION_PATCH]: patch?.toString(), [NpmScopeAttributes.VERSION_PRE_RELEASE]: preRelease?.join('.'), - [NpmScopeAttributes.INSTALLER_RAW]: this.data.installerRawName, - [NpmScopeAttributes.INSTALLER_OWNER]: installerOwner, - [NpmScopeAttributes.INSTALLER_NAME]: installerName, - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: this.data.installerRawVersion, - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: installerMajor?.toString(), - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: installerMinor?.toString(), - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: installerPatch?.toString(), - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: installerPreRelease?.join('.') + [NpmScopeAttributes.INSTRUMENTED_RAW]: this.instrumentedPackage.name, + [NpmScopeAttributes.INSTRUMENTED_OWNER]: instrumentedOwner, + [NpmScopeAttributes.INSTRUMENTED_NAME]: instrumentedName, + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: this.instrumentedPackage.version, + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: instrumentedMajor?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: instrumentedMinor?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: instrumentedPatch?.toString(), + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: instrumentedPreRelease?.join('.') } return hash(metricData, [ @@ -88,11 +90,11 @@ export class DependencyMetric extends ScopeMetric { NpmScopeAttributes.NAME, NpmScopeAttributes.VERSION_RAW, NpmScopeAttributes.VERSION_PRE_RELEASE, - NpmScopeAttributes.INSTALLER_RAW, - NpmScopeAttributes.INSTALLER_OWNER, - NpmScopeAttributes.INSTALLER_NAME, - NpmScopeAttributes.INSTALLER_VERSION_RAW, - NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE + NpmScopeAttributes.INSTRUMENTED_RAW, + NpmScopeAttributes.INSTRUMENTED_OWNER, + NpmScopeAttributes.INSTRUMENTED_NAME, + NpmScopeAttributes.INSTRUMENTED_VERSION_RAW, + NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE ]) } } diff --git a/src/main/scopes/npm/npm-scope-attributes.ts b/src/main/scopes/npm/npm-scope-attributes.ts deleted file mode 100644 index 095fa594..00000000 --- a/src/main/scopes/npm/npm-scope-attributes.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright IBM Corp. 2023, 2023 - * - * This source code is licensed under the Apache-2.0 license found in the - * LICENSE file in the root directory of this source tree. - */ -export const NpmScopeAttributes = Object.freeze({ - // - // General dependency name attributes - // - RAW: 'npm.dependency.raw', - OWNER: 'npm.dependency.owner', - NAME: 'npm.dependency.name', - INSTRUMENTED: 'npm.dependency.instrumented', - - // - // Semantic version attributes - // - VERSION_RAW: 'npm.dependency.version.raw', - VERSION_MAJOR: 'npm.dependency.version.major', - VERSION_MINOR: 'npm.dependency.version.minor', - VERSION_PATCH: 'npm.dependency.version.patch', - VERSION_PRE_RELEASE: 'npm.dependency.version.preRelease', - - // - // Attributes relating to a dependency's installer - // - INSTALLER_RAW: 'npm.dependency.installer.raw', - INSTALLER_OWNER: 'npm.dependency.installer.owner', - INSTALLER_NAME: 'npm.dependency.installer.name', - INSTALLER_VERSION_RAW: 'npm.dependency.installer.version.raw', - INSTALLER_VERSION_MAJOR: 'npm.dependency.installer.version.major', - INSTALLER_VERSION_MINOR: 'npm.dependency.installer.version.minor', - INSTALLER_VERSION_PATCH: 'npm.dependency.installer.version.patch', - INSTALLER_VERSION_PRE_RELEASE: 'npm.dependency.installer.version.preRelease' -}) diff --git a/src/main/scopes/npm/npm-scope.ts b/src/main/scopes/npm/npm-scope.ts index 9ae447c1..c93278ae 100644 --- a/src/main/scopes/npm/npm-scope.ts +++ b/src/main/scopes/npm/npm-scope.ts @@ -28,13 +28,10 @@ export class NpmScope extends Scope { */ @Trace() private async collectDependencies(): Promise { - const { name: instrumentedPkgName, version: instrumentedPkgVersion } = await getPackageData( - this.cwd, - this.logger - ) + const instrumentedPkg = await getPackageData(this.cwd, this.logger) const installingPackages = await this.findInstallingPackages( - instrumentedPkgName, - instrumentedPkgVersion + instrumentedPkg.name, + instrumentedPkg.version ) installingPackages.forEach((installingPkg) => { @@ -44,14 +41,13 @@ export class NpmScope extends Scope { { rawName: dependency.name, rawVersion: dependency.version, - installerRawName: installingPkg.name, - installerRawVersion: installingPkg.version, isInstrumented: - dependency.name === instrumentedPkgName && - dependency.version === instrumentedPkgVersion + dependency.name === instrumentedPkg.name && + dependency.version === instrumentedPkg.version ? 'true' : 'false' }, + instrumentedPkg, this.logger ) ) diff --git a/src/test/scopes/jsx/__snapshots__/jsx-scope.e2e.test.ts.snap b/src/test/scopes/jsx/__snapshots__/jsx-scope.e2e.test.ts.snap index dacecd6c..cdaa51fb 100644 --- a/src/test/scopes/jsx/__snapshots__/jsx-scope.e2e.test.ts.snap +++ b/src/test/scopes/jsx/__snapshots__/jsx-scope.e2e.test.ts.snap @@ -116,6 +116,12 @@ exports[`class: JsxScope > run > correctly captures jsx element metric data 1`] "jsx.element.invoker.package.raw": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", "jsx.element.module.specifier": "instrumented", "jsx.element.name": "[Default]", + "npm.dependency.instrumented.name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.raw": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.version.major": "0", + "npm.dependency.instrumented.version.minor": "1", + "npm.dependency.instrumented.version.patch": "0", + "npm.dependency.instrumented.version.raw": "6ad9613a455798d6d92e5f5f390ab4baa70596bc869ed6b17f5cdd2b28635f06", }, "endTime": [ 0, @@ -153,6 +159,12 @@ exports[`class: JsxScope > run > correctly captures jsx element metric data 1`] "jsx.element.invoker.package.raw": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", "jsx.element.module.specifier": "instrumented", "jsx.element.name": "ImaginaryThing", + "npm.dependency.instrumented.name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.raw": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.version.major": "0", + "npm.dependency.instrumented.version.minor": "1", + "npm.dependency.instrumented.version.patch": "0", + "npm.dependency.instrumented.version.raw": "6ad9613a455798d6d92e5f5f390ab4baa70596bc869ed6b17f5cdd2b28635f06", }, "endTime": [ 0, diff --git a/src/test/scopes/jsx/metrics/element-metric.test.ts b/src/test/scopes/jsx/metrics/element-metric.test.ts index 8b26087e..ad360113 100644 --- a/src/test/scopes/jsx/metrics/element-metric.test.ts +++ b/src/test/scopes/jsx/metrics/element-metric.test.ts @@ -4,6 +4,7 @@ * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +import { JsxScopeAttributes, NpmScopeAttributes } from '@ibm/telemetry-attributes-js' import { type ConfigSchema } from '@ibm/telemetry-config-schema' import { describe, expect, it } from 'vitest' @@ -14,7 +15,6 @@ import { JsxElementAttribute, type JsxImport } from '../../../../main/scopes/jsx/interfaces.js' -import { JsxScopeAttributes } from '../../../../main/scopes/jsx/jsx-scope-attributes.js' import { ElementMetric } from '../../../../main/scopes/jsx/metrics/element-metric.js' import { initLogger } from '../../../__utils/init-logger.js' @@ -52,8 +52,14 @@ describe('class: ElementMetric', () => { } it('returns the correct attributes for a standard element', () => { - const attributes = new ElementMetric(jsxElement, jsxImport, 'the-library', config, logger) - .attributes + const attributes = new ElementMetric( + jsxElement, + jsxImport, + 'the-library', + { name: 'instrumented', version: '1.0.0' }, + config, + logger + ).attributes const attrMap = jsxElement.attributes.reduce>( (prev, cur) => { return { ...prev, [cur.name]: cur.value } @@ -72,12 +78,25 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(subs), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: 'the-library', [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: undefined, - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library' + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library', + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'jsx.element.invoker.package.raw', 'jsx.element.invoker.package.owner', - 'jsx.element.invoker.package.name' + 'jsx.element.invoker.package.name', + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -85,8 +104,17 @@ describe('class: ElementMetric', () => { it('returns the correct attributes for a renamed element', () => { const renamedImport = { ...jsxImport, name: 'theActualName', rename: 'theName' } - const attributes = new ElementMetric(jsxElement, renamedImport, 'the-library', config, logger) - .attributes + const attributes = new ElementMetric( + jsxElement, + renamedImport, + 'the-library', + { + name: 'instrumented', + version: '1.0.0-rc.4' + }, + config, + logger + ).attributes const attrMap = jsxElement.attributes.reduce>((prev, cur) => { return { ...prev, [cur.name]: cur.value } }, {}) @@ -102,12 +130,25 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(subs), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: 'the-library', [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: undefined, - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library' + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library', + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0-rc.4', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: 'rc.4' }, [ 'jsx.element.invoker.package.raw', 'jsx.element.invoker.package.owner', - 'jsx.element.invoker.package.name' + 'jsx.element.invoker.package.name', + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -115,8 +156,17 @@ describe('class: ElementMetric', () => { it('returns the correct attributes for a default element', () => { const defaultImport = { ...jsxImport, name: '[Default]', rename: 'theName', isDefault: true } - const attributes = new ElementMetric(jsxElement, defaultImport, 'the-library', config, logger) - .attributes + const attributes = new ElementMetric( + jsxElement, + defaultImport, + 'the-library', + { + name: 'instrumented', + version: '1.0.0+9999' + }, + config, + logger + ).attributes const attrMap = jsxElement.attributes.reduce>((prev, cur) => { return { ...prev, [cur.name]: cur.value } }, {}) @@ -132,20 +182,42 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(subs), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: 'the-library', [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: undefined, - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library' + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'the-library', + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0+9999', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'jsx.element.invoker.package.raw', 'jsx.element.invoker.package.owner', - 'jsx.element.invoker.package.name' + 'jsx.element.invoker.package.name', + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) }) it('returns the correct attributes for an element with no invoker', () => { - const attributes = new ElementMetric(jsxElement, jsxImport, undefined, config, logger) - .attributes + const attributes = new ElementMetric( + jsxElement, + jsxImport, + undefined, + { + name: 'instrumented', + version: '1.0.0-rc.0+9999' + }, + config, + logger + ).attributes const attrMap = jsxElement.attributes.reduce>((prev, cur) => { return { ...prev, [cur.name]: cur.value } }, {}) @@ -161,20 +233,42 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(subs), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: undefined, [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: undefined, - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: undefined + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: undefined, + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0-rc.0+9999', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: 'rc.0' }, [ 'jsx.element.invoker.package.raw', 'jsx.element.invoker.package.owner', - 'jsx.element.invoker.package.name' + 'jsx.element.invoker.package.name', + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) }) it('returns the correct attributes for an element with invoker that has owner', () => { - const attributes = new ElementMetric(jsxElement, jsxImport, '@owner/library', config, logger) - .attributes + const attributes = new ElementMetric( + jsxElement, + jsxImport, + '@owner/library', + { + name: '@instrumented/instrumented', + version: '1.0.0' + }, + config, + logger + ).attributes const attrMap = jsxElement.attributes.reduce>((prev, cur) => { return { ...prev, [cur.name]: cur.value } @@ -191,12 +285,25 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(subs), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: '@owner/library', [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: '@owner', - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'library' + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'library', + [NpmScopeAttributes.INSTRUMENTED_RAW]: '@instrumented/instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: '@instrumented', + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'jsx.element.invoker.package.raw', 'jsx.element.invoker.package.owner', - 'jsx.element.invoker.package.name' + 'jsx.element.invoker.package.name', + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -228,6 +335,10 @@ describe('class: ElementMetric', () => { elementWithAllowedAttrs, jsxImport, '@owner/library', + { + name: '@instrumented/instrumented', + version: '1.0.0+123456' + }, config, logger ).attributes @@ -250,12 +361,25 @@ describe('class: ElementMetric', () => { [JsxScopeAttributes.ATTRIBUTE_VALUES]: Object.values(substitutedAttributes), [JsxScopeAttributes.INVOKER_PACKAGE_RAW]: '@owner/library', [JsxScopeAttributes.INVOKER_PACKAGE_OWNER]: '@owner', - [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'library' + [JsxScopeAttributes.INVOKER_PACKAGE_NAME]: 'library', + [NpmScopeAttributes.INSTRUMENTED_RAW]: '@instrumented/instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: '@instrumented', + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0+123456', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ JsxScopeAttributes.INVOKER_PACKAGE_RAW, JsxScopeAttributes.INVOKER_PACKAGE_OWNER, - JsxScopeAttributes.INVOKER_PACKAGE_NAME + JsxScopeAttributes.INVOKER_PACKAGE_NAME, + NpmScopeAttributes.INSTRUMENTED_RAW, + NpmScopeAttributes.INSTRUMENTED_OWNER, + NpmScopeAttributes.INSTRUMENTED_NAME, + NpmScopeAttributes.INSTRUMENTED_VERSION_RAW, + NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE ] ) ) diff --git a/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap b/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap index 148705c4..3bad9a10 100644 --- a/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap +++ b/src/test/scopes/npm/__snapshots__/npm-scope.e2e.test.ts.snap @@ -68,13 +68,13 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` "dataPoints": [ { "attributes": { - "npm.dependency.installer.name": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", - "npm.dependency.installer.raw": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", - "npm.dependency.installer.version.major": "1", - "npm.dependency.installer.version.minor": "0", - "npm.dependency.installer.version.patch": "0", - "npm.dependency.installer.version.raw": "92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305", - "npm.dependency.instrumented": "false", + "npm.dependency.instrumented.name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.raw": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.version.major": "0", + "npm.dependency.instrumented.version.minor": "1", + "npm.dependency.instrumented.version.patch": "0", + "npm.dependency.instrumented.version.raw": "6ad9613a455798d6d92e5f5f390ab4baa70596bc869ed6b17f5cdd2b28635f06", + "npm.dependency.isInstrumented": "false", "npm.dependency.name": "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", "npm.dependency.raw": "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", "npm.dependency.version.major": "1", @@ -94,13 +94,13 @@ exports[`class: NpmScope > run > correctly captures dependency data 1`] = ` }, { "attributes": { - "npm.dependency.installer.name": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", - "npm.dependency.installer.raw": "e497ed4e62a3b47d9cd8aaebefb6c0837b94fb8d710461ba203aa33ccf64cc4d", - "npm.dependency.installer.version.major": "1", - "npm.dependency.installer.version.minor": "0", - "npm.dependency.installer.version.patch": "0", - "npm.dependency.installer.version.raw": "92521fc3cbd964bdc9f584a991b89fddaa5754ed1cc96d6d42445338669c1305", - "npm.dependency.instrumented": "true", + "npm.dependency.instrumented.name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.raw": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", + "npm.dependency.instrumented.version.major": "0", + "npm.dependency.instrumented.version.minor": "1", + "npm.dependency.instrumented.version.patch": "0", + "npm.dependency.instrumented.version.raw": "6ad9613a455798d6d92e5f5f390ab4baa70596bc869ed6b17f5cdd2b28635f06", + "npm.dependency.isInstrumented": "true", "npm.dependency.name": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", "npm.dependency.raw": "ec46e364d52dab2e207d33617267a84df5838926793c1b0a2974899fe28229f1", "npm.dependency.version.major": "0", diff --git a/src/test/scopes/npm/metrics/dependency-metric.test.ts b/src/test/scopes/npm/metrics/dependency-metric.test.ts index df371360..6550c474 100644 --- a/src/test/scopes/npm/metrics/dependency-metric.test.ts +++ b/src/test/scopes/npm/metrics/dependency-metric.test.ts @@ -4,11 +4,11 @@ * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ +import { NpmScopeAttributes } from '@ibm/telemetry-attributes-js' import { describe, expect, it } from 'vitest' import { hash } from '../../../../main/core/anonymize/hash.js' import { DependencyMetric } from '../../../../main/scopes/npm/metrics/dependency-metric.js' -import { NpmScopeAttributes } from '../../../../main/scopes/npm/npm-scope-attributes.js' import { initLogger } from '../../../__utils/init-logger.js' describe('class: DependencyMetric', () => { @@ -19,10 +19,12 @@ describe('class: DependencyMetric', () => { { rawName: 'test-1', rawVersion: '0.0.1', - installerRawName: 'test-1-installer', - installerRawVersion: '1.0.0', isInstrumented: 'false' }, + { + name: 'test-1-instrumented', + version: '1.0.0' + }, logger ).attributes expect(attributes).toStrictEqual( @@ -31,20 +33,20 @@ describe('class: DependencyMetric', () => { [NpmScopeAttributes.RAW]: 'test-1', [NpmScopeAttributes.OWNER]: undefined, [NpmScopeAttributes.NAME]: 'test-1', - [NpmScopeAttributes.INSTRUMENTED]: 'false', + [NpmScopeAttributes.IS_INSTRUMENTED]: 'false', [NpmScopeAttributes.VERSION_RAW]: '0.0.1', [NpmScopeAttributes.VERSION_MAJOR]: '0', [NpmScopeAttributes.VERSION_MINOR]: '0', [NpmScopeAttributes.VERSION_PATCH]: '1', [NpmScopeAttributes.VERSION_PRE_RELEASE]: undefined, - [NpmScopeAttributes.INSTALLER_RAW]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_OWNER]: undefined, - [NpmScopeAttributes.INSTALLER_NAME]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: '1.0.0', - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: '1', - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: undefined + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'npm.dependency.raw', @@ -52,11 +54,11 @@ describe('class: DependencyMetric', () => { 'npm.dependency.name', 'npm.dependency.version.raw', 'npm.dependency.version.preRelease', - 'npm.dependency.installer.raw', - 'npm.dependency.installer.owner', - 'npm.dependency.installer.name', - 'npm.dependency.installer.version.raw', - 'npm.dependency.installer.version.preRelease' + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -67,10 +69,12 @@ describe('class: DependencyMetric', () => { { rawName: 'test-1', rawVersion: '0.0.1-rc.0', - installerRawName: 'test-1-installer', - installerRawVersion: '1.0.0-rc.4', isInstrumented: 'false' }, + { + name: 'test-1-instrumented', + version: '1.0.0-rc.4' + }, logger ).attributes expect(attributes).toStrictEqual( @@ -79,20 +83,20 @@ describe('class: DependencyMetric', () => { [NpmScopeAttributes.RAW]: 'test-1', [NpmScopeAttributes.OWNER]: undefined, [NpmScopeAttributes.NAME]: 'test-1', - [NpmScopeAttributes.INSTRUMENTED]: 'false', + [NpmScopeAttributes.IS_INSTRUMENTED]: 'false', [NpmScopeAttributes.VERSION_RAW]: '0.0.1-rc.0', [NpmScopeAttributes.VERSION_MAJOR]: '0', [NpmScopeAttributes.VERSION_MINOR]: '0', [NpmScopeAttributes.VERSION_PATCH]: '1', [NpmScopeAttributes.VERSION_PRE_RELEASE]: 'rc.0', - [NpmScopeAttributes.INSTALLER_RAW]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_OWNER]: undefined, - [NpmScopeAttributes.INSTALLER_NAME]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: '1.0.0-rc.4', - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: '1', - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: 'rc.4' + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0-rc.4', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: 'rc.4' }, [ 'npm.dependency.raw', @@ -100,11 +104,11 @@ describe('class: DependencyMetric', () => { 'npm.dependency.name', 'npm.dependency.version.raw', 'npm.dependency.version.preRelease', - 'npm.dependency.installer.raw', - 'npm.dependency.installer.owner', - 'npm.dependency.installer.name', - 'npm.dependency.installer.version.raw', - 'npm.dependency.installer.version.preRelease' + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -115,10 +119,12 @@ describe('class: DependencyMetric', () => { { rawName: 'test-1', rawVersion: '0.0.1+12345', - installerRawName: 'test-1-installer', - installerRawVersion: '1.0.0+9999', isInstrumented: 'false' }, + { + name: 'test-1-instrumented', + version: '1.0.0+9999' + }, logger ).attributes expect(attributes).toStrictEqual( @@ -127,20 +133,20 @@ describe('class: DependencyMetric', () => { [NpmScopeAttributes.RAW]: 'test-1', [NpmScopeAttributes.OWNER]: undefined, [NpmScopeAttributes.NAME]: 'test-1', - [NpmScopeAttributes.INSTRUMENTED]: 'false', + [NpmScopeAttributes.IS_INSTRUMENTED]: 'false', [NpmScopeAttributes.VERSION_RAW]: '0.0.1+12345', [NpmScopeAttributes.VERSION_MAJOR]: '0', [NpmScopeAttributes.VERSION_MINOR]: '0', [NpmScopeAttributes.VERSION_PATCH]: '1', [NpmScopeAttributes.VERSION_PRE_RELEASE]: undefined, - [NpmScopeAttributes.INSTALLER_RAW]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_OWNER]: undefined, - [NpmScopeAttributes.INSTALLER_NAME]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: '1.0.0+9999', - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: '1', - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: undefined + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0+9999', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'npm.dependency.raw', @@ -148,11 +154,11 @@ describe('class: DependencyMetric', () => { 'npm.dependency.name', 'npm.dependency.version.raw', 'npm.dependency.version.preRelease', - 'npm.dependency.installer.raw', - 'npm.dependency.installer.owner', - 'npm.dependency.installer.name', - 'npm.dependency.installer.version.raw', - 'npm.dependency.installer.version.preRelease' + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -163,10 +169,12 @@ describe('class: DependencyMetric', () => { { rawName: 'test-1', rawVersion: '0.0.1-rc.1+12345', - installerRawName: 'test-1-installer', - installerRawVersion: '1.0.0-rc.0+9999', isInstrumented: 'false' }, + { + name: 'test-1-instrumented', + version: '1.0.0-rc.0+9999' + }, logger ).attributes @@ -176,20 +184,20 @@ describe('class: DependencyMetric', () => { [NpmScopeAttributes.RAW]: 'test-1', [NpmScopeAttributes.OWNER]: undefined, [NpmScopeAttributes.NAME]: 'test-1', - [NpmScopeAttributes.INSTRUMENTED]: 'false', + [NpmScopeAttributes.IS_INSTRUMENTED]: 'false', [NpmScopeAttributes.VERSION_RAW]: '0.0.1-rc.1+12345', [NpmScopeAttributes.VERSION_MAJOR]: '0', [NpmScopeAttributes.VERSION_MINOR]: '0', [NpmScopeAttributes.VERSION_PATCH]: '1', [NpmScopeAttributes.VERSION_PRE_RELEASE]: 'rc.1', - [NpmScopeAttributes.INSTALLER_RAW]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_OWNER]: undefined, - [NpmScopeAttributes.INSTALLER_NAME]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: '1.0.0-rc.0+9999', - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: '1', - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: 'rc.0' + [NpmScopeAttributes.INSTRUMENTED_RAW]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: undefined, + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0-rc.0+9999', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: 'rc.0' }, [ 'npm.dependency.raw', @@ -197,11 +205,11 @@ describe('class: DependencyMetric', () => { 'npm.dependency.name', 'npm.dependency.version.raw', 'npm.dependency.version.preRelease', - 'npm.dependency.installer.raw', - 'npm.dependency.installer.owner', - 'npm.dependency.installer.name', - 'npm.dependency.installer.version.raw', - 'npm.dependency.installer.version.preRelease' + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -212,10 +220,12 @@ describe('class: DependencyMetric', () => { { rawName: '@owner/test-1', rawVersion: '0.0.1-rc.0+12345', - installerRawName: '@installer/test-1-installer', - installerRawVersion: '1.0.0', isInstrumented: 'false' }, + { + name: '@instrumented/test-1-instrumented', + version: '1.0.0' + }, logger ).attributes @@ -225,20 +235,20 @@ describe('class: DependencyMetric', () => { [NpmScopeAttributes.RAW]: '@owner/test-1', [NpmScopeAttributes.OWNER]: '@owner', [NpmScopeAttributes.NAME]: 'test-1', - [NpmScopeAttributes.INSTRUMENTED]: 'false', + [NpmScopeAttributes.IS_INSTRUMENTED]: 'false', [NpmScopeAttributes.VERSION_RAW]: '0.0.1-rc.0+12345', [NpmScopeAttributes.VERSION_MAJOR]: '0', [NpmScopeAttributes.VERSION_MINOR]: '0', [NpmScopeAttributes.VERSION_PATCH]: '1', [NpmScopeAttributes.VERSION_PRE_RELEASE]: 'rc.0', - [NpmScopeAttributes.INSTALLER_RAW]: '@installer/test-1-installer', - [NpmScopeAttributes.INSTALLER_OWNER]: '@installer', - [NpmScopeAttributes.INSTALLER_NAME]: 'test-1-installer', - [NpmScopeAttributes.INSTALLER_VERSION_RAW]: '1.0.0', - [NpmScopeAttributes.INSTALLER_VERSION_MAJOR]: '1', - [NpmScopeAttributes.INSTALLER_VERSION_MINOR]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PATCH]: '0', - [NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]: undefined + [NpmScopeAttributes.INSTRUMENTED_RAW]: '@instrumented/test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_OWNER]: '@instrumented', + [NpmScopeAttributes.INSTRUMENTED_NAME]: 'test-1-instrumented', + [NpmScopeAttributes.INSTRUMENTED_VERSION_RAW]: '1.0.0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MAJOR]: '1', + [NpmScopeAttributes.INSTRUMENTED_VERSION_MINOR]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PATCH]: '0', + [NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]: undefined }, [ 'npm.dependency.raw', @@ -246,11 +256,11 @@ describe('class: DependencyMetric', () => { 'npm.dependency.name', 'npm.dependency.version.raw', 'npm.dependency.version.preRelease', - 'npm.dependency.installer.raw', - 'npm.dependency.installer.owner', - 'npm.dependency.installer.name', - 'npm.dependency.installer.version.raw', - 'npm.dependency.installer.version.preRelease' + 'npm.dependency.instrumented.raw', + 'npm.dependency.instrumented.owner', + 'npm.dependency.instrumented.name', + 'npm.dependency.instrumented.version.raw', + 'npm.dependency.instrumented.version.preRelease' ] ) ) @@ -261,14 +271,16 @@ describe('class: DependencyMetric', () => { { rawName: '@owner/test-1', rawVersion: '0.0.1+12345', - installerRawName: '@installer/test-1-installer', - installerRawVersion: '1.0.0+123456', isInstrumented: 'false' }, + { + name: '@instrumented/test-1-instrumented', + version: '1.0.0+123456' + }, logger ).attributes expect(attributes[NpmScopeAttributes.VERSION_PRE_RELEASE]).toBeUndefined() - expect(attributes[NpmScopeAttributes.INSTALLER_VERSION_PRE_RELEASE]).toBeUndefined() + expect(attributes[NpmScopeAttributes.INSTRUMENTED_VERSION_PRE_RELEASE]).toBeUndefined() }) })