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

feat: add new instrumentations into auto-instrumentations-node #981

Merged
merged 12 commits into from
Sep 30, 2022
Merged
3 changes: 3 additions & 0 deletions metapackages/auto-instrumentations-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@opentelemetry/instrumentation-dataloader": "^0.2.0",
"@opentelemetry/instrumentation-dns": "^0.30.0",
"@opentelemetry/instrumentation-express": "^0.31.2",
"@opentelemetry/instrumentation-fs": "^0.5.0",
"@opentelemetry/instrumentation-fastify": "^0.30.0",
"@opentelemetry/instrumentation-generic-pool": "^0.30.0",
"@opentelemetry/instrumentation-graphql": "^0.31.0",
Expand All @@ -78,6 +79,8 @@
"@opentelemetry/instrumentation-redis": "^0.33.0",
"@opentelemetry/instrumentation-redis-4": "^0.33.0",
"@opentelemetry/instrumentation-restify": "^0.30.0",
"@opentelemetry/instrumentation-router": "^0.30.0",
"@opentelemetry/instrumentation-tedious": "^0.4.0",
"@opentelemetry/instrumentation-winston": "^0.30.0"
}
}
7 changes: 7 additions & 0 deletions metapackages/auto-instrumentations-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { diag } from '@opentelemetry/api';
import { Instrumentation } from '@opentelemetry/instrumentation';

import { AmqplibInstrumentation } from '@opentelemetry/instrumentation-amqplib';
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
Expand All @@ -26,6 +27,7 @@ import { DataloaderInstrumentation } from '@opentelemetry/instrumentation-datalo
import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
import { FsInstrumentation } from '@opentelemetry/instrumentation-fs';
import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool';
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
import { GrpcInstrumentation } from '@opentelemetry/instrumentation-grpc';
Expand All @@ -47,6 +49,8 @@ import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
import { RedisInstrumentation as RedisInstrumentationV2 } from '@opentelemetry/instrumentation-redis';
import { RedisInstrumentation as RedisInstrumentationV4 } from '@opentelemetry/instrumentation-redis-4';
import { RestifyInstrumentation } from '@opentelemetry/instrumentation-restify';
import { RouterInstrumentation } from '@opentelemetry/instrumentation-router';
import { TediousInstrumentation } from '@opentelemetry/instrumentation-tedious';
import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';

const InstrumentationMap = {
Expand All @@ -61,6 +65,7 @@ const InstrumentationMap = {
'@opentelemetry/instrumentation-dns': DnsInstrumentation,
'@opentelemetry/instrumentation-express': ExpressInstrumentation,
'@opentelemetry/instrumentation-fastify': FastifyInstrumentation,
'@opentelemetry/instrumentation-fs': FsInstrumentation,
'@opentelemetry/instrumentation-generic-pool': GenericPoolInstrumentation,
'@opentelemetry/instrumentation-graphql': GraphQLInstrumentation,
'@opentelemetry/instrumentation-grpc': GrpcInstrumentation,
Expand All @@ -82,6 +87,8 @@ const InstrumentationMap = {
'@opentelemetry/instrumentation-redis': RedisInstrumentationV2,
'@opentelemetry/instrumentation-redis-4': RedisInstrumentationV4,
'@opentelemetry/instrumentation-restify': RestifyInstrumentation,
'@opentelemetry/instrumentation-router': RouterInstrumentation,
'@opentelemetry/instrumentation-tedious': TediousInstrumentation,
'@opentelemetry/instrumentation-winston': WinstonInstrumentation,
};

Expand Down
54 changes: 11 additions & 43 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,18 @@ import { getNodeAutoInstrumentations } from '../src';

describe('utils', () => {
describe('getNodeAutoInstrumentations', () => {
it('should load default instrumentations', () => {
it('should include all installed instrumentations', () => {
const instrumentations = getNodeAutoInstrumentations();
const expectedInstrumentations = [
'@opentelemetry/instrumentation-amqplib',
'@opentelemetry/instrumentation-aws-lambda',
'@opentelemetry/instrumentation-aws-sdk',
'@opentelemetry/instrumentation-bunyan',
'@opentelemetry/instrumentation-cassandra-driver',
'@opentelemetry/instrumentation-connect',
'@opentelemetry/instrumentation-dataloader',
'@opentelemetry/instrumentation-dns',
'@opentelemetry/instrumentation-express',
'@opentelemetry/instrumentation-fastify',
'@opentelemetry/instrumentation-generic-pool',
'@opentelemetry/instrumentation-graphql',
'@opentelemetry/instrumentation-grpc',
'@opentelemetry/instrumentation-hapi',
'@opentelemetry/instrumentation-http',
'@opentelemetry/instrumentation-ioredis',
'@opentelemetry/instrumentation-knex',
'@opentelemetry/instrumentation-koa',
'@opentelemetry/instrumentation-lru-memoizer',
'@opentelemetry/instrumentation-memcached',
'@opentelemetry/instrumentation-mongodb',
'@opentelemetry/instrumentation-mongoose',
'@opentelemetry/instrumentation-mysql2',
'@opentelemetry/instrumentation-mysql',
'@opentelemetry/instrumentation-nestjs-core',
'@opentelemetry/instrumentation-net',
'@opentelemetry/instrumentation-pg',
'@opentelemetry/instrumentation-pino',
'@opentelemetry/instrumentation-redis',
'@opentelemetry/instrumentation-redis-4',
'@opentelemetry/instrumentation-restify',
'@opentelemetry/instrumentation-winston',
];
assert.strictEqual(instrumentations.length, 32);
for (let i = 0, j = instrumentations.length; i < j; i++) {
assert.strictEqual(
instrumentations[i].instrumentationName,
expectedInstrumentations[i],
`Instrumentation ${expectedInstrumentations[i]}, not loaded`
);
}
const installedInstrumentations = Object.keys(
require('../package.json').dependencies
).filter(depName => {
return depName.startsWith('@opentelemetry/instrumentation-');
});

assert.deepStrictEqual(
new Set(instrumentations.map(i => i.instrumentationName)),
new Set(installedInstrumentations)
);
});

it('should use user config', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import * as api from '@opentelemetry/api';
import {
InstrumentationConfig,
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
Expand All @@ -34,8 +35,12 @@ import AttributeNames from './enums/AttributeNames';
import LayerType from './enums/LayerType';

export default class RouterInstrumentation extends InstrumentationBase<any> {
constructor() {
super(`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, VERSION);
constructor(config?: InstrumentationConfig) {
super(
`@opentelemetry/instrumentation-${constants.MODULE_NAME}`,
VERSION,
config
);
}

private _moduleVersion?: string;
Expand Down