diff --git a/.circleci/config.yml b/.circleci/config.yml index 0af27cf45e..3b04413452 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ cache_2: &cache_2 - packages/opentelemetry-plugin-grpc/node_modules - packages/opentelemetry-plugin-http/node_modules - packages/opentelemetry-plugin-http2/node_modules - - packages/opentelemetry-plugin-mongodb-core/node_modules + - packages/opentelemetry-plugin-mongodb/node_modules - packages/opentelemetry-plugin-redis/node_modules - packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/node_modules - packages/opentelemetry-plugin-document-load/node_modules diff --git a/README.md b/README.md index 3542d7bff4..9ce9ccebff 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ OpenTelemetry can collect tracing data automatically using plugins. Vendors/User - [@opentelemetry/plugin-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-grpc) - [@opentelemetry/plugin-http](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-http) - [@opentelemetry/plugin-https](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-https) -- [@opentelemetry/plugin-mongodb-core](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mongodb-core) +- [@opentelemetry/plugin-mongodb](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mongodb) - [@opentelemetry/plugin-mysql](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mysql) - [@opentelemetry/plugin-pg](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg) - [@opentelemetry/plugin-pg-pool](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool) diff --git a/packages/opentelemetry-node/src/config.ts b/packages/opentelemetry-node/src/config.ts index 5fe7f6a567..0c52ee081d 100644 --- a/packages/opentelemetry-node/src/config.ts +++ b/packages/opentelemetry-node/src/config.ts @@ -27,7 +27,7 @@ export interface NodeTracerConfig extends BasicTracerConfig { /** List of all default supported plugins */ export const DEFAULT_INSTRUMENTATION_PLUGINS: Plugins = { - 'mongodb-core': { enabled: true, path: '@opentelemetry/plugin-mongodb-core' }, + mongodb: { enabled: true, path: '@opentelemetry/plugin-mongodb' }, grpc: { enabled: true, path: '@opentelemetry/plugin-grpc' }, http: { enabled: true, path: '@opentelemetry/plugin-http' }, https: { enabled: true, path: '@opentelemetry/plugin-https' }, diff --git a/packages/opentelemetry-plugin-mongodb-core/src/version.ts b/packages/opentelemetry-plugin-mongodb-core/src/version.ts deleted file mode 100644 index 60ca3ab548..0000000000 --- a/packages/opentelemetry-plugin-mongodb-core/src/version.ts +++ /dev/null @@ -1,18 +0,0 @@ -/*! - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.1'; diff --git a/packages/opentelemetry-plugin-mongodb-core/.npmignore b/packages/opentelemetry-plugin-mongodb/.npmignore similarity index 100% rename from packages/opentelemetry-plugin-mongodb-core/.npmignore rename to packages/opentelemetry-plugin-mongodb/.npmignore diff --git a/packages/opentelemetry-plugin-mongodb-core/LICENSE b/packages/opentelemetry-plugin-mongodb/LICENSE similarity index 100% rename from packages/opentelemetry-plugin-mongodb-core/LICENSE rename to packages/opentelemetry-plugin-mongodb/LICENSE diff --git a/packages/opentelemetry-plugin-mongodb-core/README.md b/packages/opentelemetry-plugin-mongodb/README.md similarity index 82% rename from packages/opentelemetry-plugin-mongodb-core/README.md rename to packages/opentelemetry-plugin-mongodb/README.md index d4da15c5d4..dd6697c39e 100644 --- a/packages/opentelemetry-plugin-mongodb-core/README.md +++ b/packages/opentelemetry-plugin-mongodb/README.md @@ -1,10 +1,10 @@ -# OpenTelemetry mongodb-core Instrumentation for Node.js +# OpenTelemetry mongodb Instrumentation for Node.js [![Gitter chat][gitter-image]][gitter-url] [![dependencies][dependencies-image]][dependencies-url] [![devDependencies][devDependencies-image]][devDependencies-url] [![Apache License][license-image]][license-image] -This module provides automatic instrumentation for [`mongodb-core`](https://github.com/mongodb-js/mongodb-core). +This module provides automatic instrumentation for [`mongodb`](https://github.com/mongodb/node-mongodb-native). For automatic instrumentation see the [@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node) package. @@ -12,8 +12,10 @@ For automatic instrumentation see the ## Installation ```bash -npm install --save @opentelemetry/plugin-mongodb-core +npm install --save @opentelemetry/plugin-mongodb ``` +### Supported Versions + - `'>=2.0.0 <4` ## Usage @@ -25,10 +27,10 @@ const { NodeTracer } = require('@opentelemetry/node'); const tracer = new NodeTracer({ plugins: { - 'mongodb-core': { + mongodb: { enabled: true, // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-mongodb-core', + path: '@opentelemetry/plugin-mongodb', } } }); @@ -41,7 +43,7 @@ const { NodeTracer } = require('@opentelemetry/node'); const tracer = new NodeTracer(); ``` -See [examples/mongodb](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/mongodb-core) for a short example. +See [examples/mongodb](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/mongodb) for a short example. ## Useful links - For more information on OpenTelemetry, visit: @@ -56,7 +58,7 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [gitter-url]: https://gitter.im/open-telemetry/opentelemetry-node?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge [license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/master/LICENSE [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat -[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/status.svg?path=packages/opentelemetry-plugin-mongodb-core -[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-plugin-mongodb-core -[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-plugin-mongodb-core -[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-plugin-mongodb-core&type=dev +[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/status.svg?path=packages/opentelemetry-plugin-mongodb +[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-plugin-mongodb +[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-plugin-mongodb +[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-plugin-mongodb&type=dev diff --git a/packages/opentelemetry-plugin-mongodb-core/package.json b/packages/opentelemetry-plugin-mongodb/package.json similarity index 90% rename from packages/opentelemetry-plugin-mongodb-core/package.json rename to packages/opentelemetry-plugin-mongodb/package.json index 49182d0472..a028fa5216 100644 --- a/packages/opentelemetry-plugin-mongodb-core/package.json +++ b/packages/opentelemetry-plugin-mongodb/package.json @@ -1,7 +1,7 @@ { - "name": "@opentelemetry/plugin-mongodb-core", + "name": "@opentelemetry/plugin-mongodb", "version": "0.3.1", - "description": "OpenTelemetry mongodb-core automatic instrumentation package.", + "description": "OpenTelemetry mongodb automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", @@ -19,7 +19,7 @@ }, "keywords": [ "opentelemetry", - "mongodb-core", + "mongodb", "nodejs", "tracing", "profiling", @@ -50,7 +50,7 @@ "codecov": "^3.6.1", "gts": "^1.1.0", "mocha": "^6.2.0", - "mongodb": "^3.3.0", + "mongodb": "^3.4.1", "nyc": "^14.1.1", "rimraf": "^3.0.0", "ts-mocha": "^6.0.0", diff --git a/packages/opentelemetry-plugin-mongodb-core/src/index.ts b/packages/opentelemetry-plugin-mongodb/src/index.ts similarity index 100% rename from packages/opentelemetry-plugin-mongodb-core/src/index.ts rename to packages/opentelemetry-plugin-mongodb/src/index.ts diff --git a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts b/packages/opentelemetry-plugin-mongodb/src/mongodb.ts similarity index 91% rename from packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts rename to packages/opentelemetry-plugin-mongodb/src/mongodb.ts index 0c2afbbf3f..8d76981177 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/mongodb.ts +++ b/packages/opentelemetry-plugin-mongodb/src/mongodb.ts @@ -30,14 +30,14 @@ import * as mongodb from 'mongodb'; import * as shimmer from 'shimmer'; /** MongoDBCore instrumentation plugin for OpenTelemetry */ -export class MongoDBCorePlugin extends BasePlugin { +export class MongoDBPlugin extends BasePlugin { private readonly _SERVER_METHODS = ['insert', 'update', 'remove', 'command']; private readonly _CURSOR_METHODS = ['_next', 'next']; - private readonly _COMPONENT = 'mongodb-core'; + private readonly _COMPONENT = 'mongodb'; private readonly _DB_TYPE = 'mongodb'; - readonly supportedVersions = ['>=2 <3']; + readonly supportedVersions = ['>=2 <4']; constructor(readonly moduleName: string) { super(); @@ -51,7 +51,7 @@ export class MongoDBCorePlugin extends BasePlugin { if (this._moduleExports.Server) { for (const fn of this._SERVER_METHODS) { - this._logger.debug(`patching mongodb-core.Server.prototype.${fn}`); + this._logger.debug(`patching mongodb.Server.prototype.${fn}`); shimmer.wrap( this._moduleExports.Server.prototype, // Forced to ignore due to incomplete typings @@ -65,7 +65,7 @@ export class MongoDBCorePlugin extends BasePlugin { if (this._moduleExports.Cursor) { this._logger.debug( - 'patching mongodb-core.Cursor.prototype functions:', + 'patching mongodb.Cursor.prototype functions:', this._CURSOR_METHODS ); shimmer.massWrap( @@ -170,10 +170,12 @@ export class MongoDBCorePlugin extends BasePlugin { topology: MongoInternalTopology ) { // add network attributes to determine the remote server - if (topology && topology.s && topology.s.options) { + if (topology && topology.s) { span.setAttributes({ - [AttributeNames.PEER_HOSTNAME]: `${topology.s.options.host}`, - [AttributeNames.PEER_PORT]: `${topology.s.options.port}`, + [AttributeNames.PEER_HOSTNAME]: `${topology.s.options?.host ?? + topology.s.host}`, + [AttributeNames.PEER_PORT]: `${topology.s.options?.port ?? + topology.s.port}`, }); } // add database related attributes @@ -184,7 +186,7 @@ export class MongoDBCorePlugin extends BasePlugin { }); if (command === undefined) return; - const query = Object.keys(command.query || command.q || {}).reduce( + const query = Object.keys(command.query ?? command.q ?? command).reduce( (obj, key) => { obj[key] = '?'; return obj; @@ -246,4 +248,4 @@ export class MongoDBCorePlugin extends BasePlugin { } } -export const plugin = new MongoDBCorePlugin('mongodb-core'); +export const plugin = new MongoDBPlugin('mongodb'); diff --git a/packages/opentelemetry-plugin-mongodb-core/src/types.ts b/packages/opentelemetry-plugin-mongodb/src/types.ts similarity index 88% rename from packages/opentelemetry-plugin-mongodb-core/src/types.ts rename to packages/opentelemetry-plugin-mongodb/src/types.ts index 3c8b33b542..396517471c 100644 --- a/packages/opentelemetry-plugin-mongodb-core/src/types.ts +++ b/packages/opentelemetry-plugin-mongodb/src/types.ts @@ -20,18 +20,23 @@ export type MongoInternalCommand = { createIndexes: boolean; count: boolean; ismaster: boolean; + indexes?: unknown[]; query?: { [key: string]: unknown }; q?: { [key: string]: unknown }; }; -// -// https://github.com/mongodb-js/mongodb-core/blob/master/lib/topologies/server.js#L117 + +// https://github.com/mongodb/node-mongodb-native/blob/master/lib/topologies/server.js#L179 export type MongoInternalTopology = { s?: { + // those are for mongodb@3 options?: { host?: string; port?: number; servername?: string; }; + // those are for mongodb@2 + host?: string; + port?: number; }; }; diff --git a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts b/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts similarity index 99% rename from packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts rename to packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts index b0f4ee15fc..7572a747d9 100644 --- a/packages/opentelemetry-plugin-mongodb-core/test/mongodb.test.ts +++ b/packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts @@ -77,7 +77,7 @@ function assertSpans( assert.strictEqual(mongoSpan.kind, expectedKind); assert.strictEqual( mongoSpan.attributes[AttributeNames.COMPONENT], - 'mongodb-core' + 'mongodb' ); assert.strictEqual( mongoSpan.attributes[AttributeNames.PEER_HOSTNAME], diff --git a/packages/opentelemetry-plugin-mongodb-core/tsconfig.json b/packages/opentelemetry-plugin-mongodb/tsconfig.json similarity index 100% rename from packages/opentelemetry-plugin-mongodb-core/tsconfig.json rename to packages/opentelemetry-plugin-mongodb/tsconfig.json diff --git a/packages/opentelemetry-plugin-mongodb-core/tslint.json b/packages/opentelemetry-plugin-mongodb/tslint.json similarity index 100% rename from packages/opentelemetry-plugin-mongodb-core/tslint.json rename to packages/opentelemetry-plugin-mongodb/tslint.json