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(nodejs): add ability to be able to enable/disable active instrumentations by env var #1653

Merged
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
168 changes: 118 additions & 50 deletions nodejs/packages/layer/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,21 @@ import {
} from '@opentelemetry/sdk-logs';
import { logs } from '@opentelemetry/api-logs';

function defaultConfigureInstrumentations() {
// Use require statements for instrumentation
// to avoid having to have transitive dependencies on all the typescript definitions.
const { DnsInstrumentation } = require('@opentelemetry/instrumentation-dns');
const {
ExpressInstrumentation,
} = require('@opentelemetry/instrumentation-express');
const {
GraphQLInstrumentation,
} = require('@opentelemetry/instrumentation-graphql');
const {
GrpcInstrumentation,
} = require('@opentelemetry/instrumentation-grpc');
const {
HapiInstrumentation,
} = require('@opentelemetry/instrumentation-hapi');
const {
HttpInstrumentation,
} = require('@opentelemetry/instrumentation-http');
const {
IORedisInstrumentation,
} = require('@opentelemetry/instrumentation-ioredis');
const { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa');
const {
MongoDBInstrumentation,
} = require('@opentelemetry/instrumentation-mongodb');
const {
MySQLInstrumentation,
} = require('@opentelemetry/instrumentation-mysql');
const { NetInstrumentation } = require('@opentelemetry/instrumentation-net');
const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');
const {
RedisInstrumentation,
} = require('@opentelemetry/instrumentation-redis');
return [
new DnsInstrumentation(),
new ExpressInstrumentation(),
new GraphQLInstrumentation(),
new GrpcInstrumentation(),
new HapiInstrumentation(),
new HttpInstrumentation(),
new IORedisInstrumentation(),
new KoaInstrumentation(),
new MongoDBInstrumentation(),
new MySQLInstrumentation(),
new NetInstrumentation(),
new PgInstrumentation(),
new RedisInstrumentation(),
];
}
const defaultInstrumentationList = [
'dns',
'express',
'graphql',
'grpc',
'hapi',
'http',
'ioredis',
'koa',
'mongodb',
'mysql',
'net',
'pg',
'redis',
];

declare global {
// In case of downstream configuring span processors etc
Expand All @@ -126,6 +91,109 @@ declare global {
function configureInstrumentations(): Instrumentation[];
}

function getActiveInstumentations(): Set<string> {
let enabledInstrumentations: string[] = defaultInstrumentationList;
if (process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS) {
enabledInstrumentations =
process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS.split(',').map(i =>
i.trim(),
);
}
const instrumentationSet = new Set<string>(enabledInstrumentations);
if (process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS) {
const disableInstrumentations =
process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS.split(',').map(i =>
i.trim(),
);
disableInstrumentations.forEach(di => instrumentationSet.delete(di));
}
return instrumentationSet;
}

function defaultConfigureInstrumentations() {
const instrumentations = [];
const activeInstrumentations = getActiveInstumentations();
// Use require statements for instrumentation
// to avoid having to have transitive dependencies on all the typescript definitions.
if (activeInstrumentations.has('dns')) {
const {
DnsInstrumentation,
} = require('@opentelemetry/instrumentation-dns');
instrumentations.push(new DnsInstrumentation());
}
if (activeInstrumentations.has('express')) {
const {
ExpressInstrumentation,
} = require('@opentelemetry/instrumentation-express');
instrumentations.push(new ExpressInstrumentation());
}
if (activeInstrumentations.has('graphql')) {
const {
GraphQLInstrumentation,
} = require('@opentelemetry/instrumentation-graphql');
instrumentations.push(new GraphQLInstrumentation());
}
if (activeInstrumentations.has('grpc')) {
const {
GrpcInstrumentation,
} = require('@opentelemetry/instrumentation-grpc');
instrumentations.push(new GrpcInstrumentation());
}
if (activeInstrumentations.has('hapi')) {
const {
HapiInstrumentation,
} = require('@opentelemetry/instrumentation-hapi');
instrumentations.push(new HapiInstrumentation());
}
if (activeInstrumentations.has('http')) {
const {
HttpInstrumentation,
} = require('@opentelemetry/instrumentation-http');
instrumentations.push(new HttpInstrumentation());
}
if (activeInstrumentations.has('ioredis')) {
const {
IORedisInstrumentation,
} = require('@opentelemetry/instrumentation-ioredis');
instrumentations.push(new IORedisInstrumentation());
}
if (activeInstrumentations.has('koa')) {
const {
KoaInstrumentation,
} = require('@opentelemetry/instrumentation-koa');
instrumentations.push(new KoaInstrumentation());
}
if (activeInstrumentations.has('mongodb')) {
const {
MongoDBInstrumentation,
} = require('@opentelemetry/instrumentation-mongodb');
instrumentations.push(new MongoDBInstrumentation());
}
if (activeInstrumentations.has('mysql')) {
const {
MySQLInstrumentation,
} = require('@opentelemetry/instrumentation-mysql');
instrumentations.push(new MySQLInstrumentation());
}
if (activeInstrumentations.has('net')) {
const {
NetInstrumentation,
} = require('@opentelemetry/instrumentation-net');
instrumentations.push(new NetInstrumentation());
}
if (activeInstrumentations.has('pg')) {
const { PgInstrumentation } = require('@opentelemetry/instrumentation-pg');
instrumentations.push(new PgInstrumentation());
}
if (activeInstrumentations.has('redis')) {
const {
RedisInstrumentation,
} = require('@opentelemetry/instrumentation-redis');
instrumentations.push(new RedisInstrumentation());
}
return instrumentations;
}

function createInstrumentations() {
return [
new AwsInstrumentation(
Expand Down
Loading