Skip to content

feat(instrumentation-oracledb): add database client metrics - #3657

Open
prajalg wants to merge 19 commits into
open-telemetry:mainfrom
prajalg:oracledb_metrics_support
Open

feat(instrumentation-oracledb): add database client metrics#3657
prajalg wants to merge 19 commits into
open-telemetry:mainfrom
prajalg:oracledb_metrics_support

Conversation

@prajalg

@prajalg prajalg commented Aug 6, 2026

Copy link
Copy Markdown

Which problem is this PR solving?

Adds metrics support for @opentelemetry/instrumentation-oracledb.

This introduces Oracle DB client metrics aligned with OpenTelemetry database semantic conventions:

  • db.client.connection.count
  • db.client.operation.duration
  • db.client.connection.pending_requests
  • db.client.connection.timeouts

Short description of the changes

This PR adds metric collection to instrumentation-oracledb using node-oracledb trace handler callbacks.

Main changes:

  • Adds OracleTelemetryTraceMetricHandler, extending the existing trace handler behavior with metric callbacks.
  • Records pool connection metrics from node-oracledb pool lifecycle hooks such as acquire, release, wait, timeout, shrink, expand, and close.
  • Adds metric helpers for tracking pool state deltas and operation duration.
  • Uses connectionsCounterState map which stores counts as {idle, pending, used, timeouts} for each poolName so that it also supports instrumented application to have multiple pools (each with unique pool alias). Maintaining this map also reconciles if any pool changes that were not recorded, such as the changes made while instrumentation was disabled, ensuring metric values remain accurate after instrumentation is enabled again.
  • Adds semantic convention constants for Oracle DB client metrics.
  • Adds tests covering pool connection count, pending requests, timeouts, operation duration, and instrumentation enable/disable behavior.
  • Updates oracledb test dependency to ^6.7.0 and @types/oracledb to 6.10.4.

The pool metrics are recorded by reading the latest pool statistics and publishing deltas through OpenTelemetry metric instruments.

@prajalg
prajalg requested a review from a team as a code owner August 6, 2026 11:13
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 6, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-js-contrib.

Important reminders:

  • Read our Contributing Guidelines.
  • Sign the CLA if you haven't already.
  • Follow the OpenTelemetry Generative AI policy: disclose any AI use in your contribution, and communicate (PR descriptions, review replies) in your own words rather than AI-generated text.
  • Give reviewers at least a few days before pinging them for feedback.
  • If you need help with general setup, development process, or contributor etiquette, ask in #opentelemetry-new-contributors.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 6, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-08-13 20:47 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Comment thread package-lock.json
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/@types/oracledb/-/oracledb-6.5.2.tgz",
"integrity": "sha512-kK1eBS/Adeyis+3OlBDMeQQuasIDLUYXsi2T15ccNJ0iyUpQ4xDF7svFu3+bGVrI0CMBUclPciz+lsQR3JX3TQ==",
"version": "6.10.4",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be 6.10.4 or the 7.0.x version

@prajalg prajalg Aug 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tested with @types/oracledb 7.0.2, but encountered an error:
Cannot find lib definition for 'esnext.disposable', seems it is not in TS 5.0.4 which the root repository uses.
Looks like it needs some typescript update, so decided to avoid updating to latest types.

"@opentelemetry/instrumentation": "^0.221.0",
"@opentelemetry/semantic-conventions": "^1.34.0",
"@types/oracledb": "6.5.2"
"@types/oracledb": "^6.10.4"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this version be greater than 7.0.x?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

same reason of use of esnext.disposable in newer types.
Repository TS version should be updated first to support 7.0.2 types oracledb version

// calculate the correct delta on every pool event. On the next pool event, this
// also reconciles any pool changes that were not recorded, such as changes made
// while instrumentation was disabled, ensuring metric values remain accurate.
const connectionsCounterState: Record<string, PoolConnectionsCounter> = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a weak map probably may be better to automatically cleanup as the pools are closed/freed without receiving a callback (like when tracing is disabled after enable) into this module.

const connectionsCounterState = new WeakMap<oracleDBTypes.Pool, PoolConnectionsCounter>();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Thanks!

Comment on lines -869 to +867
pool.getConnection((err, conn) => {
pool.getConnection((...args) => {
const [err, conn] = args;

@prajalg prajalg Aug 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@types/oracledb@6.10.4 defines ResultCallback<T> as (...args: [DBError] | [null, T]) => void. A callback therefore receives either one error argument or two arguments for success. Our tests previously used (err, result), which assumes there are always two arguments. Using (...args) and destructuring the values works for both cases.

@sudarshan12s sudarshan12s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@sharadraju

Copy link
Copy Markdown

@maryliag Can you help us with the review here?

@maryliag maryliag left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for working on this, I added just small nits

Comment thread packages/instrumentation-oracledb/src/OracleTelemetryTraceHandler.ts Outdated
Comment thread packages/instrumentation-oracledb/test/oracle.metrics.test.ts Outdated
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Hi @prajalg — just a friendly reminder that this pull request is waiting on you.

There are still items that need your attention. See the dashboard status comment for the full list. You don't need to push a code change to hand it back — replying to move each discussion forward is enough, whether that's answering a question, explaining why no change is needed, or asking a follow-up. The dashboard then automatically routes it back to reviewers.

If you believe this pull request is incorrectly routed as waiting on the author, comment /dashboard route:reviewers to route it from waiting on the author to waiting on reviewers.

@prajalg

prajalg commented Aug 13, 2026

Copy link
Copy Markdown
Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@prajalg routed this pull request to reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants