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

0 commit comments

Comments
 (0)