Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions plugins/node/instrumentation-runtime-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install --save @opentelemetry/instrumentation-runtime-node
```js
import { NodeSDK } from '@opentelemetry/sdk-node';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { PerfHooksInstrumentation } from '@opentelemetry/instrumentation-runtime-node';
import { RuntimeNodeInstrumentation } from '@opentelemetry/instrumentation-runtime-node';

const prometheusExporter = new PrometheusExporter({
port: 9464,
Expand All @@ -25,7 +25,7 @@ const prometheusExporter = new PrometheusExporter({

const sdk = new NodeSDK({
metricReader: prometheusExporter,
instrumentations: [new PerfHooksInstrumentation({
instrumentations: [new RuntimeNodeInstrumentation({
eventLoopUtilizationMeasurementInterval: 5000,
})],
});
Expand All @@ -44,15 +44,15 @@ Go to [`localhost:9464/metrics`](http://localhost:9464/metrics), and you should
nodejs_performance_event_loop_utilization 0.010140079547955264
```

> Metrics will only be exported after it has collected two ELU readings (at least approximately `PerfHooksInstrumentationConfig.eventLoopUtilizationMeasurementInterval` milliseconds after initialization). Otherwise, you may see:
> Metrics will only be exported after it has collected two ELU readings (at least approximately `RuntimeNodeInstrumentationConfig.eventLoopUtilizationMeasurementInterval` milliseconds after initialization). Otherwise, you may see:
>
> ```txt
> # no registered metrics
> ```

### Options

`PerfHooksInstrumentation`'s constructor accepts the following options:
`RuntimeNodeInstrumentation`'s constructor accepts the following options:

| name | type | unit | default | description |
|---|---|---|---|---|
Expand Down
4 changes: 2 additions & 2 deletions plugins/node/instrumentation-runtime-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './instrumentation';
export * from './types';
export { RuntimeNodeInstrumentation } from './instrumentation';
export { RuntimeNodeInstrumentationConfig } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ const { eventLoopUtilization } = performance;
import { InstrumentationBase } from '@opentelemetry/instrumentation';

import { VERSION } from './version';
import { PerfHooksInstrumentationConfig } from './types';
import { RuntimeNodeInstrumentationConfig } from './types';

const ELUS_LENGTH = 2;
const DEFAULT_CONFIG: PerfHooksInstrumentationConfig = {
const DEFAULT_CONFIG: RuntimeNodeInstrumentationConfig = {
eventLoopUtilizationMeasurementInterval: 5000,
};

export class PerfHooksInstrumentation extends InstrumentationBase {
export class RuntimeNodeInstrumentation extends InstrumentationBase {
private _ELUs: EventLoopUtilization[] = [];
private _interval: NodeJS.Timeout | undefined;

constructor(config: PerfHooksInstrumentationConfig = DEFAULT_CONFIG) {
constructor(config: RuntimeNodeInstrumentationConfig = DEFAULT_CONFIG) {
super('@opentelemetry/instrumentation-runtime-node', VERSION, config);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export class PerfHooksInstrumentation extends InstrumentationBase {
clearInterval(this._interval);
this._interval = setInterval(
() => this._addELU(),
(this._config as PerfHooksInstrumentationConfig)
(this._config as RuntimeNodeInstrumentationConfig)
.eventLoopUtilizationMeasurementInterval
);
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/node/instrumentation-runtime-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';

export interface PerfHooksInstrumentationConfig extends InstrumentationConfig {
export interface RuntimeNodeInstrumentationConfig
extends InstrumentationConfig {
/**
* The approximate number of milliseconds for which to calculate event loop utilization averages.
* A larger value will result in more accurate averages at the expense of less granular data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';

import { PerfHooksInstrumentation } from '../src';
import { RuntimeNodeInstrumentation } from '../src';
import * as assert from 'assert';

const MEASUREMENT_INTERVAL = 10;
Expand All @@ -34,7 +34,7 @@ const metricReader = new PeriodicExportingMetricReader({
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(metricReader);

const instrumentation = new PerfHooksInstrumentation({
const instrumentation = new RuntimeNodeInstrumentation({
eventLoopUtilizationMeasurementInterval: MEASUREMENT_INTERVAL,
});

Expand Down Expand Up @@ -69,7 +69,7 @@ describe('nodejs.event_loop.utilization', () => {

it('can use default eventLoopUtilizationMeasurementInterval', async () => {
// Repeat of 'should not export immediately after enable' but with defaults
const localInstrumentation = new PerfHooksInstrumentation();
const localInstrumentation = new RuntimeNodeInstrumentation();
localInstrumentation.setMeterProvider(meterProvider);
localInstrumentation.disable();
metricExporter.reset();
Expand Down