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 16 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
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(instrumentation): add new `_setMeterInstruments` protected method that update the meter instruments every meter provider update.
legendecas marked this conversation as resolved.
Show resolved Hide resolved
* feat(metrics-sdk): Add tracing suppresing for Metrics Export [#3332](https://github.com/open-telemetry/opentelemetry-js/pull/3332) @hectorhdzg
* feat(instrumentation): implement `require-in-the-middle` singleton [#3161](https://github.com/open-telemetry/opentelemetry-js/pull/3161) @mhassan1
* feat(sdk-node): configure trace exporter with environment variables [#3143](https://github.com/open-telemetry/opentelemetry-js/pull/3143) @svetlanabrennan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import {
SpanStatusCode,
trace,
Histogram,
MeterProvider,
MetricAttributes,
ValueType,
ValueType
} from '@opentelemetry/api';
import { hrTime, hrTimeDuration, hrTimeToMilliseconds, suppressTracing } from '@opentelemetry/core';
import type * as http from 'http';
Expand Down Expand Up @@ -73,15 +72,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.3.0"
},
"devDependencies": {
"@opentelemetry/sdk-metrics": "^1.8.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 believe this needs to follow our dev dependency conventions to set a specific version instead of version ranges. However, I can not edit the PR before merging.

Suggested change
"@opentelemetry/sdk-metrics": "^1.8.0",
"@opentelemetry/sdk-metrics": "1.8.0",

Copy link
Member

Choose a reason for hiding this comment

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

Tips: when you create the PR, if you are ok with it, it would be more convenient for us to adopt those miscellaneous snippets before merging if you can check this option.

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! it will be enabled from my next pr (currently I'm under my company fork so I can't set this option).

Copy link
Member

Choose a reason for hiding this comment

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

@osherv could you do the change and rebase so we can merge this ?

Copy link
Member Author

Choose a reason for hiding this comment

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

ready for merge :)

Copy link
Member

Choose a reason for hiding this comment

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

I still didn't find the caret being removed. Would you mind verifying if your commits are pushed?

Copy link
Member

Choose a reason for hiding this comment

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

Has this been updated?

"@babel/core": "7.16.0",
"@opentelemetry/api": "^1.3.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