Skip to content

Commit 2ade5ae

Browse files
authored
chore: align config constructor pattern across instrumentations (#2162)
* chore: align config constructor pattern across instrumentations * fix: unused import * revert: remove diag patch message * fix: align config pattern for mongoose and koa * fix: apply common config handling in setConfig
1 parent e74cee4 commit 2ade5ae

File tree

32 files changed

+52
-71
lines changed

32 files changed

+52
-71
lines changed

plugins/node/instrumentation-amqplib/src/amqplib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import { VERSION } from './version';
7777
export class AmqplibInstrumentation extends InstrumentationBase {
7878
protected override _config!: AmqplibInstrumentationConfig;
7979

80-
constructor(config?: AmqplibInstrumentationConfig) {
80+
constructor(config: AmqplibInstrumentationConfig = {}) {
8181
super(
8282
'@opentelemetry/instrumentation-amqplib',
8383
VERSION,

plugins/node/instrumentation-dataloader/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class DataloaderInstrumentation extends InstrumentationBase {
7676
return this._config;
7777
}
7878

79-
override setConfig(config: DataloaderInstrumentationConfig) {
79+
override setConfig(config: DataloaderInstrumentationConfig = {}) {
8080
this._config = config;
8181
}
8282

plugins/node/instrumentation-fs/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function patchedFunctionWithOriginalProperties<
5252
}
5353

5454
export default class FsInstrumentation extends InstrumentationBase {
55-
constructor(config?: FsInstrumentationConfig) {
55+
constructor(config: FsInstrumentationConfig = {}) {
5656
super('@opentelemetry/instrumentation-fs', VERSION, config);
5757
}
5858

plugins/node/instrumentation-lru-memoizer/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import { VERSION } from './version';
2424

2525
export default class LruMemoizerInstrumentation extends InstrumentationBase {
26-
constructor(config?: InstrumentationConfig) {
26+
constructor(config: InstrumentationConfig = {}) {
2727
super('@opentelemetry/instrumentation-lru-memoizer', VERSION, config);
2828
}
2929

plugins/node/instrumentation-mongoose/src/mongoose.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ export class MongooseInstrumentation extends InstrumentationBase {
6161
protected override _config!: MongooseInstrumentationConfig;
6262

6363
constructor(config: MongooseInstrumentationConfig = {}) {
64-
super(
65-
'@opentelemetry/instrumentation-mongoose',
66-
VERSION,
67-
Object.assign({}, config)
68-
);
64+
super('@opentelemetry/instrumentation-mongoose', VERSION, config);
6965
}
7066

7167
override setConfig(config: MongooseInstrumentationConfig = {}) {

plugins/node/instrumentation-tedious/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function setDatabase(this: ApproxConnection, databaseName: string) {
7070
export class TediousInstrumentation extends InstrumentationBase {
7171
static readonly COMPONENT = 'tedious';
7272

73-
constructor(config?: TediousInstrumentationConfig) {
73+
constructor(config: TediousInstrumentationConfig = {}) {
7474
super('@opentelemetry/instrumentation-tedious', VERSION, config);
7575
}
7676

plugins/node/instrumentation-undici/src/undici.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class UndiciInstrumentation extends InstrumentationBase {
6666
private _recordFromReq = new WeakMap<UndiciRequest, InstrumentationRecord>();
6767

6868
private _httpClientDurationHistogram!: Histogram;
69-
constructor(config?: UndiciInstrumentationConfig) {
69+
constructor(config: UndiciInstrumentationConfig = {}) {
7070
super('@opentelemetry/instrumentation-undici', VERSION, config);
7171
this.setConfig(config);
7272
}
@@ -111,7 +111,7 @@ export class UndiciInstrumentation extends InstrumentationBase {
111111
this.subscribeToChannel('undici:request:error', this.onError.bind(this));
112112
}
113113

114-
override setConfig(config?: UndiciInstrumentationConfig): void {
114+
override setConfig(config: UndiciInstrumentationConfig = {}): void {
115115
super.setConfig(config);
116116

117117
if (config?.enabled) {

plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
7777
private _traceForceFlusher?: () => Promise<void>;
7878
private _metricForceFlusher?: () => Promise<void>;
7979

80-
constructor(protected override _config: AwsLambdaInstrumentationConfig = {}) {
81-
super('@opentelemetry/instrumentation-aws-lambda', VERSION, _config);
80+
protected override _config!: AwsLambdaInstrumentationConfig;
81+
82+
constructor(config: AwsLambdaInstrumentationConfig = {}) {
83+
super('@opentelemetry/instrumentation-aws-lambda', VERSION, config);
8284
if (this._config.disableAwsContextPropagation == null) {
8385
if (
8486
typeof env['OTEL_LAMBDA_DISABLE_AWS_CONTEXT_PROPAGATION'] ===

plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ export class AwsInstrumentation extends InstrumentationBase {
7878
private servicesExtensions: ServicesExtensions = new ServicesExtensions();
7979

8080
constructor(config: AwsSdkInstrumentationConfig = {}) {
81-
super(
82-
'@opentelemetry/instrumentation-aws-sdk',
83-
VERSION,
84-
Object.assign({}, config)
85-
);
81+
super('@opentelemetry/instrumentation-aws-sdk', VERSION, config);
8682
}
8783

8884
override setConfig(config: AwsSdkInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class BunyanInstrumentation extends InstrumentationBase {
103103
return this._config;
104104
}
105105

106-
override setConfig(config: BunyanInstrumentationConfig) {
106+
override setConfig(config: BunyanInstrumentationConfig = {}) {
107107
this._config = Object.assign({}, DEFAULT_CONFIG, config);
108108
}
109109

plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ export const ANONYMOUS_NAME = 'anonymous';
4343
/** Connect instrumentation for OpenTelemetry */
4444
export class ConnectInstrumentation extends InstrumentationBase {
4545
constructor(config: InstrumentationConfig = {}) {
46-
super(
47-
'@opentelemetry/instrumentation-connect',
48-
VERSION,
49-
Object.assign({}, config)
50-
);
46+
super('@opentelemetry/instrumentation-connect', VERSION, config);
5147
}
5248

5349
init() {

plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ import {
3737
* Dns instrumentation for Opentelemetry
3838
*/
3939
export class DnsInstrumentation extends InstrumentationBase {
40-
constructor(protected override _config: DnsInstrumentationConfig = {}) {
41-
super('@opentelemetry/instrumentation-dns', VERSION, _config);
40+
protected override _config!: DnsInstrumentationConfig;
41+
42+
constructor(config: DnsInstrumentationConfig = {}) {
43+
super('@opentelemetry/instrumentation-dns', VERSION, config);
4244
}
4345

4446
init(): (

plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ import {
5151
/** Express instrumentation for OpenTelemetry */
5252
export class ExpressInstrumentation extends InstrumentationBase {
5353
constructor(config: ExpressInstrumentationConfig = {}) {
54-
super(
55-
'@opentelemetry/instrumentation-express',
56-
VERSION,
57-
Object.assign({}, config)
58-
);
54+
super('@opentelemetry/instrumentation-express', VERSION, config);
5955
}
6056

6157
override setConfig(config: ExpressInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ export const ANONYMOUS_NAME = 'anonymous';
4848
/** Fastify instrumentation for OpenTelemetry */
4949
export class FastifyInstrumentation extends InstrumentationBase {
5050
constructor(config: FastifyInstrumentationConfig = {}) {
51-
super(
52-
'@opentelemetry/instrumentation-fastify',
53-
VERSION,
54-
Object.assign({}, config)
55-
);
51+
super('@opentelemetry/instrumentation-fastify', VERSION, config);
5652
}
5753

5854
override setConfig(config: FastifyInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-generic-pool/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class Instrumentation extends InstrumentationBase {
3333
private _isDisabled = false;
3434

3535
constructor(config: InstrumentationConfig = {}) {
36-
super(`@opentelemetry/instrumentation-${MODULE_NAME}`, VERSION);
36+
super(`@opentelemetry/instrumentation-${MODULE_NAME}`, VERSION, config);
3737
}
3838

3939
init() {

plugins/node/opentelemetry-instrumentation-graphql/src/instrumentation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { context, trace } from '@opentelemetry/api';
1818
import {
1919
isWrapped,
2020
InstrumentationBase,
21-
InstrumentationConfig,
2221
InstrumentationNodeModuleDefinition,
2322
InstrumentationNodeModuleFile,
2423
safeExecuteInTheMiddle,
@@ -65,9 +64,7 @@ const DEFAULT_CONFIG: GraphQLInstrumentationConfig = {
6564
const supportedVersions = ['>=14 <17'];
6665

6766
export class GraphQLInstrumentation extends InstrumentationBase {
68-
constructor(
69-
config: GraphQLInstrumentationConfig & InstrumentationConfig = {}
70-
) {
67+
constructor(config: GraphQLInstrumentationConfig = {}) {
7168
super(
7269
'@opentelemetry/instrumentation-graphql',
7370
VERSION,

plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949

5050
/** Hapi instrumentation for OpenTelemetry */
5151
export class HapiInstrumentation extends InstrumentationBase {
52-
constructor(config?: InstrumentationConfig) {
52+
constructor(config: InstrumentationConfig = {}) {
5353
super('@opentelemetry/instrumentation-hapi', VERSION, config);
5454
}
5555

plugins/node/opentelemetry-instrumentation-ioredis/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ const DEFAULT_CONFIG: IORedisInstrumentationConfig = {
3636
};
3737

3838
export class IORedisInstrumentation extends InstrumentationBase {
39-
constructor(_config: IORedisInstrumentationConfig = {}) {
39+
protected override _config!: IORedisInstrumentationConfig;
40+
41+
constructor(config: IORedisInstrumentationConfig = {}) {
4042
super(
4143
'@opentelemetry/instrumentation-ioredis',
4244
VERSION,
43-
Object.assign({}, DEFAULT_CONFIG, _config)
45+
Object.assign({}, DEFAULT_CONFIG, config)
4446
);
4547
}
4648

plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ import {
3636
/** Koa instrumentation for OpenTelemetry */
3737
export class KoaInstrumentation extends InstrumentationBase {
3838
constructor(config: KoaInstrumentationConfig = {}) {
39-
super(
40-
'@opentelemetry/instrumentation-koa',
41-
VERSION,
42-
Object.assign({}, config)
43-
);
39+
super('@opentelemetry/instrumentation-koa', VERSION, config);
4440
}
4541

4642
override setConfig(config: KoaInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export class MongoDBInstrumentation extends InstrumentationBase {
5858
private _connectionsUsage!: UpDownCounter;
5959
private _poolName!: string;
6060

61-
constructor(protected override _config: MongoDBInstrumentationConfig = {}) {
62-
super('@opentelemetry/instrumentation-mongodb', VERSION, _config);
61+
protected override _config!: MongoDBInstrumentationConfig;
62+
63+
constructor(config: MongoDBInstrumentationConfig = {}) {
64+
super('@opentelemetry/instrumentation-mongodb', VERSION, config);
6365
}
6466

6567
override _updateMetricInstruments() {

plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class MySQLInstrumentation extends InstrumentationBase {
5757
};
5858
private _connectionsUsage!: UpDownCounter;
5959

60-
constructor(config?: MySQLInstrumentationConfig) {
60+
constructor(config: MySQLInstrumentationConfig = {}) {
6161
super('@opentelemetry/instrumentation-mysql', VERSION, config);
6262
this._setMetricInstruments();
6363
}

plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class MySQL2Instrumentation extends InstrumentationBase {
4444
[SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MYSQL,
4545
};
4646

47-
constructor(config?: MySQL2InstrumentationConfig) {
47+
constructor(config: MySQL2InstrumentationConfig = {}) {
4848
super('@opentelemetry/instrumentation-mysql2', VERSION, config);
4949
}
5050

plugins/node/opentelemetry-instrumentation-nestjs-core/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Instrumentation extends InstrumentationBase {
3636
};
3737

3838
constructor(config: InstrumentationConfig = {}) {
39-
super('@opentelemetry/instrumentation-nestjs-core', VERSION);
39+
super('@opentelemetry/instrumentation-nestjs-core', VERSION, config);
4040
}
4141

4242
init() {

plugins/node/opentelemetry-instrumentation-net/src/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import { TLSSocket } from 'tls';
3535
import type * as net from 'net';
3636

3737
export class NetInstrumentation extends InstrumentationBase {
38-
constructor(_config?: InstrumentationConfig) {
39-
super('@opentelemetry/instrumentation-net', VERSION, _config);
38+
constructor(config: InstrumentationConfig = {}) {
39+
super('@opentelemetry/instrumentation-net', VERSION, config);
4040
}
4141

4242
init(): InstrumentationNodeModuleDefinition[] {

plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ import { SpanNames } from './enums/SpanNames';
4444

4545
export class PgInstrumentation extends InstrumentationBase {
4646
constructor(config: PgInstrumentationConfig = {}) {
47-
super(
48-
'@opentelemetry/instrumentation-pg',
49-
VERSION,
50-
Object.assign({}, config)
51-
);
47+
super('@opentelemetry/instrumentation-pg', VERSION, config);
5248
}
5349

5450
protected init() {

plugins/node/opentelemetry-instrumentation-pino/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class PinoInstrumentation extends InstrumentationBase {
9797
return this._config;
9898
}
9999

100-
override setConfig(config: PinoInstrumentationConfig) {
100+
override setConfig(config: PinoInstrumentationConfig = {}) {
101101
this._config = config;
102102
}
103103

plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ const DEFAULT_CONFIG: RedisInstrumentationConfig = {
5454
export class RedisInstrumentation extends InstrumentationBase {
5555
static readonly COMPONENT = 'redis';
5656

57-
constructor(protected override _config: RedisInstrumentationConfig = {}) {
58-
super('@opentelemetry/instrumentation-redis-4', VERSION, _config);
57+
protected override _config!: RedisInstrumentationConfig;
58+
59+
constructor(config: RedisInstrumentationConfig = {}) {
60+
super('@opentelemetry/instrumentation-redis-4', VERSION, config);
5961
}
6062

6163
override setConfig(config: RedisInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-redis/src/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ const DEFAULT_CONFIG: RedisInstrumentationConfig = {
3535
export class RedisInstrumentation extends InstrumentationBase {
3636
static readonly COMPONENT = 'redis';
3737

38-
constructor(protected override _config: RedisInstrumentationConfig = {}) {
39-
super('@opentelemetry/instrumentation-redis', VERSION, _config);
38+
protected override _config!: RedisInstrumentationConfig;
39+
40+
constructor(config: RedisInstrumentationConfig = {}) {
41+
super('@opentelemetry/instrumentation-redis', VERSION, config);
4042
}
4143

4244
override setConfig(config: RedisInstrumentationConfig = {}) {

plugins/node/opentelemetry-instrumentation-restify/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class RestifyInstrumentation extends InstrumentationBase {
4040
super(
4141
`@opentelemetry/instrumentation-${constants.MODULE_NAME}`,
4242
VERSION,
43-
Object.assign({}, config)
43+
config
4444
);
4545
}
4646

plugins/node/opentelemetry-instrumentation-router/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import AttributeNames from './enums/AttributeNames';
3535
import LayerType from './enums/LayerType';
3636

3737
export default class RouterInstrumentation extends InstrumentationBase {
38-
constructor(config?: InstrumentationConfig) {
38+
constructor(config: InstrumentationConfig = {}) {
3939
super(
4040
`@opentelemetry/instrumentation-${constants.MODULE_NAME}`,
4141
VERSION,

plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class WinstonInstrumentation extends InstrumentationBase {
116116
return this._config;
117117
}
118118

119-
override setConfig(config: WinstonInstrumentationConfig) {
119+
override setConfig(config: WinstonInstrumentationConfig = {}) {
120120
this._config = config;
121121
}
122122

plugins/web/opentelemetry-instrumentation-user-interaction/src/instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase {
6767
private _eventNames: Set<EventName>;
6868
private _shouldPreventSpanCreation: ShouldPreventSpanCreation;
6969

70-
constructor(config?: UserInteractionInstrumentationConfig) {
70+
constructor(config: UserInteractionInstrumentationConfig = {}) {
7171
super('@opentelemetry/instrumentation-user-interaction', VERSION, config);
7272
this._eventNames = new Set(config?.eventNames ?? DEFAULT_EVENT_NAMES);
7373
this._shouldPreventSpanCreation =

0 commit comments

Comments
 (0)