Skip to content

Commit f04564f

Browse files
authored
Merge branch 'main' into remove-shutdown-concept-altogether
2 parents 2e45359 + 5bc8ced commit f04564f

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

experimental/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All notable changes to experimental packages in this project will be documented
1616
### :rocket: (Enhancement)
1717

1818
* feat(instrumentation): allow LoggerProvider to be specified in Instrumentations [#4314](https://github.com/open-telemetry/opentelemetry-js/pull/4314) @hectorhdzg
19-
* feat(instrumentation): Make `init()` method public [#4418](https://github.com/open-telemetry/opentelemetry-js/pull/4418)
19+
* feat(instrumentation): add getModuleDefinitions() to InstrumentationBase [#4475](https://github.com/open-telemetry/opentelemetry-js/pull/4475) @pichlermarc
2020
* feat(exporter-metrics-otlp-http): add option to set the exporter aggregation preference [#4409](https://github.com/open-telemetry/opentelemetry-js/pull/4409) @AkselAllas
2121
* feat(node-sdk): add spanProcessors option [#4454](https://github.com/open-telemetry/opentelemetry-js/pull/4454) @naseemkullah
2222

@@ -25,6 +25,7 @@ All notable changes to experimental packages in this project will be documented
2525
* fix(sdk-node): allow using samplers when the exporter is defined in the environment [#4394](https://github.com/open-telemetry/opentelemetry-js/pull/4394) @JacksonWeber
2626
* fix(instrumentation): normalize paths for internal files in scoped packages [#4467](https://github.com/open-telemetry/opentelemetry-js/pull/4467) @pichlermarc
2727
* Fixes a bug where, on Windows, internal files on scoped packages would not be instrumented.
28+
* fix(otlp-transformer): only use BigInt inside hrTimeToNanos() [#4484](https://github.com/open-telemetry/opentelemetry-js/pull/4484) @pichlermarc
2829

2930
### :books: (Refine Doc)
3031

experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ export abstract class InstrumentationAbstract<T = any>
108108
);
109109
}
110110

111+
/**
112+
* @experimental
113+
*
114+
* Get module definitions defined by {@link init}.
115+
* This can be used for experimental compile-time instrumentation.
116+
*
117+
* @returns an array of {@link InstrumentationModuleDefinition}
118+
*/
119+
public getModuleDefinitions(): InstrumentationModuleDefinition<T>[] {
120+
const initResult = this.init() ?? [];
121+
if (!Array.isArray(initResult)) {
122+
return [initResult];
123+
}
124+
125+
return initResult;
126+
}
127+
111128
/**
112129
* Sets the new metric instruments with the current Meter.
113130
*/
@@ -153,11 +170,8 @@ export abstract class InstrumentationAbstract<T = any>
153170
/**
154171
* Init method in which plugin should define _modules and patches for
155172
* methods.
156-
* Use `enable()` if you are trying to turn on this plugin. This method
157-
* will return objects to patch specific modules with the appropriate
158-
* instrumentation (or not return anything).
159173
*/
160-
abstract init():
174+
protected abstract init():
161175
| InstrumentationModuleDefinition<T>
162176
| InstrumentationModuleDefinition<T>[]
163177
| void;

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

+51
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Instrumentation,
2020
InstrumentationBase,
2121
InstrumentationConfig,
22+
InstrumentationModuleDefinition,
2223
} from '../../src';
2324

2425
import { MeterProvider } from '@opentelemetry/sdk-metrics';
@@ -132,4 +133,54 @@ describe('BaseInstrumentation', () => {
132133
assert.strictEqual(configuration.isActive, true);
133134
});
134135
});
136+
137+
describe('getModuleDefinitions', () => {
138+
const moduleDefinition: InstrumentationModuleDefinition<unknown> = {
139+
name: 'foo',
140+
patch: moduleExports => {},
141+
unpatch: moduleExports => {},
142+
moduleExports: {},
143+
files: [],
144+
supportedVersions: ['*'],
145+
};
146+
147+
it('should return single module definition from init() as array ', () => {
148+
class TestInstrumentation2 extends TestInstrumentation {
149+
override init() {
150+
return moduleDefinition;
151+
}
152+
}
153+
const instrumentation = new TestInstrumentation2();
154+
155+
assert.deepStrictEqual(instrumentation.getModuleDefinitions(), [
156+
moduleDefinition,
157+
]);
158+
});
159+
160+
it('should return multiple module definitions from init() as array ', () => {
161+
class TestInstrumentation2 extends TestInstrumentation {
162+
override init() {
163+
return [moduleDefinition, moduleDefinition, moduleDefinition];
164+
}
165+
}
166+
const instrumentation = new TestInstrumentation2();
167+
168+
assert.deepStrictEqual(instrumentation.getModuleDefinitions(), [
169+
moduleDefinition,
170+
moduleDefinition,
171+
moduleDefinition,
172+
]);
173+
});
174+
175+
it('should return void from init() as empty array ', () => {
176+
class TestInstrumentation2 extends TestInstrumentation {
177+
override init() {
178+
return;
179+
}
180+
}
181+
const instrumentation = new TestInstrumentation2();
182+
183+
assert.deepStrictEqual(instrumentation.getModuleDefinitions(), []);
184+
});
185+
});
135186
});

experimental/packages/otlp-transformer/src/common/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import type { OtlpEncodingOptions, Fixed64, LongBits } from './types';
1818
import { HrTime } from '@opentelemetry/api';
1919
import { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';
2020

21-
const NANOSECONDS = BigInt(1_000_000_000);
22-
2321
export function hrTimeToNanos(hrTime: HrTime): bigint {
22+
const NANOSECONDS = BigInt(1_000_000_000);
2423
return BigInt(hrTime[0]) * NANOSECONDS + BigInt(hrTime[1]);
2524
}
2625

0 commit comments

Comments
 (0)