Skip to content

Commit

Permalink
feat(otel-node): add @opentelemetry/instrumentation-mongoose (#538)
Browse files Browse the repository at this point in the history
Co-authored-by: Trent Mick <[email protected]>
  • Loading branch information
david-luna and trentm authored Jan 14, 2025
1 parent 277a724 commit 0b204c9
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"compile-all": "./scripts/oneach.sh npm run --if-present compile",
"clean": "rm -rf node_modules build",
"oneach": "./scripts/oneach.sh",
"lint": "npm run lint:eslint && ls -d packages/* | while read d; do (cd $d; npm run lint); done",
"lint": "npm run lint:eslint && (set -e; ls -d packages/* | while read d; do (cd $d; npm run lint); done)",
"lint:eslint": "eslint --ext=js,mjs,cjs scripts examples # requires node >=16.0.0",
"lint:fix": "eslint --ext=js,mjs,cjs .eslintrc.js scripts examples --fix && ls -d packages/* | while read d; do (cd $d; npm run lint:fix); done"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/mockotlpserver/lib/waterfall.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ function renderSpan(span, prefix = '') {
BigInt(span.startTimeUnixNano) -
BigInt(lastRenderedSpan.startTimeUnixNano)
) / 1e6;
let sign = startOffset >= 0 ? '+' : '-';
let unit = 'ms';

// Use the absolute value to do the proper unit transform
startOffset = Math.abs(startOffset);
if (startOffset >= 1000) {
startOffset /= 1000;
unit = 's';
Expand All @@ -95,7 +99,7 @@ function renderSpan(span, prefix = '') {
startOffset /= 24;
unit = 'd';
}
gutter = `${startOffset >= 0 ? '+' : '-'}${Math.floor(startOffset)}`;
gutter = `${sign}${Math.floor(startOffset)}`;
gutter = `${' '.repeat(4 - gutter.length)}${gutter}${unit}`;
} else {
gutter = ' '.repeat(6);
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-node/docs/supported-technologies.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ requires:
| `@opentelemetry/instrumentation-lru-memoizer` | `lru-memoizer` version range `>=1.3 <3` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer#readme) |
| `@opentelemetry/instrumentation-memcached` | `memcached` version range `>=2.2` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-memcached#readme) |
| `@opentelemetry/instrumentation-mongodb` | `mongodb` version range `>=3.3 <7` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme) |
| `@opentelemetry/instrumentation-mongoose` | `mongoose` version range `>=5.9.7 <9` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose#readme) |
| `@opentelemetry/instrumentation-mysql` | `mysql` version range `>=2.0.0 <3` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mysql#readme) |
| `@opentelemetry/instrumentation-mysql2` | `mysql2` version range `>=1.4.2 <4` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mysql2#readme) |
| `@opentelemetry/instrumentation-nestjs-core` | `@nestjs/core` version range `>=4.0.0` | [README](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core#readme) |
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-node/lib/instrumentations.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* "@opentelemetry/instrumentation-lru-memoizer": import('@opentelemetry/instrumentation').InstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-memcached": import('@opentelemetry/instrumentation-memcached').InstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-mongodb": import('@opentelemetry/instrumentation-mongodb').MongoDBInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-mongoose": import('@opentelemetry/instrumentation-mongoose').MongooseInstrumentationConfig | InstrumentationFactory,
* "@opentelemetry/instrumentation-mysql": import('@opentelemetry/instrumentation-mysql').MySQLInstrumentation | InstrumentationFactory,
* "@opentelemetry/instrumentation-mysql2": import('@opentelemetry/instrumentation-mysql2').MySQL2Instrumentation | InstrumentationFactory,
* "@opentelemetry/instrumentation-nestjs-core": import('@opentelemetry/instrumentation').InstrumentationConfig | InstrumentationFactory,
Expand Down Expand Up @@ -81,6 +82,7 @@ const {KoaInstrumentation} = require('@opentelemetry/instrumentation-koa');
const {LruMemoizerInstrumentation} = require('@opentelemetry/instrumentation-lru-memoizer');
const {MemcachedInstrumentation} = require('@opentelemetry/instrumentation-memcached');
const {MongoDBInstrumentation} = require('@opentelemetry/instrumentation-mongodb');
const {MongooseInstrumentation} = require('@opentelemetry/instrumentation-mongoose');
const {MySQLInstrumentation} = require('@opentelemetry/instrumentation-mysql');
const {MySQL2Instrumentation} = require('@opentelemetry/instrumentation-mysql2');
const {NestInstrumentation} = require('@opentelemetry/instrumentation-nestjs-core');
Expand Down Expand Up @@ -128,6 +130,7 @@ const INSTRUMENTATIONS = {
'@opentelemetry/instrumentation-lru-memoizer': (cfg) => new LruMemoizerInstrumentation(cfg),
'@opentelemetry/instrumentation-memcached': (cfg) => new MemcachedInstrumentation(cfg),
'@opentelemetry/instrumentation-mongodb': (cfg) => new MongoDBInstrumentation(cfg),
'@opentelemetry/instrumentation-mongoose': (cfg) => new MongooseInstrumentation(cfg),
'@opentelemetry/instrumentation-mysql': (cfg) => new MySQLInstrumentation(cfg),
'@opentelemetry/instrumentation-mysql2': (cfg) => new MySQL2Instrumentation(cfg),
'@opentelemetry/instrumentation-nestjs-core': (cfg) => new NestInstrumentation(cfg),
Expand Down
235 changes: 235 additions & 0 deletions packages/opentelemetry-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@opentelemetry/instrumentation-lru-memoizer": "^0.44.0",
"@opentelemetry/instrumentation-memcached": "^0.43.0",
"@opentelemetry/instrumentation-mongodb": "^0.51.0",
"@opentelemetry/instrumentation-mongoose": "^0.46.0",
"@opentelemetry/instrumentation-mysql": "^0.45.0",
"@opentelemetry/instrumentation-mysql2": "^0.45.0",
"@opentelemetry/instrumentation-nestjs-core": "^0.44.0",
Expand Down Expand Up @@ -139,6 +140,7 @@
"ioredis": "^5.4.1",
"module-details-from-path": "^1.0.3",
"mongodb": "^6.9.0",
"mongoose": "^8.9.4",
"mysql": "^2.18.1",
"mysql2": "^3.11.5",
"openai": "^4.76.3",
Expand Down
Loading

0 comments on commit 0b204c9

Please sign in to comment.