# @aspecto/opentelemetry-instrumentation-mongodb

> Aspecto fork of OpenTelemetry mongodb automatic instrumentation package.

Latest version **0.2.0** (published 2024-05-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @aspecto/opentelemetry-instrumentation-mongodb
pnpm add @aspecto/opentelemetry-instrumentation-mongodb
yarn add @aspecto/opentelemetry-instrumentation-mongodb
bun add @aspecto/opentelemetry-instrumentation-mongodb
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2024-05-21 |
| First published | 2021-05-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 2 |
| Unpacked size | 96.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3465 |
| Author | OpenTelemetry Authors |
| Maintainers | habmic, amir.aspecto, aspecto-release-bot, andriy-aspecto, yanivd |
| Keywords | opentelemetry, mongodb, nodejs, tracing, profiling, plugin |

## Links

- npm: https://www.npmjs.com/package/@aspecto/opentelemetry-instrumentation-mongodb
- Repository: https://github.com/open-telemetry/opentelemetry-js
- Homepage: https://github.com/open-telemetry/opentelemetry-js#readme
- Issues: https://github.com/open-telemetry/opentelemetry-js/issues
- npm.io page: https://npm.io/package/@aspecto/opentelemetry-instrumentation-mongodb

## Dependencies (2)

- [@opentelemetry/instrumentation](https://npm.io/package/@opentelemetry/instrumentation.md) 0.51.1
- [@opentelemetry/semantic-conventions](https://npm.io/package/@opentelemetry/semantic-conventions.md) 1.24.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2024-05-21
- 0.0.0-2024-05-21--09-06 (alpha) — 2024-05-21
- 0.0.0-2024-05-16--14-39 — 2024-05-16
- 0.1.0 — 2023-10-17
- 0.0.142 — 2023-09-21
- 0.0.0-2023-07-30--08-42 — 2023-07-30
- 0.0.0-2023-07-27--11-15 — 2023-07-27
- 0.0.140 — 2023-03-01
- 0.0.0-2023-03-01--13-22 — 2023-03-01
- 0.0.139 — 2022-11-30
- 0.0.0-2022-11-24--17-44 — 2022-11-24
- 0.0.138 — 2022-11-02
- 0.0.0-2022-11-02--07-46 — 2022-11-02
- 0.0.137 — 2022-07-12
- 0.0.0-2022-07-11--10-54 — 2022-07-11
- … 42 more at https://npm.io/package/@aspecto/opentelemetry-instrumentation-mongodb/versions

## README

# 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 is a fork of the instrumentation, to add features required by aspecto until they are merged into the main repo and published.

This module provides automatic instrumentation for [`mongodb`](https://github.com/mongodb/node-mongodb-native).

For automatic instrumentation see the
[@opentelemetry/sdk-trace-node](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-node) package.

## Installation

```bash
npm install --save @opentelemetry/instrumentation-mongodb
```
### Supported Versions
 - `'>=3.3 <4`

## Usage

OpenTelemetry Mongodb Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.

To load a specific instrumentation (**mongodb** in this case), specify it in the Node Tracer's configuration.

```javascript
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');

const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();

const mongodbInstrumentation = new MongoDBInstrumentation({
  // see under for available configuration
});
```

### Mongo instrumentation Options

Mongodb instrumentation has few options available to choose from. You can set the following:

| Options | Type | Description |
| ------- | ---- | ----------- |
| `dbStatementSerializer` | `DbStatementSerializer` | Mongodb instrumentation will serialize `db.statement` using the specified function. |
| `responseHook` | `MongoDbResponseCustomAttributesFunction` | Hook called before response is returned, which allows to add custom attributes to span. |
| `moduleVersionAttributeName` | `string` | If passed, a span attribute will be added to all spans with key of the provided `moduleVersionAttributeName` and value of the patched module version. |
| `requireParentSpan` | `boolean` | Require parent to create mongodb span, default when unset is true |
| `ignoreIsMasterCommand` | `boolean` | If true, a span for periodical `isMaster` command will not be generated, default when unset is false. The mongodb client library periodically re-run the `isMaster` command to detect the replica set configuration changes. |
| `aggregateGetMoreOperations` | `boolean` | If true, a span for a `getMore` command will not be generated, default when unset is false. |
| `aggregateGetMoreResponseHook` | `MongoDbGetMoreResponseAggregateFunction` | Hook for aggregate a response payload of a GetMore operation, allows to add custom attributes to span. |

## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us on [gitter][gitter-url]

## License

Apache 2.0 - See [LICENSE][license-url] for more information.

[gitter-image]: https://badges.gitter.im/open-telemetry/opentelemetry-js.svg
[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-contrib/blob/main/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-contrib/status.svg?path=packages/opentelemetry-instrumentation-mongodb
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=packages%2Fopentelemetry-instrumentation-mongodb
[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib/dev-status.svg?path=packages/opentelemetry-instrumentation-mongodb
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-contrib?path=packages%2Fopentelemetry-instrumentation-mongodb&type=dev

---
_Source: https://npm.io/package/@aspecto/opentelemetry-instrumentation-mongodb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
