Skip to content

Commit e624704

Browse files
authored
Merge branch 'main' into ver020
2 parents b643231 + eb9353a commit e624704

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

packages/opentelemetry-instrumentation/src/instrumentation.ts

+13
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ export abstract class InstrumentationAbstract<T = any>
7070
);
7171
}
7272

73+
/* Returns InstrumentationConfig */
74+
public getConfig() {
75+
return this._config;
76+
}
77+
78+
/**
79+
* Sets InstrumentationConfig to this plugin
80+
* @param InstrumentationConfig
81+
*/
82+
public setConfig(config: types.InstrumentationConfig = {}) {
83+
this._config = Object.assign({}, config);
84+
}
85+
7386
/**
7487
* Sets TraceProvider to this plugin
7588
* @param tracerProvider

packages/opentelemetry-instrumentation/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export interface Instrumentation {
4444
/** Method to set meter provider */
4545
setMeterProvider(meterProvider: MeterProvider): void;
4646

47+
/** Method to set instrumentation config */
48+
setConfig(config: InstrumentationConfig): void;
49+
50+
/** Method to get instrumentation config */
51+
getConfig(): InstrumentationConfig;
52+
4753
/**
4854
* Contains all supported versions.
4955
* All versions must be compatible with [semver](https://semver.org/spec/v2.0.0.html) format.

packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts

+36-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515
*/
1616

1717
import * as assert from 'assert';
18-
import { Instrumentation, InstrumentationBase } from '../../src';
18+
import {
19+
Instrumentation,
20+
InstrumentationBase,
21+
InstrumentationConfig,
22+
} from '../../src';
23+
24+
interface TestInstrumentationConfig extends InstrumentationConfig {
25+
isActive?: boolean;
26+
}
1927

2028
class TestInstrumentation extends InstrumentationBase {
21-
constructor() {
22-
super('test', '1.0.0');
29+
constructor(config: TestInstrumentationConfig & InstrumentationConfig = {}) {
30+
super('test', '1.0.0', Object.assign({}, config));
2331
}
2432
enable() {}
2533
disable() {}
@@ -56,4 +64,29 @@ describe('BaseInstrumentation', () => {
5664
assert.strictEqual(called, true);
5765
});
5866
});
67+
68+
describe('getConfig', () => {
69+
it('should return instrumentation config', () => {
70+
const instrumentation: Instrumentation = new TestInstrumentation({
71+
isActive: false,
72+
});
73+
const configuration =
74+
instrumentation.getConfig() as TestInstrumentationConfig;
75+
assert.notStrictEqual(configuration, null);
76+
assert.strictEqual(configuration.isActive, false);
77+
});
78+
});
79+
80+
describe('setConfig', () => {
81+
it('should set a new config for instrumentation', () => {
82+
const instrumentation: Instrumentation = new TestInstrumentation();
83+
const config: TestInstrumentationConfig = {
84+
isActive: true,
85+
};
86+
instrumentation.setConfig(config);
87+
const configuration =
88+
instrumentation.getConfig() as TestInstrumentationConfig;
89+
assert.strictEqual(configuration.isActive, true);
90+
});
91+
});
5992
});

0 commit comments

Comments
 (0)