Skip to content

Commit

Permalink
chore: add 'lint:deps' script to check for unused and unlisted deps (#…
Browse files Browse the repository at this point in the history
…2477)

This uses knip (https://knip.dev) to check dependencies, in hopes of avoiding
issues like #2473. This adds 'npm run lint:deps' and adds that to the
existing 'npm run lint'.

This change includes fixes for a handful of unused and unlisted deps.
For now knip is configured to only check 'production' deps. Checking non-prod
deps results in way too many false positives.

Note that knip is being run via `npx` rather than installing as a devDep because
there is a conflict: knip deps on typescript@5 and all packaegs in this repo
currently use [email protected]. Installing knip at the top-level results in a
ballooning of the node_modules install size as [email protected] is installed
40+ types in all separate workspaces.
  • Loading branch information
trentm authored Oct 24, 2024
1 parent 2822511 commit 9b43ccb
Show file tree
Hide file tree
Showing 58 changed files with 86 additions and 47 deletions.
11 changes: 11 additions & 0 deletions knip.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://knip.dev/reference/configuration
{
"$schema": "https://unpkg.com/knip@5/schema-jsonc.json",
"workspaces": {
"metapackages/auto-instrumentations-node": {
// Ensure register.ts is considered an entry-point (the `!` is to be
// included with the `--production` flag).
"entry": "src/register.ts!"
}
}
}
51 changes: 16 additions & 35 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"test-all-versions": "npm run --if-present --workspaces test-all-versions",
"bump": "lerna publish",
"changelog": "lerna-changelog",
"lint": "lerna run lint && npm run lint:readme && npm run lint:markdown",
"lint": "lerna run lint && npm run lint:deps && npm run lint:readme && npm run lint:markdown",
"lint:fix": "lerna run lint:fix && npm run lint:markdown:fix",
"lint:deps": "npx --yes [email protected] --dependencies --production --tags=-knipignore",
"lint:examples": "eslint ./examples/**/*.js",
"lint:examples:fix": "eslint ./examples/**/*.js --fix",
"lint:markdown": "markdownlint-cli2 $(git ls-files '*.md')",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-host-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/sdk-metrics": "^1.8.0",
"@types/mocha": "8.2.3",
"@types/node": "18.18.14",
"@types/sinon": "10.0.20",
Expand All @@ -53,7 +54,6 @@
"typescript": "4.4.4"
},
"dependencies": {
"@opentelemetry/sdk-metrics": "^1.8.0",
"systeminformation": "5.22.9"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/opentelemetry-host-metrics#readme"
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { Meter, MeterProvider, diag, metrics } from '@opentelemetry/api';

/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/exporter-jaeger": "^1.3.1",
"@opentelemetry/instrumentation": "^0.54.0",
"@opentelemetry/otlp-transformer": "^0.54.0",
"@opentelemetry/resources": "^1.8.0",
"@opentelemetry/sdk-metrics": "^1.27.0",
"@opentelemetry/sdk-node": "^0.54.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@opentelemetry/sdk-trace-node": "^1.8.0",
Expand Down
1 change: 1 addition & 0 deletions packages/winston-transport/src/OpenTelemetryTransportV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { Logger, logs } from '@opentelemetry/api-logs';
import TransportStream = require('winston-transport');
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { emitLogRecord } from './utils';

Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-amqplib/src/amqplib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
normalizeExchange,
unmarkConfirmChannelTracing,
} from './utils';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

const supportedVersions = ['>=0.5.5 <1'];
Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-cucumber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"devDependencies": {
"@cucumber/cucumber": "^9.0.0",
"@cucumber/messages": "^22.0.0",
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/core": "^1.3.1",
"@opentelemetry/sdk-trace-base": "^1.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
} from '@cucumber/cucumber/lib/support_code_library_builder/types';

import { AttributeNames, CucumberInstrumentationConfig } from './types';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

const hooks = ['Before', 'BeforeStep', 'AfterStep', 'After'] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SpanKind,
} from '@opentelemetry/api';
import { DataloaderInstrumentationConfig } from './types';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import type * as Dataloader from 'dataloader';

Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-fs/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
InstrumentationNodeModuleDefinition,
isWrapped,
} from '@opentelemetry/instrumentation';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import {
CALLBACK_FUNCTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
Consumer,
} from 'kafkajs';
import { KafkaJsInstrumentationConfig } from './types';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { bufferTextMapGetter } from './propagator';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
InstrumentationConfig,
InstrumentationNodeModuleDefinition,
} from '@opentelemetry/instrumentation';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

export class LruMemoizerInstrumentation extends InstrumentationBase {
Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-mongoose/src/mongoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InstrumentationModuleDefinition,
InstrumentationNodeModuleDefinition,
} from '@opentelemetry/instrumentation';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import {
SEMATTRS_DB_OPERATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { eventLoopUtilization } = performance;

import { InstrumentationBase } from '@opentelemetry/instrumentation';

/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { RuntimeNodeInstrumentationConfig } from './types';

Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-socket.io/src/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from '@opentelemetry/semantic-conventions';
import { SocketIoInstrumentationConfig } from './types';
import { SocketIoInstrumentationAttributes } from './AttributeNames';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import {
extractRoomsAttributeValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import type * as tedious from 'tedious';
import { TediousInstrumentationConfig } from './types';
import { getSpanName, once } from './utils';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

const CURRENT_DATABASE = Symbol(
Expand Down
1 change: 1 addition & 0 deletions plugins/node/instrumentation-undici/src/undici.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ValueType,
} from '@opentelemetry/api';

/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"dependencies": {
"@opentelemetry/instrumentation": "^0.54.0",
"@opentelemetry/propagator-aws-xray": "^1.3.1",
"@opentelemetry/resources": "^1.8.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
"@types/aws-lambda": "8.10.143"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
} from 'aws-lambda';

import { AwsLambdaInstrumentationConfig, EventContextExtractor } from './types';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import { env } from 'process';
import { LambdaModule } from './internal-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
NormalizedRequest,
NormalizedResponse,
} from './types';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';
import {
InstrumentationBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { logs, SeverityNumber, Logger } from '@opentelemetry/api-logs';
import type { LogLevelString } from 'bunyan';
/** @knipignore */
import { PACKAGE_NAME, PACKAGE_VERSION } from './version';

const DEFAULT_INSTRUMENTATION_SCOPE_NAME = PACKAGE_NAME;
Expand Down
Loading

0 comments on commit 9b43ccb

Please sign in to comment.