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

Conversation

osherv
Copy link
Member

@osherv osherv commented Sep 19, 2022

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 osherv requested a review from a team September 19, 2022 12:51
@codecov
Copy link

codecov bot commented Sep 19, 2022

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%) ⬇️
...entelemetry-instrumentation/src/instrumentation.ts 80.00% <100.00%> (+10.76%) ⬆️
...ckages/opentelemetry-sdk-trace-web/karma.worker.js 0.00% <0.00%> (-100.00%) ⬇️

@osherv
Copy link
Member Author

osherv commented Sep 20, 2022

@legendecas agreed with your comments, thanks :)

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Generally LGTM! Thank you for working on this.

@osherv
Copy link
Member Author

osherv commented Nov 6, 2022

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

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

LGTM % nits.

experimental/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Still LGTM

@@ -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?

@legendecas
Copy link
Member

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

@vmarchaud vmarchaud merged commit b29deee into open-telemetry:main Nov 20, 2022
pichlermarc added a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
* feat(mongodb): started working on mongodb connection pool instrumentations

* feat(mongodb): started working on mongodb connection pool instrumentations

* feat(mongodb): started working on mongodb connection pool instrumentations

* feat(mongodb): started working on mongodb connection pool instrumentations

* feat(mongodb): added connection metrics mongodb4 before tests

* feat(mongodb): started working on tests

* feat(mongodb): started working on tests

* feat(mongodb): started working on tests

* feat(mongodb): started working on tests

* feat(mongodb): started working on tests

* feat(mongodb): added mongodb4 metric tests

* feat(mongodb): added mongodb4 metric tests

* feat(mongodb): added mongodb4 metric tests

* feat(mongodb): started working on mongodb3 metrics

* feat(mongodb): removed <4 supprot

* fix(mongo4): mongodb v4 instrumentation. fix idle/used counting

* fix(mongo4): lint

* fix(mongo4): use _updateMetricInstruments() as described in open-telemetry#3267

* fix(mongo4): lint

* fix(mongo4): change deps

* fix(mongo4): change deps 2

* fix(mongo4): revert deps

* fix(mongo4): fixes

* fix(mongo4): lint

* fix(mongo4): lexport type

* fix(mongo4): fixes

* fix(mongo4): fixes

* fix(mongo4): fixes: remote redundant from types, remove unneeded comments

* fix(mongo4): add connection_string

* fix(mongo4): add undefined instead of connection_string for for mongo v3

* Update plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>

* Update plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>

* fix(mongo4): move V4Connect and V4Session to internal-types

* fix(mongo): lint

* fix(mongo): align metric description with semconv

* Update plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.metrics.test.ts

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>

* fix(mongo): fix sessions.length to work also for versions 4.1 - 4.11

* fix(mongo): try to fix TAV for node 16 & 18 that doesn't work for mongo 3.6.2

---------

Co-authored-by: haddasbronfman <haddasb@cisco.com>
Co-authored-by: Haddas Bronfman <85441461+haddasbronfman@users.noreply.github.com>
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Meter metrics get override in instrumentations after setMeterProvider has called
5 participants