opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

feat(instrumentation): add new setMeterInstruments method

Open osherv opened this issue 3 years ago • 2 comments
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.',
      }
    );
  }

osherv avatar Sep 19 '22 12:09 osherv

Codecov Report

Merging #3267 (7c67a60) into main (e315f53) will decrease coverage by 0.02%. The diff coverage is 100.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:

codecov[bot] avatar Sep 19 '22 12:09 codecov[bot]

@legendecas agreed with your comments, thanks :)

osherv avatar Sep 20 '22 07:09 osherv

Hey :) @legendecas Sorry for the delay but added tests now.

osherv avatar Nov 06 '22 11:11 osherv

:( it looks like we need another update with the main branch.

legendecas avatar Nov 15 '22 17:11 legendecas