opentelemetry-js
opentelemetry-js copied to clipboard
feat(instrumentation): add new setMeterInstruments method
trafficstars
Fixes #3249
This issue allows the instrumentations to only implement the setMeterInstruments when collecting metrics.
Before:
export class MongoDBInstrumentation extends InstrumentationBase {
private _connectionsUsage!: UpDownCounter;
constructor(protected override _config: MongoDBInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-mongodb', VERSION, _config);
this._setMetricInstruments();
}
override setMeterProvider(meterProvider: MeterProvider) {
super.setMeterProvider(meterProvider);
this._setMetricInstruments();
}
private _setMetricInstruments() {
this._connectionsUsage = this.meter.createUpDownCounter(
'active_connections',
{
description:
'The number of connections that are currently in state described by the state attribute.',
}
);
}
After:
export class MongoDBInstrumentation extends InstrumentationBase {
private _connectionsUsage!: UpDownCounter;
private _setMetricInstruments() {
this._connectionsUsage = this.meter.createUpDownCounter(
'active_connections',
{
description:
'The number of connections that are currently in state described by the state attribute.',
}
);
}
Codecov Report
Merging #3267 (7c67a60) into main (e315f53) will decrease coverage by
0.02%. The diff coverage is100.00%.
Additional details and impacted files
@@ Coverage Diff @@
## main #3267 +/- ##
==========================================
- Coverage 93.26% 93.23% -0.03%
==========================================
Files 247 247
Lines 7348 7348
Branches 1512 1512
==========================================
- Hits 6853 6851 -2
- Misses 495 497 +2
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...ges/opentelemetry-instrumentation-http/src/http.ts | 94.71% <100.00%> (-0.07%) |
:arrow_down: |
| ...entelemetry-instrumentation/src/instrumentation.ts | 80.00% <100.00%> (+10.76%) |
:arrow_up: |
| ...ckages/opentelemetry-sdk-trace-web/karma.worker.js | 0.00% <0.00%> (-100.00%) |
:arrow_down: |
@legendecas agreed with your comments, thanks :)
Hey :) @legendecas Sorry for the delay but added tests now.
:( it looks like we need another update with the main branch.