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 new setMeterInstruments method #3267

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2fafb4c
feat(instrumentation): add new protected method that update the mete…
osherv Sep 19, 2022
5188bb9
feat(instrumentation): fixed markdown lint
osherv Sep 19, 2022
b92bb79
Update experimental/packages/opentelemetry-instrumentation/src/instru…
osherv Sep 20, 2022
a1d9119
Update experimental/packages/opentelemetry-instrumentation/src/instru…
osherv Sep 20, 2022
d5b3ddc
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Sep 20, 2022
77c9374
feat(instrumentation): renamed function
osherv Sep 20, 2022
75af723
feat(instrumentation): adapted http instrumentation to the new api
osherv Sep 20, 2022
210b77b
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 6, 2022
f768af1
feat(instrumentation): added tests
osherv Nov 6, 2022
d6952f8
Merge branch 'feat/add-update-metric-instruments-interface' of github…
osherv Nov 6, 2022
7328f00
feat(instrumentation): resolved conlicts
osherv Nov 6, 2022
c6c2be9
feat(instrumentation): fixed legendcas CR
osherv Nov 7, 2022
f65c81e
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 8, 2022
244cd98
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 9, 2022
8f70a7f
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 10, 2022
fe7880c
feat(instrumentation): fixed dyladan's CR
osherv Nov 10, 2022
9df8e43
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 13, 2022
3bfca7f
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 14, 2022
0ef2766
feat(instrumentation): fixed vmarchaud's CR
osherv Nov 14, 2022
ca02353
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 15, 2022
f31f953
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 16, 2022
2e550f8
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 17, 2022
7c67a60
Merge branch 'main' into feat/add-update-metric-instruments-interface
osherv Nov 20, 2022
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
5 changes: 5 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to experimental packages in this project will be documented

## Unreleased

* feat(instrumentation): add new `_setMeterInstruments` protected method that update the meter instruments every
legendecas marked this conversation as resolved.
Show resolved Hide resolved
meter provider update.

*

### :boom: Breaking Change

* Add semver check to metrics API [#3357](https://github.com/open-telemetry/opentelemetry-js/pull/3357) @dyladan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import {
SpanStatus,
SpanStatusCode,
trace,
Histogram,
MeterProvider,
MetricAttributes,
ValueType,
} from '@opentelemetry/api';
import { Histogram, MetricAttributes, ValueType } from '@opentelemetry/api-metrics';
legendecas marked this conversation as resolved.
Show resolved Hide resolved
import { hrTime, hrTimeDuration, hrTimeToMilliseconds, suppressTracing } from '@opentelemetry/core';
import type * as http from 'http';
import type * as https from 'https';
Expand Down Expand Up @@ -73,15 +70,9 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
config
);
this._headerCapture = this._createHeaderCapture();
this._updateMetricInstruments();
}

override setMeterProvider(meterProvider: MeterProvider) {
super.setMeterProvider(meterProvider);
this._updateMetricInstruments();
}

private _updateMetricInstruments() {
protected override _updateMetricInstruments() {
this._httpServerDurationHistogram = this.meter.createHistogram('http.server.duration', {
description: 'measures the duration of the inbound HTTP requests',
unit: 'ms',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@opentelemetry/api": "^1.2.0"
},
"devDependencies": {
"@opentelemetry/sdk-metrics": "^0.32.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already otudated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

"@babel/core": "7.16.0",
"@opentelemetry/api": "^1.2.0",
"@types/mocha": "10.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ implements types.Instrumentation {
this._tracer = trace.getTracer(instrumentationName, instrumentationVersion);

this._meter = metrics.getMeter(instrumentationName, instrumentationVersion);
this._updateMetricInstruments();
}

/* Api to wrap instrumented method */
Expand All @@ -81,6 +82,15 @@ implements types.Instrumentation {
this.instrumentationName,
this.instrumentationVersion
);

this._updateMetricInstruments();
}

/**
* Sets the new metric instruments with the current Meter.
*/
protected _updateMetricInstruments(): void {
legendecas marked this conversation as resolved.
Show resolved Hide resolved
return;
}

/* Returns InstrumentationConfig */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
InstrumentationConfig,
} from '../../src';

import { MeterProvider } from '@opentelemetry/sdk-metrics';

interface TestInstrumentationConfig extends InstrumentationConfig {
isActive?: boolean;
}
Expand Down Expand Up @@ -54,13 +56,36 @@ describe('BaseInstrumentation', () => {

describe('constructor', () => {
it('should enable instrumentation by default', () => {
let called = false;
let enableCalled = false;
let updateMetricInstrumentsCalled = false;
class TestInstrumentation2 extends TestInstrumentation {
override enable() {
enableCalled = true;
}
override _updateMetricInstruments() {
updateMetricInstrumentsCalled = true;
}
}
instrumentation = new TestInstrumentation2();
assert.strictEqual(enableCalled, true);
assert.strictEqual(updateMetricInstrumentsCalled, true);
});
});

describe('setMeterProvider', () => {
let otelTestingMeterProvider: MeterProvider;
beforeEach(() => {
otelTestingMeterProvider = new MeterProvider();
});
it('should call _updateMetricInstruments', () => {
let called = true;
class TestInstrumentation2 extends TestInstrumentation {
override _updateMetricInstruments() {
called = true;
}
}
instrumentation = new TestInstrumentation2();
instrumentation.setMeterProvider(otelTestingMeterProvider);
assert.strictEqual(called, true);
});
});
Expand Down