Skip to content

Commit

Permalink
Merge branch 'main' into ver020
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny committed May 25, 2021
2 parents b643231 + eb9353a commit e624704
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
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,29 @@ describe('BaseInstrumentation', () => {
assert.strictEqual(called, true);
});
});

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

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

0 comments on commit e624704

Please sign in to comment.