Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions packages/opentelemetry-instrumentation/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ export abstract class InstrumentationAbstract<T = any>
);
}

/* Returns InstrumentationConfig */
public getConfig() {
return this._config;
}

/**
* Sets InstrumentationConfig to this plugin
* @param InstrumentationConfig
*/
public setConfig(config: types.InstrumentationConfig = {}) {
this._config = Object.assign({}, config);
}

/**
* Sets TraceProvider to this plugin
* @param tracerProvider
Expand Down
6 changes: 6 additions & 0 deletions packages/opentelemetry-instrumentation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export interface Instrumentation {
/** Method to set meter provider */
setMeterProvider(meterProvider: MeterProvider): void;

/** Method to set instrumentation config */
setConfig(config: InstrumentationConfig): void;

/** Method to get instrumentation config */
getConfig(): InstrumentationConfig;

/**
* Contains all supported versions.
* All versions must be compatible with [semver](https://semver.org/spec/v2.0.0.html) format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
*/

import * as assert from 'assert';
import { Instrumentation, InstrumentationBase } from '../../src';
import {
Instrumentation,
InstrumentationBase,
InstrumentationConfig,
} from '../../src';

interface TestInstrumentationConfig extends InstrumentationConfig {
isActive?: boolean;
}

class TestInstrumentation extends InstrumentationBase {
constructor() {
super('test', '1.0.0');
constructor(config: TestInstrumentationConfig & InstrumentationConfig = {}) {
super('test', '1.0.0', Object.assign({}, config));
}
enable() {}
disable() {}
Expand Down Expand Up @@ -56,4 +64,27 @@ describe('BaseInstrumentation', () => {
assert.strictEqual(called, true);
});
});

describe('config', () => {
it('should get config', () => {
const instrumentation: Instrumentation = new TestInstrumentation({
isActive: false,
});
const configuration =
instrumentation.getConfig() as TestInstrumentationConfig;
assert.notStrictEqual(configuration, null);
assert.strictEqual(configuration.isActive, false);
});

it('should modify config', () => {
const instrumentation: Instrumentation = new TestInstrumentation();
const config: TestInstrumentationConfig = {
isActive: true,
};
instrumentation.setConfig(config);
const configuration =
instrumentation.getConfig() as TestInstrumentationConfig;
assert.strictEqual(configuration.isActive, true);
});
});
});