aspecto-opentelemetry-instrumentation-mocha
TypeScript icon, indicating that this package has built-in type declarations

0.0.9-alpha.0 • Public • Published

OpenTelemetry mocha Instrumentation for Node.js

NPM version

This module is a mocha root hook plugin and reporter which, in the presence of an installed open-telemetry SDK, provides automatic instrumentation for the mocha testing framework.

Installation

npm install --save opentelemetry-instrumentation-mocha

Supported Versions

This instrumentation uses root hook plugins which are available from mocha ^8.0.0

Usage

For opentelemetry integration to work, you need to configure your mocha run to use otel-plugin and otel-reporter.

  • otel-plugin - takes care of setting the otel context during the execution of the test, which create nested spans in the same trace as the test. This is done via the --require option for mocha.
  • otel-reporter - creates a span for each test, add relevant attributes and status. Reporter is registered via the --reporter option for mocha. Since there can only be one reporter, you might want to use mocha-multi-reporters so you'll get the run report as you're used to.

CLI

mocha --require ./node_modules/opentelemetry-instrumentation-mocha/dist/src/otel-plugin.js --reporter ./node_modules/opentelemetry-instrumentation-mocha/dist/src/otel-reporter.js

package.json

  "mocha": {
    "require": "opentelemetry-instrumentation-mocha",
    "reporter": "./node_modules/opentelemetry-instrumentation-mocha/dist/src/otel-reporter.js"
  }

If you already requireing a plugin, you can use JSON array to use multi plugins:

  "mocha": {
    "require": ["some-other-plugin", "opentelemetry-instrumentation-mocha"],
    "reporter": "./node_modules/opentelemetry-instrumentation-mocha/dist/src/otel-reporter.js"
  }

For reporter, it is not possible to specify multiple values. Setting otel-reporter will override the default reporter which means you will not get test run reports to you console (or any other report you are using). You can use mocha-multi-reporters for that.

Readme

Keywords

Package Sidebar

Install

npm i aspecto-opentelemetry-instrumentation-mocha

Weekly Downloads

0

Version

0.0.9-alpha.0

License

Apache-2.0

Unpacked Size

22.9 kB

Total Files

15

Last publish

Collaborators

  • mottibec