Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation): add getModuleDefinitions() instead of making init() public #4475

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(instrumetation): add tests for getModuleDefinitions()
  • Loading branch information
pichlermarc committed Feb 12, 2024
commit 5817d893fb37add304407c27761af66767171c71
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Instrumentation,
InstrumentationBase,
InstrumentationConfig,
InstrumentationModuleDefinition,
} from '../../src';

import { MeterProvider } from '@opentelemetry/sdk-metrics';
Expand Down Expand Up @@ -132,4 +133,54 @@ describe('BaseInstrumentation', () => {
assert.strictEqual(configuration.isActive, true);
});
});

describe('getModuleDefinitions', () => {
const moduleDefinition: InstrumentationModuleDefinition<unknown> = {
name: 'foo',
patch: moduleExports => {},
unpatch: moduleExports => {},
moduleExports: {},
files: [],
supportedVersions: ['*'],
};

it('should return single module definition from init() as array ', () => {
class TestInstrumentation2 extends TestInstrumentation {
override init() {
return moduleDefinition;
}
}
const instrumentation = new TestInstrumentation2();

assert.deepStrictEqual(instrumentation.getModuleDefinitions(), [
moduleDefinition,
]);
});

it('should return multiple module definitions from init() as array ', () => {
class TestInstrumentation2 extends TestInstrumentation {
override init() {
return [moduleDefinition, moduleDefinition, moduleDefinition];
}
}
const instrumentation = new TestInstrumentation2();

assert.deepStrictEqual(instrumentation.getModuleDefinitions(), [
moduleDefinition,
moduleDefinition,
moduleDefinition,
]);
});

it('should return void from init() as empty array ', () => {
class TestInstrumentation2 extends TestInstrumentation {
override init() {
return;
}
}
const instrumentation = new TestInstrumentation2();

assert.deepStrictEqual(instrumentation.getModuleDefinitions(), []);
});
});
});
Loading