diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f7a3a45983..49f2fb39df7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -172,6 +172,12 @@ jobs: root: packages/opentelemetry-types/docs paths: - out + - run: + name: Install minimal modules to lint examples + command: npm i -D eslint eslint-plugin-import eslint-config-airbnb-base + - run: + name: Lint examples + command: npm run lint-examples docs-deploy: docker: - image: node:12 @@ -236,7 +242,7 @@ workflows: - lint_&_docs filters: tags: - only: /^v\d+\.\d+\.0$/ + only: /^v\d+\.\d+\.\d$/ branches: ignore: /.*/ - node8 diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b7e8c2d27..873d464157f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file. ## Unreleased +## 0.3.3 + +Released 2020-01-22 + +#### :rocket: (Enhancement) +* `opentelemetry-core`, `opentelemetry-exporter-collector`, `opentelemetry-exporter-zipkin`, `opentelemetry-node`, `opentelemetry-plugin-dns`, `opentelemetry-plugin-document-load`, `opentelemetry-plugin-grpc`, `opentelemetry-plugin-http`, `opentelemetry-plugin-https`, `opentelemetry-plugin-ioredis`, `opentelemetry-plugin-mongodb`, `opentelemetry-plugin-mysql`, `opentelemetry-plugin-postgres`, `opentelemetry-plugin-redis`, `opentelemetry-plugin-xml-http-request`, `opentelemetry-shim-opentracing`, `opentelemetry-tracing`, `opentelemetry-types`, `opentelemetry-web` + * [#582](https://github.com/open-telemetry/opentelemetry-js/pull/582) Named Tracers / Tracer Registry +* `opentelemetry-node`, `opentelemetry-plugin-postgres` + * [#662](https://github.com/open-telemetry/opentelemetry-js/pull/662) feat: add pg-pool to default list of instrumented plugins + * [#708](https://github.com/open-telemetry/opentelemetry-js/pull/708) Simplify and speed up trace context parsing +* `opentelemetry-metrics` + * [#700](https://github.com/open-telemetry/opentelemetry-js/pull/700) implement named meter + +#### :sparkles: (Feature) +* `opentelemetry-propagator-jaeger` + * [#701](https://github.com/open-telemetry/opentelemetry-js/pull/701) add jaeger http trace format +* `opentelemetry-exporter-stackdriver-trace` + * [#648](https://github.com/open-telemetry/opentelemetry-js/pull/648) Stackdriver Trace exporter + +#### :books: (Refine Doc) + * [#673](https://github.com/open-telemetry/opentelemetry-js/pull/673) chore(getting-started): Added a TypeScript version for Getting Started Guide + +#### :bug: (Bug Fix) +* `opentelemetry-plugin-ioredis` + * [#714](https://github.com/open-telemetry/opentelemetry-js/pull/714) fix: return module exports from ioredis + ## 0.3.2 Released 2020-01-03 diff --git a/README.md b/README.md index 1cc87cc19bf..525e3535db2 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,19 @@ This is the JavaScript version of [OpenTelemetry](https://opentelemetry.io/), a > This project is currently in Alpha stage. Its APIs can change at any time and it is not intended to be used in production scenarios! +## Documentation + +For detailed documentation of the OpenTelemetry API, see [the documentation][docs]. + ## Quick start -To get started tracing your own application, see the [Getting Started Guide](getting-started/README.md). +### Application Owner + +To get started tracing your own application, see the [Getting Started Guide](getting-started/README.md). For more information about automatic instrumentation see [@opentelemetry/node][otel-node], which provides auto-instrumentation for Node.js applications. If the automatic instrumentation does not suit your needs, or you would like to create manual traces, see [@opentelemetry/tracing][otel-tracing] -For more information, see [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing) for an SDK that supports creating traces through manual instrumentation or [@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node) which provides auto-instrumentation for Node.js applications. +### Library Author + +If you are a library author looking to build OpenTelemetry into your library, please see [the documentation][docs]. As a library author, it is important that you only depend on properties and methods published on the public API. If you use any properties or methods from the SDK that are not officially a part of the public API, your library may break if an [Application Owner](#application-owner) uses a different SDK implementation. ## Release Schedule @@ -68,7 +76,7 @@ Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry - [Roch Devost](https://github.com/rochdev), DataDog - [Brandon Gonzalez](https://github.com/bg451), LightStep -- [Olivier Albertini](https://github.com/OlivierAlbertini), VilledeMontreal +- [Olivier Albertini](https://github.com/OlivierAlbertini), Ville de Montréal - [Valentin Marchaud](https://github.com/vmarchaud), Open Source Contributor - [Mark Wolff](https://github.com/markwolff), Microsoft - [Bartlomiej Obecny](https://github.com/obecny), LightStep @@ -88,51 +96,51 @@ Maintainers ([@open-telemetry/js-maintainers](https://github.com/orgs/open-telem | Package | Description | | ----------------------- | -----------------| -| [@opentelemetry/types](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-types) | This package provides TypeScript interfaces and enums for the OpenTelemetry core trace and metrics model. It is intended for use both on the server and in the browser. | -| [@opentelemetry/core](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-core) | This package provides default and no-op implementations of the OpenTelemetry types for trace and metrics. It's intended for use both on the server and in the browser. | +| [@opentelemetry/types][otel-types] | This package provides TypeScript interfaces and enums for the OpenTelemetry core trace and metrics model. It is intended for use both on the server and in the browser. | +| [@opentelemetry/core][otel-core] | This package provides default and no-op implementations of the OpenTelemetry types for trace and metrics. It's intended for use both on the server and in the browser. | ### Implementation / SDKs | Package | Description | | ----------------------- | -----------------| -| [@opentelemetry/tracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing) | This module provides a full control over instrumentation and span creation. It doesn't load [`async_hooks`](https://nodejs.org/api/async_hooks.html) or any instrumentation plugin by default. It is intended for use both on the server and in the browser. | -| [@opentelemetry/metrics](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics) | This module provides instruments and meters for reporting of time series data. | -| [@opentelemetry/node](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node) | This module provides automatic tracing for Node.js applications. It is intended for use on the server only. | -| [@opentelemetry/web](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-web) | This module provides automated instrumentation and tracing for Web applications. It is intended for use in the browser only. | -| [@opentelemetry/base](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-base) | This package provides base code for the SDK packages (tracing and metrics). | +| [@opentelemetry/tracing][otel-tracing] | This module provides a full control over instrumentation and span creation. It doesn't load [`async_hooks`](https://nodejs.org/api/async_hooks.html) or any instrumentation plugin by default. It is intended for use both on the server and in the browser. | +| [@opentelemetry/metrics][otel-metrics] | This module provides instruments and meters for reporting of time series data. | +| [@opentelemetry/node][otel-node] | This module provides automatic tracing for Node.js applications. It is intended for use on the server only. | +| [@opentelemetry/web][otel-web] | This module provides automated instrumentation and tracing for Web applications. It is intended for use in the browser only. | +| [@opentelemetry/base][otel-base] | This package provides base code for the SDK packages (tracing and metrics). | ### Exporters OpenTelemetry is vendor-agnostic and can upload data to any backend with various exporter implementations. Even though, OpenTelemetry provides support for many backends, vendors/users can also implement their own exporters for proprietary and unofficially supported backends. Currently, OpenTelemetry supports: #### Trace Exporters -- [@opentelemetry/exporter-jaeger](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-jaeger) -- [@opentelemetry/exporter-zipkin](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-zipkin) -- [@opentelemetry/exporter-stackdriver-trace](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-stackdriver-trace) -- [@opentelemetry/exporter-collector](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-collector) +- [@opentelemetry/exporter-jaeger][otel-exporter-jaeger] +- [@opentelemetry/exporter-zipkin][otel-exporter-zipkin] +- [@opentelemetry/exporter-stackdriver-trace][otel-exporter-stackdriver-trace] +- [@opentelemetry/exporter-collector][otel-exporter-collector] #### Metric Exporters -- [@opentelemetry/exporter-prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-prometheus) +- [@opentelemetry/exporter-prometheus][otel-exporter-prometheus] ### Plugins OpenTelemetry can collect tracing data automatically using plugins. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for: #### Node Plugins -- [@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](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) -- [@opentelemetry/plugin-redis](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-redis) -- [@opentelemetry/plugin-ioredis](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-ioredis) -- [@opentelemetry/plugin-dns](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-dns) - By default, this plugin is not loaded [#612](https://github.com/open-telemetry/opentelemetry-js/issues/612) +- [@opentelemetry/plugin-grpc][otel-plugin-grpc] +- [@opentelemetry/plugin-http][otel-plugin-http] +- [@opentelemetry/plugin-https][otel-plugin-https] +- [@opentelemetry/plugin-mongodb][otel-plugin-mongodb] +- [@opentelemetry/plugin-mysql][otel-plugin-mysql] +- [@opentelemetry/plugin-pg][otel-plugin-pg] +- [@opentelemetry/plugin-pg-pool][otel-plugin-pg-pool] +- [@opentelemetry/plugin-redis][otel-plugin-redis] +- [@opentelemetry/plugin-ioredis][otel-plugin-ioredis] +- [@opentelemetry/plugin-dns][otel-plugin-dns] - By default, this plugin is not loaded [#612](https://github.com/open-telemetry/opentelemetry-js/issues/612) #### Web Plugins -- [@opentelemetry/plugin-document-load](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-document-load) -- [@opentelemetry/plugin-xml-http-request](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-xml-http-request) +- [@opentelemetry/plugin-document-load][otel-plugin-document-load] +- [@opentelemetry/plugin-xml-http-request][otel-plugin-xml-http-request] To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, you can [write a plugin yourself](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/plugin-guide.md). @@ -140,7 +148,7 @@ To request automatic tracing support for a module not on this list, please [file | Package | Description | | ----------------------- | -----------------| -| [@opentelemetry/shim-opentracing](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-shim-opentracing) | OpenTracing shim allows existing OpenTracing instrumentation to report to OpenTelemetry | +| [@opentelemetry/shim-opentracing][otel-shim-opentracing] | OpenTracing shim allows existing OpenTracing instrumentation to report to OpenTelemetry | ## Useful links @@ -161,3 +169,31 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [codecov-image]: https://codecov.io/gh/open-telemetry/opentelemetry-js/branch/master/graph/badge.svg [codecov-url]: https://codecov.io/gh/open-telemetry/opentelemetry-js/branch/master/ [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat + +[docs]: https://open-telemetry.github.io/opentelemetry-js + +[otel-base]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-base +[otel-exporter-collector]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-collector +[otel-exporter-jaeger]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-jaeger +[otel-exporter-prometheus]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-prometheus +[otel-exporter-stackdriver-trace]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-stackdriver-trace +[otel-exporter-zipkin]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-zipkin +[otel-metrics]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics +[otel-node]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node +[otel-plugin-dns]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-dns +[otel-plugin-document-load]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-document-load +[otel-plugin-grpc]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-grpc +[otel-plugin-http]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-http +[otel-plugin-https]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-https +[otel-plugin-ioredis]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-ioredis +[otel-plugin-mongodb]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mongodb +[otel-plugin-mysql]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mysql +[otel-plugin-pg-pool]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool +[otel-plugin-pg]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg +[otel-plugin-redis]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-redis +[otel-plugin-xml-http-request]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-xml-http-request +[otel-shim-opentracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-shim-opentracing +[otel-tracing]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-tracing +[otel-web]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-web +[otel-types]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-types +[otel-core]: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-core diff --git a/RELEASING.md b/RELEASING.md index a2073a8fee2..68b2f6c9567 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -2,6 +2,34 @@ This document explains how to publish all OT modules at version x.y.z. Ensure that you’re following semver when choosing a version number. +Release Process: + +* [Update to latest locally](#update-to-latest-locally) +* [Create a new branch](#create-a-new-branch) +* [Prepare each package for release](#prepare-each-package-for-release) +* [Use the Changelog to create a GitHub Release](#use-the-changelog-to-create-a-github-release) +* [Create a new PR](#create-a-new-pr) +* [Merge and pull](#merge-and-pull) +* [Publish all packages](#publish-all-packages) +* [Publish the GitHub Release](#publish-the-github-release) +* [Update CHANGELOG](#update-changelog) + +## Update to latest locally + +Use `git fetch` and `git checkout origin/master` to ensure you’re on the latest commit. Make sure you have no unstaged changes. Ideally, also use `git clean -dfx` to remove all ignored and untracked files. + +## Create a new branch + +Create a new branch called `x.y.z-proposal` from the current commit. + +## Prepare each package for release + +Decide on the next `major.minor.patch` release number based on [semver](http://semver.org/) guidelines. + +* Use `npm install` command to initialize all package directories +* Use `lerna publish --skip-npm --no-git-tag-version --no-push` to bump the version in all `package.json` +* Use `npm run bootstrap` to generate latest `version.ts` files + ## Use the Changelog to create a GitHub Release ### Generate the changelog with lerna @@ -9,7 +37,7 @@ This document explains how to publish all OT modules at version x.y.z. Ensure th Since we use `lerna`, we can use [lerna-changelog](https://github.com/lerna/lerna-changelog#lerna-changelog) #### How to use -Pass your [github token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) to generate the changelog automatically. +Pass your [github token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) to generate the changelog automatically. For security reasons, when you create a Github token, select the permissions: under **repo**, select **Access public repositories**, **commit status**. In your terminal, execute the following command: @@ -41,3 +69,43 @@ GITHUB_AUTH=xxxxx lerna-changelog --from=v1.0.0 --to=v2.0.0 #### Update Changelog file From what `lerna-changelog` has generated, starts new Unreleased label. Follow the example set by recent Released label. + +On [GitHub Releases](https://github.com/open-telemetry/opentelemetry-js/releases), follow the example set by recent releases to populate a summary of changes, as well as a list of commits that were applied since the last release. Save it as a draft, don’t publish it. Don’t forget the tag -- call it `vx.y.z` and leave it pointing at `master` for now (this can be changed as long as the GitHub release isn’t published). + +## Create a new PR + +Create a pull request titled `chore: x.y.z release proposal`. The commit body should just be a link to the draft notes. Someone who can access draft notes should approve it, looking in particular for test passing, and whether the draft notes are satisfactory. + +## Merge and pull + +Merge the PR, and pull the changes locally (using the commands in the first step). Ensure that `chore: x.y.z release proposal` is the most recent commit. + +## Publish all packages + +Go into each directory and use `npm publish` (requires permissions) to publish the package. You can use the following script to automate this. + +```bash +#!/bin/bash + +for dir in $(ls packages); do + pushd packages/$dir + npm publish + popd +done +``` + +Check your e-mail and make sure the number of “you’ve published this module” emails matches the number you expect. + +## Publish the GitHub Release +Publish the GitHub release, ensuring that the tag points to the newly landed commit corresponding to release proposal `x.y.z`. + +## Update CHANGELOG + +* After releasing is done, update the [CHANGELOG.md](https://github.com/open-telemetry/opentelemetry-js/blob/master/CHANGELOG.md) and start new Unreleased label. +* Create a new commit with the exact title: `Post Release: update CHANGELOG.md`. +* Go through PR review and merge it to GitHub master branch. + + +## Known Issues + +* The `examples/` and `getting-started/` folders are not part of lerna packages, we need to manually bump the version in `package.json`. diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 00000000000..0f1e81a9fa2 --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,67 @@ +# Benchmarks + +## How to run + +To run your benchmark, just: +```sh +$ npm run bench +``` + +The minimum sample size is set to 10 to perform statistical analysis on benchmark, you can re-configure that in `benchmark.js`. + +> NOTE: If you're interested in writing benchmark for other APIs, please write a benchmark in the `benchmark/index.js` module. Please refer to the `benchmark/tracer.js` or `benchmark/propagator.js` for more comprehensive examples. + +## Results + +### `v0.3.3` release + +``` +Beginning NoopTracerRegistry Benchmark... + 5 tests completed. + + #startSpan x 731,516,636 ops/sec ±2.57% (20 runs sampled) + #startSpan:parent x 744,353,590 ops/sec ±3.03% (20 runs sampled) + #startSpan with attribute x 737,451,332 ops/sec ±3.75% (20 runs sampled) + #startSpan with 30 attributes x 1,658,688 ops/sec ±1.23% (20 runs sampled) + #startSpan with 100 attributes x 535,082 ops/sec ±1.55% (20 runs sampled) + +Beginning BasicTracerRegistry Benchmark... + 5 tests completed. + + #startSpan x 80,633 ops/sec ±3.57% (20 runs sampled) + #startSpan:parent x 56,228 ops/sec ±2.18% (20 runs sampled) + #startSpan with attribute x 86,710 ops/sec ±1.80% (20 runs sampled) + #startSpan with 30 attributes x 36,331 ops/sec ±1.29% (20 runs sampled) + #startSpan with 100 attributes x 3,549 ops/sec ±3.59% (20 runs sampled) + +Beginning BasicTracerRegistry with SimpleSpanProcessor Benchmark... + 5 tests completed. + + #startSpan x 74,539 ops/sec ±4.49% (20 runs sampled) + #startSpan:parent x 48,953 ops/sec ±4.98% (20 runs sampled) + #startSpan with attribute x 79,686 ops/sec ±2.54% (20 runs sampled) + #startSpan with 30 attributes x 26,491 ops/sec ±13.68% (20 runs sampled) + #startSpan with 100 attributes x 2,464 ops/sec ±19.64% (20 runs sampled) + +Beginning BasicTracerRegistry with BatchSpanProcessor Benchmark... + 5 tests completed. + + #startSpan x 74,974 ops/sec ±3.57% (20 runs sampled) + #startSpan:parent x 42,390 ops/sec ±20.68% (20 runs sampled) + #startSpan with attribute x 76,497 ops/sec ±2.93% (20 runs sampled) + #startSpan with 30 attributes x 33,042 ops/sec ±2.03% (20 runs sampled) + #startSpan with 100 attributes x 3,459 ops/sec ±4.56% (20 runs sampled) + + +Beginning B3Format Benchmark... + 2 tests completed. + + #Inject x 5,086,366 ops/sec ±3.18% (100 runs sampled) + #Extract x 4,859,557 ops/sec ±3.80% (100 runs sampled) + +Beginning HttpTraceContext Benchmark... + 2 tests completed. + + #Inject x 13,660,710 ops/sec ±1.84% (100 runs sampled) + #Extract x 1,692,010 ops/sec ±0.83% (100 runs sampled) +``` diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index cb71c03a873..8bc04a47b5a 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -4,10 +4,9 @@ const Benchmark = require('benchmark'); const benchmarks = require('beautify-benchmark'); Benchmark.options.maxTime = 0; -// @todo : Change it to between 50-100 or keep it random. -Benchmark.options.minSamples = 10; -module.exports = () => { +module.exports = (minSamples) => { + Benchmark.options.minSamples = minSamples; const suite = new Benchmark.Suite(); return suite diff --git a/benchmark/index.js b/benchmark/index.js index ebf5aff932b..745b93b75a6 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -3,5 +3,5 @@ const execSync = require('child_process').execSync; const exec = cmd => execSync(cmd, { stdio: [0, 1, 2] }); -exec('node benchmark/tracer'); -exec('node benchmark/propagator'); +exec('node benchmark/tracer.js'); +exec('node benchmark/propagator.js'); diff --git a/benchmark/propagator.js b/benchmark/propagator.js index f28a78a3026..0c5c137c26d 100644 --- a/benchmark/propagator.js +++ b/benchmark/propagator.js @@ -1,7 +1,7 @@ 'use strict'; const benchmark = require('./benchmark'); -const opentelemetry = require('@opentelemetry/core'); +const opentelemetry = require('../packages/opentelemetry-core'); const setups = [ { @@ -26,7 +26,7 @@ const setups = [ for (const setup of setups) { console.log(`Beginning ${setup.name} Benchmark...`); const propagator = setup.propagator; - const suite = benchmark() + const suite = benchmark(100) .add('#Inject', function () { propagator.inject({ traceId: 'd4cda95b652f4a1592b449d5929fda1b', diff --git a/benchmark/tracer.js b/benchmark/tracer.js index 83700b0171d..a1a6c360cdf 100644 --- a/benchmark/tracer.js +++ b/benchmark/tracer.js @@ -1,28 +1,34 @@ 'use strict'; const benchmark = require('./benchmark'); -const opentelemetry = require('@opentelemetry/core'); -const { BasicTracerRegistry, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { NodeTracerRegistry } = require('@opentelemetry/node'); +const opentelemetry = require('../packages/opentelemetry-core'); +const { BasicTracerRegistry, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('../packages/opentelemetry-tracing'); -const exporter = new InMemorySpanExporter(); const logger = new opentelemetry.NoopLogger(); const setups = [ + { + name: 'NoopTracerRegistry', + registry: opentelemetry.getTracerRegistry() + }, { name: 'BasicTracerRegistry', registry: new BasicTracerRegistry({ logger }) }, { - name: 'NodeTracerRegistry', - registry: new NodeTracerRegistry({ logger }) + name: 'BasicTracerRegistry with SimpleSpanProcessor', + registry: getRegistry(new SimpleSpanProcessor(new InMemorySpanExporter())) + }, + { + name: 'BasicTracerRegistry with BatchSpanProcessor', + registry: getRegistry(new BatchSpanProcessor(new InMemorySpanExporter())) } ]; for (const setup of setups) { console.log(`Beginning ${setup.name} Benchmark...`); const tracer = setup.registry.getTracer("benchmark"); - const suite = benchmark() + const suite = benchmark(20) .add('#startSpan', function () { const span = tracer.startSpan('op'); span.end(); @@ -51,25 +57,14 @@ for (const setup of setups) { span.setAttribute('attr-key-' + j, 'attr-value-' + j); } span.end(); - }) - .add('#startSpan with SimpleSpanProcessor', function () { - const simpleSpanProcessor = new SimpleSpanProcessor(exporter); - - registry.addSpanProcessor(simpleSpanProcessor); - const span = tracer.startSpan('op'); - span.end(); - - simpleSpanProcessor.shutdown(); - }) - .add('#startSpan with BatchSpanProcessor', function () { - const batchSpanProcessor = new BatchSpanProcessor(exporter); - - registry.addSpanProcessor(batchSpanProcessor); - const span = tracer.startSpan('op'); - span.end(); - batchSpanProcessor.shutdown(); }); // run async suite.run({ async: false }); } +function getRegistry(processor) { + const registry = new BasicTracerRegistry({ logger }); + registry.addSpanProcessor(processor); + return registry; +} + diff --git a/examples/.eslintrc b/examples/.eslintrc new file mode 100644 index 00000000000..5feabb97f57 --- /dev/null +++ b/examples/.eslintrc @@ -0,0 +1,16 @@ +{ + "env": { + "node": true + }, + "extends": "airbnb-base", + "parserOptions": { + "sourceType": "script" + }, + "rules": { + "strict": ["error", "global"], + "no-use-before-define": ["error", "nofunc"], + "no-console": "off", + "import/no-unresolved": "off", + "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] + } +} diff --git a/examples/basic-tracer-node/index.js b/examples/basic-tracer-node/index.js index 086d1fe1585..e16b95b8988 100644 --- a/examples/basic-tracer-node/index.js +++ b/examples/basic-tracer-node/index.js @@ -1,11 +1,13 @@ +'use strict'; + const opentelemetry = require('@opentelemetry/core'); const { BasicTracerRegistry, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorExporter } = require('@opentelemetry/exporter-collector'); const options = { - serviceName: 'basic-service' + serviceName: 'basic-service', }; // Initialize an exporter depending on how we were started @@ -27,15 +29,15 @@ registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -const tracer = opentelemetry.getTracer('example-basic-tracer-node') +const tracer = opentelemetry.getTracer('example-basic-tracer-node'); // Create a span. A span must be closed. -const span = tracer.startSpan('main'); -for (let i = 0; i < 10; i++) { - doWork(span); +const parentSpan = tracer.startSpan('main'); +for (let i = 0; i < 10; i += 1) { + doWork(parentSpan); } // Be sure to end the span. -span.end(); +parentSpan.end(); // flush and close the connection. exporter.shutdown(); @@ -44,11 +46,13 @@ function doWork(parent) { // Start another span. In this example, the main method already started a // span, so that'll be the parent span, and this will be a child span. const span = tracer.startSpan('doWork', { - parent: parent + parent, }); // simulate some random work. - for (let i = 0; i <= Math.floor(Math.random() * 40000000); i++) { } + for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) { + // empty + } // Set attributes to the span. span.setAttribute('key', 'value'); diff --git a/examples/basic-tracer-node/multi_exporter.js b/examples/basic-tracer-node/multi_exporter.js index 309daf4311d..aa8478dfa2c 100644 --- a/examples/basic-tracer-node/multi_exporter.js +++ b/examples/basic-tracer-node/multi_exporter.js @@ -1,39 +1,44 @@ +'use strict'; + const opentelemetry = require('@opentelemetry/core'); const { BasicTracerRegistry, BatchSpanProcessor, SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorExporter } = require('@opentelemetry/exporter-collector'); const registry = new BasicTracerRegistry(); -const zipkinExporter = new ZipkinExporter({serviceName: 'basic-service'}); +const zipkinExporter = new ZipkinExporter({ serviceName: 'basic-service' }); const jaegerExporter = new JaegerExporter({ serviceName: 'basic-service', }); -const collectorExporter = new CollectorExporter({serviceName: 'basic-service'}); +const collectorExporter = new CollectorExporter({ serviceName: 'basic-service' }); // It is recommended to use this BatchSpanProcessor for better performance // and optimization, especially in production. registry.addSpanProcessor(new BatchSpanProcessor(zipkinExporter, { - bufferSize: 10 // This is added for example, default size is 100. + // This is added for example, default size is 100. + bufferSize: 10, })); + +const tracer = opentelemetry.getTracer('default'); + tracer.addSpanProcessor(new BatchSpanProcessor(jaegerExporter), { - bufferSize: 10 + bufferSize: 10, }); registry.addSpanProcessor(new SimpleSpanProcessor(collectorExporter)); // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -const tracer = opentelemetry.getTracer('default'); // Create a span. A span must be closed. -const span = tracer.startSpan('main'); -for (let i = 0; i < 10; i++) { - doWork(span); +const parentSpan = tracer.startSpan('main'); +for (let i = 0; i < 10; i += 1) { + doWork(parentSpan); } // Be sure to end the span. -span.end(); +parentSpan.end(); // flush and close the connection. zipkinExporter.shutdown(); @@ -44,11 +49,13 @@ function doWork(parent) { // Start another span. In this example, the main method already started a // span, so that'll be the parent span, and this will be a child span. const span = tracer.startSpan('doWork', { - parent: parent + parent, }); // simulate some random work. - for (let i = 0; i <= Math.floor(Math.random() * 40000000); i++) { } + for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) { + // empty + } // Set attributes to the span. span.setAttribute('key', 'value'); diff --git a/examples/basic-tracer-node/package.json b/examples/basic-tracer-node/package.json index b375713a447..4968965c424 100644 --- a/examples/basic-tracer-node/package.json +++ b/examples/basic-tracer-node/package.json @@ -1,7 +1,7 @@ { "name": "example-basic-tracer-node", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of using @opentelemetry/tracing in Node.js", "main": "index.js", "scripts": { @@ -30,11 +30,11 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-collector": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-collector": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/examples/dns/client.js b/examples/dns/client.js index 317b5b9e466..1ea52d6ce02 100644 --- a/examples/dns/client.js +++ b/examples/dns/client.js @@ -1,42 +1,34 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (DNS in this case). - */ -config.setupTracerAndExporters('dns-client-service'); - +const tracer = require('./tracer')('example-dns'); +// eslint-disable-next-line import/order const dns = require('dns').promises; -const tracer = opentelemetry.getTracer('example-dns'); /** A function which makes a dns lookup and handles response. */ function makeLookup() { - // span corresponds to dns lookup. Here, we have manually created - // the span, which is created to track work that happens outside of the - // dns lookup query. - const span = tracer.startSpan('dnsLookup'); - tracer.withSpan(span, async () => { - try { - await dns.lookup('montreal.ca'); - } catch (error) { - span.setAttributes({ - 'error.name': error.name, - 'error.message': error.message - }); - }finally{ - console.log(`traceid: ${span.context().traceId}`); - span.end(); - } - }); + // span corresponds to dns lookup. Here, we have manually created + // the span, which is created to track work that happens outside of the + // dns lookup query. + const span = tracer.startSpan('dnsLookup'); + tracer.withSpan(span, async () => { + try { + await dns.lookup('montreal.ca'); + } catch (error) { + span.setAttributes({ + 'error.name': error.name, + 'error.message': error.message, + }); + } finally { + console.log(`traceid: ${span.context().traceId}`); + span.end(); + } + }); - // The process must live for at least the interval past any traces that - // must be exported, or some risk being lost if they are recorded after the - // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); + // The process must live for at least the interval past any traces that + // must be exported, or some risk being lost if they are recorded after the + // last export. + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); } makeLookup(); diff --git a/examples/dns/package.json b/examples/dns/package.json index bc2f8c931fb..3f6a5db6374 100644 --- a/examples/dns/package.json +++ b/examples/dns/package.json @@ -1,7 +1,7 @@ { "name": "dns-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of DNS integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -26,12 +26,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-dns": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-dns": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/examples/dns/setup.js b/examples/dns/setup.js deleted file mode 100644 index f5ef407f2ab..00000000000 --- a/examples/dns/setup.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const opentelemetry = require('@opentelemetry/core'); -const { NodeTracerRegistry } = require('@opentelemetry/node'); -const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); -const EXPORTER = process.env.EXPORTER || ''; - -function setupTracerAndExporters(service) { - const registry = new NodeTracerRegistry({ -      plugins: { -          dns: { -            enabled: true, -            path: '@opentelemetry/plugin-dns', - // Avoid dns lookup loop with http zipkin calls - ignoreHostnames: ['localhost'] -        } -      } -  }); - - let exporter; - if (EXPORTER.toLowerCase().startsWith('z')) { - exporter = new ZipkinExporter({ - serviceName: service, - }); - } else { - exporter = new JaegerExporter({ - serviceName: service, - }); - } - - registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); - - // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings - opentelemetry.initGlobalTracerRegistry(registry); -} - -exports.setupTracerAndExporters = setupTracerAndExporters; diff --git a/examples/dns/tracer.js b/examples/dns/tracer.js new file mode 100644 index 00000000000..7a918ec33d7 --- /dev/null +++ b/examples/dns/tracer.js @@ -0,0 +1,40 @@ +'use strict'; + +const opentelemetry = require('@opentelemetry/core'); +const { NodeTracerRegistry } = require('@opentelemetry/node'); +const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); +const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); +const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + +const EXPORTER = process.env.EXPORTER || ''; + +module.exports = (serviceName) => { + const registry = new NodeTracerRegistry({ + plugins: { + dns: { + enabled: true, + path: '@opentelemetry/plugin-dns', + // Avoid dns lookup loop with http zipkin calls + ignoreHostnames: ['localhost'], + }, + }, + }); + + let exporter; + if (EXPORTER.toLowerCase().startsWith('z')) { + exporter = new ZipkinExporter({ + serviceName, + }); + } else { + exporter = new JaegerExporter({ + serviceName, + }); + } + + registry.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings + opentelemetry.initGlobalTracerRegistry(registry); + + return opentelemetry.getTracer(); +}; diff --git a/examples/grpc/client.js b/examples/grpc/client.js index 4bc65bc9764..5541113af78 100644 --- a/examples/grpc/client.js +++ b/examples/grpc/client.js @@ -1,20 +1,12 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (gRPC in this case). - */ -config.setupTracerAndExporters('grpc-client-service'); - +const tracer = require('./tracer')('example-grpc-client'); +// eslint-disable-next-line import/order const grpc = require('grpc'); - const messages = require('./helloworld_pb'); const services = require('./helloworld_grpc_pb'); + const PORT = 50051; -const tracer = opentelemetry.getTracer('example-grpc-client'); /** A function which makes requests and handles response. */ function main() { @@ -26,17 +18,18 @@ function main() { console.log('Client traceId ', span.context().traceId); const client = new services.GreeterClient( `localhost:${PORT}`, - grpc.credentials.createInsecure() + grpc.credentials.createInsecure(), ); const request = new messages.HelloRequest(); let user; if (process.argv.length >= 3) { + // eslint-disable-next-line prefer-destructuring user = process.argv[2]; } else { user = 'world'; } request.setName(user); - client.sayHello(request, function(err, response) { + client.sayHello(request, (err, response) => { span.end(); if (err) throw err; console.log('Greeting:', response.getMessage()); @@ -46,7 +39,7 @@ function main() { // The process must live for at least the interval past any traces that // must be exported, or some risk being lost if they are recorded after the // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); setTimeout(() => { console.log('Completed.'); }, 5000); } diff --git a/examples/grpc/helloworld_grpc_pb.js b/examples/grpc/helloworld_grpc_pb.js index e0eed2ea25d..c32727f8daa 100644 --- a/examples/grpc/helloworld_grpc_pb.js +++ b/examples/grpc/helloworld_grpc_pb.js @@ -1,3 +1,14 @@ +/* eslint-disable no-multi-assign */ +/* eslint-disable prefer-const */ +/* eslint-disable no-var */ +/* eslint-disable vars-on-top */ +/* eslint-disable no-unused-vars */ +/* eslint-disable func-names */ +/* eslint-disable camelcase */ +/* eslint-disable no-undef */ +/* eslint-disable no-new-func */ +/* eslint-disable strict */ + // GENERATED CODE -- DO NOT EDIT! // Original file comments: @@ -15,9 +26,11 @@ // See the License for the specific language governing permissions and // limitations under the License. // + 'use strict'; -var grpc = require('grpc'); -var helloworld_pb = require('./helloworld_pb.js'); + +const grpc = require('grpc'); +const helloworld_pb = require('./helloworld_pb.js'); function serialize_HelloReply(arg) { if (!(arg instanceof helloworld_pb.HelloReply)) { @@ -39,12 +52,12 @@ function serialize_HelloRequest(arg) { function deserialize_HelloRequest(buffer_arg) { return helloworld_pb.HelloRequest.deserializeBinary( - new Uint8Array(buffer_arg) + new Uint8Array(buffer_arg), ); } // The greeting service definition. -var GreeterService = (exports.GreeterService = { +const GreeterService = (exports.GreeterService = { // Sends a greeting sayHello: { path: '/helloworld.Greeter/SayHello', @@ -55,8 +68,8 @@ var GreeterService = (exports.GreeterService = { requestSerialize: serialize_HelloRequest, requestDeserialize: deserialize_HelloRequest, responseSerialize: serialize_HelloReply, - responseDeserialize: deserialize_HelloReply - } + responseDeserialize: deserialize_HelloReply, + }, }); exports.GreeterClient = grpc.makeGenericClientConstructor(GreeterService); diff --git a/examples/grpc/helloworld_pb.js b/examples/grpc/helloworld_pb.js index 1f69378facd..48656aef947 100644 --- a/examples/grpc/helloworld_pb.js +++ b/examples/grpc/helloworld_pb.js @@ -1,3 +1,13 @@ +/* eslint-disable prefer-const */ +/* eslint-disable no-var */ +/* eslint-disable vars-on-top */ +/* eslint-disable no-unused-vars */ +/* eslint-disable func-names */ +/* eslint-disable camelcase */ +/* eslint-disable no-undef */ +/* eslint-disable no-new-func */ +/* eslint-disable strict */ + /** * @fileoverview * @enhanceable @@ -5,9 +15,10 @@ */ // GENERATED CODE -- DO NOT EDIT! -var jspb = require('google-protobuf'); -var goog = jspb; -var global = Function('return this')(); +const jspb = require('google-protobuf'); + +const goog = jspb; +const global = Function('return this')(); goog.exportSymbol('proto.helloworld.HelloReply', null, global); goog.exportSymbol('proto.helloworld.HelloRequest', null, global); @@ -22,7 +33,7 @@ goog.exportSymbol('proto.helloworld.HelloRequest', null, global); * @extends {jspb.Message} * @constructor */ -proto.helloworld.HelloRequest = function(opt_data) { +proto.helloworld.HelloRequest = function (opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; goog.inherits(proto.helloworld.HelloRequest, jspb.Message); @@ -41,8 +52,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ - proto.helloworld.HelloRequest.prototype.toObject = function( - opt_includeInstance + proto.helloworld.HelloRequest.prototype.toObject = function ( + opt_includeInstance, ) { return proto.helloworld.HelloRequest.toObject(opt_includeInstance, this); }; @@ -55,11 +66,13 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * @param {!proto.helloworld.HelloRequest} msg The msg instance to transform. * @return {!Object} */ - proto.helloworld.HelloRequest.toObject = function(includeInstance, msg) { - var f, - obj = { - name: msg.getName() - }; + proto.helloworld.HelloRequest.toObject = function (includeInstance, msg) { + let f; + + + const obj = { + name: msg.getName(), + }; if (includeInstance) { obj.$jspbMessageInstance = msg; @@ -73,9 +86,9 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * @param {jspb.ByteSource} bytes The bytes to deserialize. * @return {!proto.helloworld.HelloRequest} */ -proto.helloworld.HelloRequest.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.helloworld.HelloRequest(); +proto.helloworld.HelloRequest.deserializeBinary = function (bytes) { + const reader = new jspb.BinaryReader(bytes); + const msg = new proto.helloworld.HelloRequest(); return proto.helloworld.HelloRequest.deserializeBinaryFromReader(msg, reader); }; @@ -86,15 +99,15 @@ proto.helloworld.HelloRequest.deserializeBinary = function(bytes) { * @param {!jspb.BinaryReader} reader The BinaryReader to use. * @return {!proto.helloworld.HelloRequest} */ -proto.helloworld.HelloRequest.deserializeBinaryFromReader = function( +proto.helloworld.HelloRequest.deserializeBinaryFromReader = function ( msg, - reader + reader, ) { while (reader.nextField()) { if (reader.isEndGroup()) { break; } - var field = reader.getFieldNumber(); + const field = reader.getFieldNumber(); switch (field) { case 1: var value = /** @type {string} */ (reader.readString()); @@ -114,9 +127,9 @@ proto.helloworld.HelloRequest.deserializeBinaryFromReader = function( * @param {!proto.helloworld.HelloRequest} message * @param {!jspb.BinaryWriter} writer */ -proto.helloworld.HelloRequest.serializeBinaryToWriter = function( +proto.helloworld.HelloRequest.serializeBinaryToWriter = function ( message, - writer + writer, ) { message.serializeBinaryToWriter(writer); }; @@ -125,8 +138,8 @@ proto.helloworld.HelloRequest.serializeBinaryToWriter = function( * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.helloworld.HelloRequest.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); +proto.helloworld.HelloRequest.prototype.serializeBinary = function () { + const writer = new jspb.BinaryWriter(); this.serializeBinaryToWriter(writer); return writer.getResultBuffer(); }; @@ -136,10 +149,10 @@ proto.helloworld.HelloRequest.prototype.serializeBinary = function() { * writing to the given BinaryWriter. * @param {!jspb.BinaryWriter} writer */ -proto.helloworld.HelloRequest.prototype.serializeBinaryToWriter = function( - writer +proto.helloworld.HelloRequest.prototype.serializeBinaryToWriter = function ( + writer, ) { - var f = undefined; + let f; f = this.getName(); if (f.length > 0) { writer.writeString(1, f); @@ -150,9 +163,9 @@ proto.helloworld.HelloRequest.prototype.serializeBinaryToWriter = function( * Creates a deep clone of this proto. No data is shared with the original. * @return {!proto.helloworld.HelloRequest} The clone. */ -proto.helloworld.HelloRequest.prototype.cloneMessage = function() { +proto.helloworld.HelloRequest.prototype.cloneMessage = function () { return /** @type {!proto.helloworld.HelloRequest} */ (jspb.Message.cloneMessage( - this + this, )); }; @@ -160,12 +173,12 @@ proto.helloworld.HelloRequest.prototype.cloneMessage = function() { * optional string name = 1; * @return {string} */ -proto.helloworld.HelloRequest.prototype.getName = function() { +proto.helloworld.HelloRequest.prototype.getName = function () { return /** @type {string} */ (jspb.Message.getFieldProto3(this, 1, '')); }; /** @param {string} value */ -proto.helloworld.HelloRequest.prototype.setName = function(value) { +proto.helloworld.HelloRequest.prototype.setName = function (value) { jspb.Message.setField(this, 1, value); }; @@ -179,7 +192,7 @@ proto.helloworld.HelloRequest.prototype.setName = function(value) { * @extends {jspb.Message} * @constructor */ -proto.helloworld.HelloReply = function(opt_data) { +proto.helloworld.HelloReply = function (opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; goog.inherits(proto.helloworld.HelloReply, jspb.Message); @@ -198,8 +211,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ - proto.helloworld.HelloReply.prototype.toObject = function( - opt_includeInstance + proto.helloworld.HelloReply.prototype.toObject = function ( + opt_includeInstance, ) { return proto.helloworld.HelloReply.toObject(opt_includeInstance, this); }; @@ -212,11 +225,13 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * @param {!proto.helloworld.HelloReply} msg The msg instance to transform. * @return {!Object} */ - proto.helloworld.HelloReply.toObject = function(includeInstance, msg) { - var f, - obj = { - message: msg.getMessage() - }; + proto.helloworld.HelloReply.toObject = function (includeInstance, msg) { + let f; + + + const obj = { + message: msg.getMessage(), + }; if (includeInstance) { obj.$jspbMessageInstance = msg; @@ -230,9 +245,9 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * @param {jspb.ByteSource} bytes The bytes to deserialize. * @return {!proto.helloworld.HelloReply} */ -proto.helloworld.HelloReply.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.helloworld.HelloReply(); +proto.helloworld.HelloReply.deserializeBinary = function (bytes) { + const reader = new jspb.BinaryReader(bytes); + const msg = new proto.helloworld.HelloReply(); return proto.helloworld.HelloReply.deserializeBinaryFromReader(msg, reader); }; @@ -243,15 +258,15 @@ proto.helloworld.HelloReply.deserializeBinary = function(bytes) { * @param {!jspb.BinaryReader} reader The BinaryReader to use. * @return {!proto.helloworld.HelloReply} */ -proto.helloworld.HelloReply.deserializeBinaryFromReader = function( +proto.helloworld.HelloReply.deserializeBinaryFromReader = function ( msg, - reader + reader, ) { while (reader.nextField()) { if (reader.isEndGroup()) { break; } - var field = reader.getFieldNumber(); + const field = reader.getFieldNumber(); switch (field) { case 1: var value = /** @type {string} */ (reader.readString()); @@ -271,9 +286,9 @@ proto.helloworld.HelloReply.deserializeBinaryFromReader = function( * @param {!proto.helloworld.HelloReply} message * @param {!jspb.BinaryWriter} writer */ -proto.helloworld.HelloReply.serializeBinaryToWriter = function( +proto.helloworld.HelloReply.serializeBinaryToWriter = function ( message, - writer + writer, ) { message.serializeBinaryToWriter(writer); }; @@ -282,8 +297,8 @@ proto.helloworld.HelloReply.serializeBinaryToWriter = function( * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.helloworld.HelloReply.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); +proto.helloworld.HelloReply.prototype.serializeBinary = function () { + const writer = new jspb.BinaryWriter(); this.serializeBinaryToWriter(writer); return writer.getResultBuffer(); }; @@ -293,10 +308,10 @@ proto.helloworld.HelloReply.prototype.serializeBinary = function() { * writing to the given BinaryWriter. * @param {!jspb.BinaryWriter} writer */ -proto.helloworld.HelloReply.prototype.serializeBinaryToWriter = function( - writer +proto.helloworld.HelloReply.prototype.serializeBinaryToWriter = function ( + writer, ) { - var f = undefined; + let f; f = this.getMessage(); if (f.length > 0) { writer.writeString(1, f); @@ -307,9 +322,9 @@ proto.helloworld.HelloReply.prototype.serializeBinaryToWriter = function( * Creates a deep clone of this proto. No data is shared with the original. * @return {!proto.helloworld.HelloReply} The clone. */ -proto.helloworld.HelloReply.prototype.cloneMessage = function() { +proto.helloworld.HelloReply.prototype.cloneMessage = function () { return /** @type {!proto.helloworld.HelloReply} */ (jspb.Message.cloneMessage( - this + this, )); }; @@ -317,12 +332,12 @@ proto.helloworld.HelloReply.prototype.cloneMessage = function() { * optional string message = 1; * @return {string} */ -proto.helloworld.HelloReply.prototype.getMessage = function() { +proto.helloworld.HelloReply.prototype.getMessage = function () { return /** @type {string} */ (jspb.Message.getFieldProto3(this, 1, '')); }; /** @param {string} value */ -proto.helloworld.HelloReply.prototype.setMessage = function(value) { +proto.helloworld.HelloReply.prototype.setMessage = function (value) { jspb.Message.setField(this, 1, value); }; diff --git a/examples/grpc/package.json b/examples/grpc/package.json index 72771fa977d..ce521066949 100644 --- a/examples/grpc/package.json +++ b/examples/grpc/package.json @@ -1,7 +1,7 @@ { "name": "grpc-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of gRPC integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,12 +28,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-grpc": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-grpc": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "google-protobuf": "^3.9.2", "grpc": "^1.23.3", "node-pre-gyp": "0.12.0" diff --git a/examples/grpc/server.js b/examples/grpc/server.js index 2a411ba40bd..1b9d5331728 100644 --- a/examples/grpc/server.js +++ b/examples/grpc/server.js @@ -1,26 +1,19 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (gRPC in this case). - */ -const config = require('./setup'); -config.setupTracerAndExporters('grpc-server-service'); - +const tracer = require('./tracer')(('example-grpc-server')); +// eslint-disable-next-line import/order const grpc = require('grpc'); -const tracer = opentelemetry.getTracer('example-grpc-server'); const messages = require('./helloworld_pb'); const services = require('./helloworld_grpc_pb'); + const PORT = 50051; /** Starts a gRPC server that receives requests on sample server port. */ function startServer() { // Creates a server const server = new grpc.Server(); - server.addService(services.GreeterService, { sayHello: sayHello }); + server.addService(services.GreeterService, { sayHello }); server.bind(`0.0.0.0:${PORT}`, grpc.ServerCredentials.createInsecure()); console.log(`binding server on 0.0.0.0:${PORT}`); server.start(); @@ -33,11 +26,11 @@ function sayHello(call, callback) { const span = tracer.startSpan('server.js:sayHello()', { parent: currentSpan, kind: 1, // server - attributes: { key: 'value' } + attributes: { key: 'value' }, }); span.addEvent(`invoking sayHello() to ${call.request.getName()}`); const reply = new messages.HelloReply(); - reply.setMessage('Hello ' + call.request.getName()); + reply.setMessage(`Hello ${call.request.getName()}`); callback(null, reply); span.end(); } diff --git a/examples/grpc/setup.js b/examples/grpc/tracer.js similarity index 72% rename from examples/grpc/setup.js rename to examples/grpc/tracer.js index 7a7fc3eafe7..ad881334c9c 100644 --- a/examples/grpc/setup.js +++ b/examples/grpc/tracer.js @@ -5,27 +5,27 @@ const { NodeTracerRegistry } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; -function setupTracerAndExporters(service) { +module.exports = (serviceName) => { const registry = new NodeTracerRegistry({ plugins: { grpc: { enabled: true, - // if it can't find the module, put the absolute path since the packages are not published yet - path: '@opentelemetry/plugin-grpc' - } - } + path: '@opentelemetry/plugin-grpc', + }, + }, }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service, + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, }); } @@ -33,6 +33,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/grpc_dynamic_codegen/capitalize_client.js b/examples/grpc_dynamic_codegen/capitalize_client.js index a994307854f..07916865674 100644 --- a/examples/grpc_dynamic_codegen/capitalize_client.js +++ b/examples/grpc_dynamic_codegen/capitalize_client.js @@ -1,22 +1,15 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (gRPC in this case). - */ -config.setupTracerAndExporters('grpc-client-service'); - +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-grpc-capitalize-client'); const path = require('path'); const grpc = require('grpc'); const protoLoader = require('@grpc/proto-loader'); -const tracer = opentelemetry.getTracer('example-grpc-capitalize-client'); - const PROTO_PATH = path.join(__dirname, 'protos/defs.proto'); -const PROTO_OPTIONS = { keepCase: true, enums: String, defaults: true, oneofs: true }; +const PROTO_OPTIONS = { + keepCase: true, enums: String, defaults: true, oneofs: true, +}; const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS); const rpcProto = grpc.loadPackageDefinition(definition).rpc; @@ -28,7 +21,7 @@ function main() { const span = tracer.startSpan('tutorialsClient.capitalize'); tracer.withSpan(span, () => { - client.capitalize({ data: Buffer.from(data) }, function (err, response) { + client.capitalize({ data: Buffer.from(data) }, (err, response) => { if (err) { console.log('could not get grpc response'); return; @@ -43,7 +36,7 @@ function main() { // The process must live for at least the interval past any traces that // must be exported, or some risk being lost if they are recorded after the // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); setTimeout(() => { console.log('Completed.'); }, 5000); } diff --git a/examples/grpc_dynamic_codegen/capitalize_server.js b/examples/grpc_dynamic_codegen/capitalize_server.js index 79dcd3c0fe8..3755e4ea560 100644 --- a/examples/grpc_dynamic_codegen/capitalize_server.js +++ b/examples/grpc_dynamic_codegen/capitalize_server.js @@ -1,26 +1,19 @@ 'use strict'; +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-grpc-capitalize-server'); const { SpanKind } = require('@opentelemetry/types'); -const opentelemetry = require('@opentelemetry/core'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (gRPC in this case). - */ -const config = require('./setup'); -config.setupTracerAndExporters('grpc-server-service'); - const path = require('path'); const grpc = require('grpc'); const protoLoader = require('@grpc/proto-loader'); const PROTO_PATH = path.join(__dirname, 'protos/defs.proto'); -const PROTO_OPTIONS = { keepCase: true, enums: String, defaults: true, oneofs: true }; +const PROTO_OPTIONS = { + keepCase: true, enums: String, defaults: true, oneofs: true, +}; const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS); const rpcProto = grpc.loadPackageDefinition(definition).rpc; -const tracer = opentelemetry.getTracer('example-grpc-capitalize-server'); - /** Implements the Capitalize RPC method. */ function capitalize(call, callback) { const currentSpan = tracer.getCurrentSpan(); @@ -34,7 +27,9 @@ function capitalize(call, callback) { const data = call.request.data.toString('utf8'); const capitalized = data.toUpperCase(); - for (let i = 0; i < 100000000; i++) {} + for (let i = 0; i < 100000000; i += 1) { + // empty + } span.end(); callback(null, { data: Buffer.from(capitalized) }); } @@ -45,7 +40,7 @@ function capitalize(call, callback) { */ function main() { const server = new grpc.Server(); - server.addService(rpcProto.Fetch.service, { capitalize: capitalize }); + server.addService(rpcProto.Fetch.service, { capitalize }); server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); server.start(); } diff --git a/examples/grpc_dynamic_codegen/package.json b/examples/grpc_dynamic_codegen/package.json index a4321a01690..8d91d64ee24 100644 --- a/examples/grpc_dynamic_codegen/package.json +++ b/examples/grpc_dynamic_codegen/package.json @@ -1,6 +1,6 @@ { "name": "grpc-dynamic-codegen-example", - "version": "0.3.2", + "version": "0.3.3", "description": "Example of gRPC integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,13 +28,13 @@ }, "dependencies": { "@grpc/proto-loader": "^0.4.0", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-grpc": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-grpc": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "grpc": "^1.23.3", "node-pre-gyp": "0.12.0" }, diff --git a/examples/grpc_dynamic_codegen/setup.js b/examples/grpc_dynamic_codegen/tracer.js similarity index 82% rename from examples/grpc_dynamic_codegen/setup.js rename to examples/grpc_dynamic_codegen/tracer.js index 4fd8b0a8b6f..23d6e25f01b 100644 --- a/examples/grpc_dynamic_codegen/setup.js +++ b/examples/grpc_dynamic_codegen/tracer.js @@ -5,27 +5,28 @@ const { NodeTracerRegistry } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; -function setupTracerAndExporters(service) { +module.exports = (serviceName) => { const registry = new NodeTracerRegistry({ plugins: { grpc: { enabled: true, // You may use a package name or absolute path to the file. - path: '@opentelemetry/plugin-grpc' - } - } + path: '@opentelemetry/plugin-grpc', + }, + }, }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service, + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, }); } @@ -35,6 +36,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/http/client.js b/examples/http/client.js index 8b299b98fff..5a88497f668 100644 --- a/examples/http/client.js +++ b/examples/http/client.js @@ -1,43 +1,35 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTP in this case). - */ -config.setupTracerAndExporters('http-client-service'); - +const tracer = require('./tracer')('example-http-client'); +// eslint-disable-next-line import/order const http = require('http'); -const tracer = opentelemetry.getTracer('example-http-client'); /** A function which makes requests and handles response. */ function makeRequest() { - // span corresponds to outgoing requests. Here, we have manually created - // the span, which is created to track work that happens outside of the - // request lifecycle entirely. - const span = tracer.startSpan('makeRequest'); - tracer.withSpan(span, () => { - http.get({ - host: 'localhost', - port: 8080, - path: '/helloworld' - }, (response) => { - let body = []; - response.on('data', chunk => body.push(chunk)); - response.on('end', () => { - console.log(body.toString()); - span.end(); - }); - }); - }) + // span corresponds to outgoing requests. Here, we have manually created + // the span, which is created to track work that happens outside of the + // request lifecycle entirely. + const span = tracer.startSpan('makeRequest'); + tracer.withSpan(span, () => { + http.get({ + host: 'localhost', + port: 8080, + path: '/helloworld', + }, (response) => { + const body = []; + response.on('data', (chunk) => body.push(chunk)); + response.on('end', () => { + console.log(body.toString()); + span.end(); + }); + }); + }); - // The process must live for at least the interval past any traces that - // must be exported, or some risk being lost if they are recorded after the - // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); + // The process must live for at least the interval past any traces that + // must be exported, or some risk being lost if they are recorded after the + // last export. + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); } makeRequest(); diff --git a/examples/http/package.json b/examples/http/package.json index 6ee9a5f01e3..98503047c4c 100644 --- a/examples/http/package.json +++ b/examples/http/package.json @@ -1,7 +1,7 @@ { "name": "http-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of HTTP integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,12 +28,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/examples/http/server.js b/examples/http/server.js index d3c0046bf9b..d142badf83b 100644 --- a/examples/http/server.js +++ b/examples/http/server.js @@ -1,22 +1,15 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTP in this case). - */ -config.setupTracerAndExporters('http-server-service'); - +const tracer = require('./tracer')('example-http-server'); +// eslint-disable-next-line import/order const http = require('http'); -const tracer = opentelemetry.getTracer('example-http-server'); /** Starts a HTTP server that receives requests on sample server port. */ -function startServer (port) { +function startServer(port) { // Creates a server const server = http.createServer(handleRequest); // Starts the server - server.listen(port, err => { + server.listen(port, (err) => { if (err) { throw err; } @@ -25,21 +18,21 @@ function startServer (port) { } /** A function which handles requests and send response. */ -function handleRequest (request, response) { +function handleRequest(request, response) { const currentSpan = tracer.getCurrentSpan(); // display traceid in the terminal console.log(`traceid: ${currentSpan.context().traceId}`); const span = tracer.startSpan('handleRequest', { parent: currentSpan, kind: 1, // server - attributes: { key:'value' } + attributes: { key: 'value' }, }); // Annotate our span to capture metadata about the operation span.addEvent('invoking handleRequest'); try { - let body = []; - request.on('error', err => console.log(err)); - request.on('data', chunk => body.push(chunk)); + const body = []; + request.on('error', (err) => console.log(err)); + request.on('data', (chunk) => body.push(chunk)); request.on('end', () => { // deliberately sleeping to mock some action. setTimeout(() => { @@ -48,7 +41,7 @@ function handleRequest (request, response) { }, 2000); }); } catch (err) { - console.log(err); + console.error(err); span.end(); } } diff --git a/examples/redis/setup.js b/examples/http/tracer.js similarity index 83% rename from examples/redis/setup.js rename to examples/http/tracer.js index 770cdd5dfd3..29a21f4f0d5 100644 --- a/examples/redis/setup.js +++ b/examples/http/tracer.js @@ -5,19 +5,20 @@ const { NodeTracerRegistry } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; -function setupTracerAndExporters(service) { +module.exports = (serviceName) => { const registry = new NodeTracerRegistry(); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service, + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, }); } @@ -25,6 +26,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/https/client.js b/examples/https/client.js index 40ebc94d3f9..e5b1825163e 100644 --- a/examples/https/client.js +++ b/examples/https/client.js @@ -1,42 +1,35 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTPs in this case). - */ -config.setupTracerAndExporters('https-client-service'); - +const tracer = require('./tracer')('example-https-client'); +// eslint-disable-next-line import/order const https = require('https'); -const tracer = opentelemetry.getTracer('example-https-client'); /** A function which makes requests and handles response. */ function makeRequest() { - // span corresponds to outgoing requests. Here, we have manually created - // the span, which is created to track work that happens outside of the - // request lifecycle entirely. - const span = tracer.startSpan('makeRequest'); - tracer.withSpan(span, () => { - https.get({ - host: 'localhost', - port: 443, - path: '/helloworld' - }, (response) => { - let body = []; - response.on('data', chunk => body.push(chunk)); - response.on('end', () => { - console.log(body.toString()); - span.end(); - }); - }); + // span corresponds to outgoing requests. Here, we have manually created + // the span, which is created to track work that happens outside of the + // request lifecycle entirely. + const span = tracer.startSpan('makeRequest'); + tracer.withSpan(span, () => { + https.get({ + host: 'localhost', + port: 443, + path: '/helloworld', + }, (response) => { + const body = []; + response.on('data', (chunk) => body.push(chunk)); + response.on('end', () => { + console.log(body.toString()); + span.end(); + }); }); + }); - // The process must live for at least the interval past any traces that - // must be exported, or some risk being lost if they are recorded after the - // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); + // The process must live for at least the interval past any traces that + // must be exported, or some risk being lost if they are recorded after the + // last export. + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); } makeRequest(); diff --git a/examples/https/package.json b/examples/https/package.json index 2d90f3ae142..cb46108550d 100644 --- a/examples/https/package.json +++ b/examples/https/package.json @@ -1,7 +1,7 @@ { "name": "https-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of HTTPs integration with OpenTelemetry", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -29,12 +29,12 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-https": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-https": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/examples/https/server.js b/examples/https/server.js index 7280c8f61fd..105005fea8c 100644 --- a/examples/https/server.js +++ b/examples/https/server.js @@ -1,27 +1,20 @@ 'use strict'; +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-https-server'); const fs = require('fs'); -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTPs in this case). - */ -config.setupTracerAndExporters('https-server-service'); - const https = require('https'); -const tracer = opentelemetry.getTracer('example-https-server'); /** Starts a HTTPs server that receives requests on sample server port. */ -function startServer (port) { +function startServer(port) { const options = { key: fs.readFileSync('./server-key.pem'), - cert: fs.readFileSync('./server-cert.pem') + cert: fs.readFileSync('./server-cert.pem'), }; // Creates a server const server = https.createServer(options, handleRequest); // Starts the server - server.listen(port, err => { + server.listen(port, (err) => { if (err) { throw err; } @@ -30,21 +23,21 @@ function startServer (port) { } /** A function which handles requests and send response. */ -function handleRequest (request, response) { +function handleRequest(request, response) { const currentSpan = tracer.getCurrentSpan(); // display traceid in the terminal console.log(`traceid: ${currentSpan.context().traceId}`); const span = tracer.startSpan('handleRequest', { parent: currentSpan, kind: 1, // server - attributes: { key:'value' } + attributes: { key: 'value' }, }); // Annotate our span to capture metadata about the operation span.addEvent('invoking handleRequest'); try { - let body = []; - request.on('error', err => console.log(err)); - request.on('data', chunk => body.push(chunk)); + const body = []; + request.on('error', (err) => console.log(err)); + request.on('data', (chunk) => body.push(chunk)); request.on('end', () => { // deliberately sleeping to mock some action. setTimeout(() => { diff --git a/examples/https/setup.js b/examples/https/tracer.js similarity index 84% rename from examples/https/setup.js rename to examples/https/tracer.js index ef426a90b57..eaec28f3760 100644 --- a/examples/https/setup.js +++ b/examples/https/tracer.js @@ -5,19 +5,21 @@ const { NodeTracerRegistry } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; -function setupTracerAndExporters(service) { + +module.exports = (serviceName) => { let exporter; const registry = new NodeTracerRegistry(); if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, }); } @@ -25,6 +27,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/mysql/client.js b/examples/mysql/client.js index e080ab994ab..6e8bc0c51af 100644 --- a/examples/mysql/client.js +++ b/examples/mysql/client.js @@ -1,81 +1,73 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); - -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTP and MySQL in this case). - */ -config.setupTracerAndExporters('http-client-service'); - +const tracer = require('./tracer')('example-mysql-http-client'); +// eslint-disable-next-line import/order const http = require('http'); -const tracer = opentelemetry.getTracer('example-mysql-http-client'); /** A function which makes requests and handles response. */ function makeRequest() { - // span corresponds to outgoing requests. Here, we have manually created - // the span, which is created to track work that happens outside of the - // request lifecycle entirely. - const span = tracer.startSpan('makeRequest'); + // span corresponds to outgoing requests. Here, we have manually created + // the span, which is created to track work that happens outside of the + // request lifecycle entirely. + const span = tracer.startSpan('makeRequest'); - let queries = 0 - let responses = 0; + let queries = 0; + let responses = 0; - tracer.withSpan(span, () => { - queries += 1; - http.get({ - host: 'localhost', - port: 8080, - path: '/connection/query' - }, (response) => { - let body = []; - response.on('data', chunk => body.push(chunk)); - response.on('end', () => { - responses += 1; - console.log(body.toString()); - if (responses === queries) span.end(); - }); - }); + tracer.withSpan(span, () => { + queries += 1; + http.get({ + host: 'localhost', + port: 8080, + path: '/connection/query', + }, (response) => { + const body = []; + response.on('data', (chunk) => body.push(chunk)); + response.on('end', () => { + responses += 1; + console.log(body.toString()); + if (responses === queries) span.end(); + }); }); - tracer.withSpan(span, () => { - queries += 1; - http.get({ - host: 'localhost', - port: 8080, - path: '/pool/query' - }, (response) => { - let body = []; - response.on('data', chunk => body.push(chunk)); - response.on('end', () => { - responses += 1; - console.log(body.toString()); - if (responses === queries) span.end(); - }); - }); + }); + tracer.withSpan(span, () => { + queries += 1; + http.get({ + host: 'localhost', + port: 8080, + path: '/pool/query', + }, (response) => { + const body = []; + response.on('data', (chunk) => body.push(chunk)); + response.on('end', () => { + responses += 1; + console.log(body.toString()); + if (responses === queries) span.end(); + }); }); - tracer.withSpan(span, () => { - queries += 1; - http.get({ - host: 'localhost', - port: 8080, - path: '/cluster/query' - }, (response) => { - let body = []; - response.on('data', chunk => body.push(chunk)); - response.on('end', () => { - responses += 1; - console.log(body.toString()); - if (responses === queries) span.end(); - }); - }); + }); + tracer.withSpan(span, () => { + queries += 1; + http.get({ + host: 'localhost', + port: 8080, + path: '/cluster/query', + }, (response) => { + const body = []; + response.on('data', (chunk) => body.push(chunk)); + response.on('end', () => { + responses += 1; + console.log(body.toString()); + if (responses === queries) span.end(); + }); }); + }); - // The process must live for at least the interval past any traces that - // must be exported, or some risk being lost if they are recorded after the - // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); + // The process must live for at least the interval past any traces that + // must be exported, or some risk being lost if they are recorded after the + // last export. + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); } makeRequest(); diff --git a/examples/mysql/package.json b/examples/mysql/package.json index 916c5b49109..09e3e92eb54 100644 --- a/examples/mysql/package.json +++ b/examples/mysql/package.json @@ -1,7 +1,7 @@ { "name": "mysql-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of mysql integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -28,13 +28,13 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/plugin-mysql": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/plugin-mysql": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "mysql": "*" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", diff --git a/examples/mysql/server.js b/examples/mysql/server.js index 1ba4eb72587..748ef339d1b 100644 --- a/examples/mysql/server.js +++ b/examples/mysql/server.js @@ -1,47 +1,39 @@ 'use strict'; -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -/** - * The trace instance needs to be initialized first, if you want to enable - * automatic tracing for built-in plugins (HTTP and MySQL in this case). - */ -config.setupTracerAndExporters('http-mysql-server-service'); - +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-mysql-http-server'); const mysql = require('mysql'); const http = require('http'); -const tracer = opentelemetry.getTracer('example-mysql-http-server'); - const pool = mysql.createPool({ - host : 'localhost', - user : 'root', - password : 'secret', - database : 'my_db', + host: 'localhost', + user: 'root', + password: 'secret', + database: 'my_db', }); const connection = mysql.createConnection({ - host : 'localhost', - user : 'root', - password : 'secret', - database : 'my_db', + host: 'localhost', + user: 'root', + password: 'secret', + database: 'my_db', }); const cluster = mysql.createPoolCluster(); cluster.add({ - host : 'localhost', - user : 'root', - password : 'secret', - database : 'my_db', -}) + host: 'localhost', + user: 'root', + password: 'secret', + database: 'my_db', +}); /** Starts a HTTP server that receives requests on sample server port. */ -function startServer (port) { +function startServer(port) { // Creates a server const server = http.createServer(handleRequest); // Starts the server - server.listen(port, err => { + server.listen(port, (err) => { if (err) { throw err; } @@ -50,23 +42,23 @@ function startServer (port) { } /** A function which handles requests and send response. */ -function handleRequest (request, response) { +function handleRequest(request, response) { const currentSpan = tracer.getCurrentSpan(); // display traceid in the terminal - const {traceId} = currentSpan.context(); + const { traceId } = currentSpan.context(); console.log(`traceid: ${traceId}`); - console.log(`Jaeger URL: http://localhost:16686/trace/${traceId}`) - console.log(`Zipkin URL: http://localhost:9411/zipkin/traces/${traceId}`) + console.log(`Jaeger URL: http://localhost:16686/trace/${traceId}`); + console.log(`Zipkin URL: http://localhost:9411/zipkin/traces/${traceId}`); try { - let body = []; - request.on('error', err => console.log(err)); - request.on('data', chunk => body.push(chunk)); + const body = []; + request.on('error', (err) => console.log(err)); + request.on('data', (chunk) => body.push(chunk)); request.on('end', () => { - if (request.url === "/connection/query") { + if (request.url === '/connection/query') { handleConnectionQuery(response); - } else if (request.url === "/pool/query") { + } else if (request.url === '/pool/query') { handlePoolQuery(response); - } else if (request.url === "/cluster/query") { + } else if (request.url === '/cluster/query') { handleClusterQuery(response); } else { handleNotFound(response); @@ -80,51 +72,47 @@ function handleRequest (request, response) { startServer(8080); function handlePoolQuery(response) { - const query = "SELECT 1 + 1 as pool_solution"; - pool.getConnection((err, conn) => { - conn.query(query, (err, results, fields) => { - tracer.getCurrentSpan().addEvent("results"); + const query = 'SELECT 1 + 1 as pool_solution'; + pool.getConnection((connErr, conn, _fields) => { + conn.query(query, (err, results) => { + tracer.getCurrentSpan().addEvent('results'); if (err) { - console.log("Error code:", err.code); + console.log('Error code:', err.code); response.end(err.message); - } - else { + } else { response.end(`${query}: ${results[0].pool_solution}`); } }); - }) + }); } function handleConnectionQuery(response) { - const query = "SELECT 1 + 1 as solution"; - connection.query(query, (err, results, fields) => { + const query = 'SELECT 1 + 1 as solution'; + connection.query(query, (err, results, _fields) => { if (err) { - console.log("Error code:", err.code); + console.log('Error code:', err.code); response.end(err.message); - } - else { + } else { response.end(`${query}: ${results[0].solution}`); } }); } function handleClusterQuery(response) { - const query = "SELECT 1 + 1 as cluster_solution"; - cluster.getConnection((err, conn) => { - conn.query(query, (err, results, fields) => { - tracer.getCurrentSpan().addEvent("results"); + const query = 'SELECT 1 + 1 as cluster_solution'; + cluster.getConnection((connErr, conn) => { + conn.query(query, (err, results, _fields) => { + tracer.getCurrentSpan().addEvent('results'); if (err) { - console.log("Error code:", err.code); + console.log('Error code:', err.code); response.end(err.message); - } - else { + } else { response.end(`${query}: ${results[0].cluster_solution}`); } }); - }) + }); } function handleNotFound(response) { - response.end("not found"); + response.end('not found'); } - diff --git a/examples/mysql/setup.js b/examples/mysql/tracer.js similarity index 75% rename from examples/mysql/setup.js rename to examples/mysql/tracer.js index e3f9ce3f412..e3e93e4d79b 100644 --- a/examples/mysql/setup.js +++ b/examples/mysql/tracer.js @@ -6,29 +6,29 @@ const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); -function setupTracerAndExporters(service) { +module.exports = (serviceName) => { const registry = new NodeTracerRegistry({ plugins: { mysql: { enabled: true, - path: "@opentelemetry/plugin-mysql" + path: '@opentelemetry/plugin-mysql', }, http: { enabled: true, - path: "@opentelemetry/plugin-http" - } - } + path: '@opentelemetry/plugin-http', + }, + }, }); registry.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({ - serviceName: service, + serviceName, }))); registry.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({ - serviceName: service, + serviceName, }))); // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/opentracing-shim/client.js b/examples/opentracing-shim/client.js index 916b1c65f06..451467e3ef9 100644 --- a/examples/opentracing-shim/client.js +++ b/examples/opentracing-shim/client.js @@ -1,8 +1,8 @@ -"use strict"; +'use strict'; -const http = require("http"); -const opentracing = require("opentracing"); -const shim = require("./shim").shim("http_client_service"); +const http = require('http'); +const opentracing = require('opentracing'); +const shim = require('./shim').shim('http_client_service'); opentracing.initGlobalTracer(shim); const tracer = opentracing.globalTracer(); @@ -10,7 +10,7 @@ const tracer = opentracing.globalTracer(); makeRequest(); async function makeRequest() { - const span = tracer.startSpan("make_request"); + const span = tracer.startSpan('make_request'); const headers = {}; tracer.inject(span, opentracing.FORMAT_HTTP_HEADERS, headers); @@ -18,28 +18,28 @@ async function makeRequest() { http .get( { - host: "localhost", + host: 'localhost', port: 3000, - path: "/", - headers + path: '/', + headers, }, - resp => { - let data = ""; + (resp) => { + let data = ''; - resp.on("data", chunk => { + resp.on('data', (chunk) => { data += chunk; }); - resp.on("end", async () => { + resp.on('end', async () => { console.log(JSON.parse(data)); span.finish(); - console.log("Sleeping 5 seconds before shutdown to ensure all records are flushed."); - setTimeout(() => { console.log("Completed."); }, 5000); + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); }); - } + }, ) - .on("error", err => { - console.log("Error: " + err.message); + .on('error', (err) => { + console.log(`Error: ${err.message}`); }); } diff --git a/examples/opentracing-shim/package.json b/examples/opentracing-shim/package.json index 2ff92279f0b..46d065f9fe8 100644 --- a/examples/opentracing-shim/package.json +++ b/examples/opentracing-shim/package.json @@ -1,7 +1,7 @@ { "name": "opentracing-shim", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of using @opentelemetry/shim-opentracing in Node.js", "main": "index.js", "scripts": { @@ -29,10 +29,11 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/shim-opentracing": "^0.3.2", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/shim-opentracing": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "opentracing": "^0.14.4" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", diff --git a/examples/opentracing-shim/server.js b/examples/opentracing-shim/server.js index f10ffdfc5d3..66c0803ccda 100644 --- a/examples/opentracing-shim/server.js +++ b/examples/opentracing-shim/server.js @@ -1,9 +1,9 @@ -"use strict"; +'use strict'; -const http = require("http"); -const opentracing = require("opentracing"); -const utils = require("./utils"); -const shim = require("./shim").shim("http_server_service"); +const http = require('http'); +const opentracing = require('opentracing'); +const utils = require('./utils'); +const shim = require('./shim').shim('http_server_service'); opentracing.initGlobalTracer(shim); const tracer = opentracing.globalTracer(); @@ -13,7 +13,7 @@ startServer(3000); function startServer(port) { const server = http.createServer(handleRequest); - server.listen(port, err => { + server.listen(port, (err) => { if (err) throw err; console.log(`Server is listening on ${port}`); @@ -23,21 +23,21 @@ function startServer(port) { async function handleRequest(req, res) { const parentSpan = tracer.extract( opentracing.FORMAT_HTTP_HEADERS, - req.headers + req.headers, ); - const span = tracer.startSpan("handle_request", { - childOf: parentSpan + const span = tracer.startSpan('handle_request', { + childOf: parentSpan, }); - span.setTag("custom", "tag value"); - span.setTag("alpha", "1000"); + span.setTag('custom', 'tag value'); + span.setTag('alpha', '1000'); await doSomething(span); - res.writeHead(200, { "Content-Type": "application/json" }); + res.writeHead(200, { 'Content-Type': 'application/json' }); res.write( - JSON.stringify({ status: "OK", traceId: span.context().toTraceId() }) + JSON.stringify({ status: 'OK', traceId: span.context().toTraceId() }), ); res.end(); @@ -45,11 +45,11 @@ async function handleRequest(req, res) { } async function doSomething(parentSpan) { - const span = tracer.startSpan("do_something", { childOf: parentSpan }); + const span = tracer.startSpan('do_something', { childOf: parentSpan }); - span.setTag("alpha", "200"); - span.setTag("beta", "50"); - span.log({ state: "waiting" }); + span.setTag('alpha', '200'); + span.setTag('beta', '50'); + span.log({ state: 'waiting' }); // deliberately sleeping to mock some action. await utils.sleep(1000); diff --git a/examples/opentracing-shim/shim.js b/examples/opentracing-shim/shim.js index 8efb1c2a8bc..4730f9e2587 100644 --- a/examples/opentracing-shim/shim.js +++ b/examples/opentracing-shim/shim.js @@ -1,23 +1,23 @@ -"use strict"; +'use strict'; -const { NodeTracerRegistry } = require("@opentelemetry/node"); -const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); -const { JaegerExporter } = require("@opentelemetry/exporter-jaeger"); -const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); -const { TracerShim } = require("@opentelemetry/shim-opentracing"); +const { NodeTracerRegistry } = require('@opentelemetry/node'); +const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); +const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); +const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { TracerShim } = require('@opentelemetry/shim-opentracing'); function shim(serviceName) { const registry = new NodeTracerRegistry(); registry.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName))); - return new TracerShim(registry.getTracer("opentracing-shim")); + return new TracerShim(registry.getTracer('opentracing-shim')); } function getExporter(serviceName) { - const type = process.env.EXPORTER.toLowerCase() || "jaeger"; + const type = process.env.EXPORTER.toLowerCase() || 'jaeger'; - if (type.startsWith("z")) { + if (type.startsWith('z')) { return new ZipkinExporter({ serviceName }); } diff --git a/examples/opentracing-shim/utils.js b/examples/opentracing-shim/utils.js index 813dc35dcdc..a913e95acd2 100644 --- a/examples/opentracing-shim/utils.js +++ b/examples/opentracing-shim/utils.js @@ -1,7 +1,7 @@ -"use strict"; +'use strict'; async function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms)); } exports.sleep = sleep; diff --git a/examples/postgres/client.js b/examples/postgres/client.js index 1c31f5c1d34..1df7bdf9f6a 100644 --- a/examples/postgres/client.js +++ b/examples/postgres/client.js @@ -1,35 +1,32 @@ 'use strict'; -// set up ot -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -config.setupTracerAndExporters('postgres-client-service'); +const tracer = require('./tracer')('postgres-client-service'); +// eslint-disable-next-line import/order const http = require('http'); -const tracer = opentelemetry.getTracer(); function makeRequest() { - const span = tracer.startSpan('makeRequest'); - const randomId = Math.floor(Math.random() * 10); - tracer.withSpan(span, () => { - console.log('Client traceId ', span.context().traceId); - http.get({ - host: 'localhost', - port: 3000, - path: `/insert?id=${randomId}&text=randomstring` - }); + const span = tracer.startSpan('makeRequest'); + const randomId = Math.floor(Math.random() * 10); + tracer.withSpan(span, () => { + console.log('Client traceId ', span.context().traceId); + http.get({ + host: 'localhost', + port: 3000, + path: `/insert?id=${randomId}&text=randomstring`, + }); - http.get({ - host: 'localhost', - port: 3000, - path: `/get?id=${randomId}` - }); + http.get({ + host: 'localhost', + port: 3000, + path: `/get?id=${randomId}`, }); + }); - // The process must live for at least the interval past any traces that - // must be exported, or some risk being lost if they are recorded after the - // last export. - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); + // The process must live for at least the interval past any traces that + // must be exported, or some risk being lost if they are recorded after the + // last export. + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); } makeRequest(); diff --git a/examples/postgres/package.json b/examples/postgres/package.json index 8907e3406cc..eff66b11611 100644 --- a/examples/postgres/package.json +++ b/examples/postgres/package.json @@ -1,7 +1,7 @@ { "name": "postgres-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of Postgres integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -30,15 +30,15 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.2.0", - "@opentelemetry/exporter-jaeger": "^0.2.0", - "@opentelemetry/exporter-zipkin": "^0.2.0", - "@opentelemetry/node": "^0.2.0", - "@opentelemetry/plugin-http": "^0.2.0", - "@opentelemetry/plugin-pg": "^0.2.0", - "@opentelemetry/plugin-pg-pool": "^0.2.0", - "@opentelemetry/tracing": "^0.2.0", - "@opentelemetry/types": "^0.2.0", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/plugin-pg": "^0.3.3", + "@opentelemetry/plugin-pg-pool": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "express": "^4.17.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", diff --git a/examples/postgres/server.js b/examples/postgres/server.js index 9f67ed4a562..8486add4a30 100644 --- a/examples/postgres/server.js +++ b/examples/postgres/server.js @@ -1,18 +1,13 @@ 'use strict'; -// set up ot -const opentelemetry = require('@opentelemetry/core'); +// eslint-disable-next-line import/order +const tracer = require('./tracer')('postgres-server-service'); const { SpanKind, CanonicalCode } = require('@opentelemetry/types'); -const config = require('./setup'); -config.setupTracerAndExporters('postgres-server-service'); -const tracer = opentelemetry.getTracer(); +const express = require('express'); +const setupPg = require('./setupPsql'); -// set up pg -const setupPg = require('./setupPsql'); const pool = setupPg.startPsql(); -// set up express -const express = require('express'); const app = express(); app.get('/:cmd', (req, res) => { @@ -28,7 +23,7 @@ app.get('/:cmd', (req, res) => { return; } queryText = { - text: `INSERT INTO test (id, text) VALUES($1, $2) ON CONFLICT(id) DO UPDATE SET text=$2`, + text: 'INSERT INTO test (id, text) VALUES($1, $2) ON CONFLICT(id) DO UPDATE SET text=$2', values: [req.query.id, req.query.text], }; } @@ -45,7 +40,7 @@ app.get('/:cmd', (req, res) => { res.send(ret.rows); }); } catch (e) { - res.status(400).send({message: e.message}); + res.status(400).send({ message: e.message }); span.setStatus(CanonicalCode.UNKNOWN); } span.end(); @@ -54,7 +49,6 @@ app.get('/:cmd', (req, res) => { // start server const port = 3000; -app.listen(port, function() { +app.listen(port, () => { console.log(`Node HTTP listening on ${port}`); }); - diff --git a/examples/postgres/setupPsql.js b/examples/postgres/setupPsql.js index 988e23a4670..d6722b840e9 100644 --- a/examples/postgres/setupPsql.js +++ b/examples/postgres/setupPsql.js @@ -1,28 +1,31 @@ +'use strict'; + const { Pool } = require('pg'); // create new pool for psql const CONFIG = { - user: process.env.POSTGRES_USER || 'postgres', - database: process.env.POSTGRES_DB || 'postgres', - host: process.env.POSTGRES_HOST || 'localhost', - port: process.env.POSTGRES_PORT - ? parseInt(process.env.POSTGRES_PORT, 10) - : 54320, - }; - + user: process.env.POSTGRES_USER || 'postgres', + database: process.env.POSTGRES_DB || 'postgres', + host: process.env.POSTGRES_HOST || 'localhost', + port: process.env.POSTGRES_PORT + ? parseInt(process.env.POSTGRES_PORT, 10) + : 54320, +}; + function startPsql() { - let pool = new Pool(CONFIG); + const pool = new Pool(CONFIG); - pool.connect(function(err, client, release) { - if (err) throw err; - release(); - const queryText = 'CREATE TABLE IF NOT EXISTS test(id SERIAL PRIMARY KEY, text VARCHAR(40) not null)'; - client.query(queryText, (err, res) => { - if (err) throw err; - }); + pool.connect((connectErr, client, release) => { + if (connectErr) throw connectErr; + release(); + const queryText = 'CREATE TABLE IF NOT EXISTS test(id SERIAL PRIMARY KEY, text VARCHAR(40) not null)'; + client.query(queryText, (err, res) => { + if (err) throw err; + console.log(res.rows[0]); }); + }); - return pool; + return pool; } exports.startPsql = startPsql; diff --git a/examples/postgres/setup.js b/examples/postgres/tracer.js similarity index 68% rename from examples/postgres/setup.js rename to examples/postgres/tracer.js index 1c369a0f482..ab1d34ddc1f 100644 --- a/examples/postgres/setup.js +++ b/examples/postgres/tracer.js @@ -5,37 +5,41 @@ const { NodeTracer } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; -function setupTracerAndExporters(service) { +module.exports = (serviceName) => { const tracer = new NodeTracer({ plugins: { pg: { enabled: true, - // if it can't find the module, put the absolute path since the packages are not published yet - path: '@opentelemetry/plugin-pg' + /* + if it can't find the module, + put the absolute path since the packages are not published yet + */ + path: '@opentelemetry/plugin-pg', }, 'pg-pool': { enabled: true, - path: '@opentelemetry/plugin-pg-pool' + path: '@opentelemetry/plugin-pg-pool', }, http: { enabled: true, - path: '@opentelemetry/plugin-http' - } - } + path: '@opentelemetry/plugin-http', + }, + }, }); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service, + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, // The default flush interval is 5 seconds. - flushInterval: 2000 + flushInterval: 2000, }); } @@ -43,6 +47,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracer bindings opentelemetry.initGlobalTracer(tracer); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/prometheus/index.js b/examples/prometheus/index.js index 166dff8e94f..7e6a85dee9f 100644 --- a/examples/prometheus/index.js +++ b/examples/prometheus/index.js @@ -1,43 +1,43 @@ -"use strict"; +'use strict'; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-prometheus'); const exporter = new PrometheusExporter( { - startServer: true + startServer: true, }, () => { - console.log("prometheus scrape endpoint: http://localhost:9464/metrics"); - } + console.log('prometheus scrape endpoint: http://localhost:9464/metrics'); + }, ); meter.addExporter(exporter); // Monotonic counters and gauges can only be increased. -const monotonicCounter = meter.createCounter("monotonic_counter", { +const monotonicCounter = meter.createCounter('monotonic_counter', { monotonic: true, - labelKeys: ["pid"], - description: "Example of a monotonic counter" + labelKeys: ['pid'], + description: 'Example of a monotonic counter', }); -const monotonicGauge = meter.createGauge("monotonic_gauge", { +const monotonicGauge = meter.createGauge('monotonic_gauge', { monotonic: true, - labelKeys: ["pid"], - description: "Example of a monotonic gauge" + labelKeys: ['pid'], + description: 'Example of a monotonic gauge', }); // Non-monotonic counters and gauges can be increased or decreased. -const nonMonotonicCounter = meter.createCounter("non_monotonic_counter", { +const nonMonotonicCounter = meter.createCounter('non_monotonic_counter', { monotonic: false, - labelKeys: ["pid"], - description: "Example of a non-monotonic counter" + labelKeys: ['pid'], + description: 'Example of a non-monotonic counter', }); -const nonMonotonicGauge = meter.createGauge("non_monotonic_gauge", { +const nonMonotonicGauge = meter.createGauge('non_monotonic_gauge', { monotonic: false, - labelKeys: ["pid"], - description: "Example of a non-monotonic gauge" + labelKeys: ['pid'], + description: 'Example of a non-monotonic gauge', }); let currentMonotonicGaugeValue = 0; diff --git a/examples/prometheus/package.json b/examples/prometheus/package.json index e95aa9c9ad3..08bca5e8673 100644 --- a/examples/prometheus/package.json +++ b/examples/prometheus/package.json @@ -1,6 +1,6 @@ { "name": "prometheus-example", - "version": "0.3.2", + "version": "0.3.3", "description": "Example of using @opentelemetry/metrics and @opentelemetry/exporter-prometheus", "main": "index.js", "scripts": { @@ -9,7 +9,7 @@ "author": "OpenTelemetry Authors", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/exporter-prometheus": "^0.3.2", - "@opentelemetry/metrics": "^0.3.2" + "@opentelemetry/exporter-prometheus": "^0.3.3", + "@opentelemetry/metrics": "^0.3.3" } } diff --git a/examples/redis/client.js b/examples/redis/client.js index 191effe612b..30fd9b65ca0 100644 --- a/examples/redis/client.js +++ b/examples/redis/client.js @@ -1,30 +1,28 @@ -'use strict' +'use strict'; -const opentelemetry = require('@opentelemetry/core'); +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-redis-client'); const types = require('@opentelemetry/types'); -const config = require('./setup'); -config.setupTracerAndExporters('redis-client-service'); -const tracer = opentelemetry.getTracer('example-redis-client'); const axios = require('axios').default; function makeRequest() { - const span = tracer.startSpan('client.makeRequest()', { - parent: tracer.getCurrentSpan(), - kind: types.SpanKind.CLIENT - }); + const span = tracer.startSpan('client.makeRequest()', { + parent: tracer.getCurrentSpan(), + kind: types.SpanKind.CLIENT, + }); - tracer.withSpan(span, async () => { - try { - const res = await axios.get('http://localhost:8080/run_test'); - span.setStatus({ code: types.CanonicalCode.OK }); - console.log(res.statusText); - } catch (e) { - span.setStatus({ code: types.CanonicalCode.UNKNOWN, message: e.message }); - } - span.end(); - console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.') - setTimeout(() => { console.log('Completed.'); }, 5000); - }); + tracer.withSpan(span, async () => { + try { + const res = await axios.get('http://localhost:8080/run_test'); + span.setStatus({ code: types.CanonicalCode.OK }); + console.log(res.statusText); + } catch (e) { + span.setStatus({ code: types.CanonicalCode.UNKNOWN, message: e.message }); + } + span.end(); + console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); + setTimeout(() => { console.log('Completed.'); }, 5000); + }); } makeRequest(); diff --git a/examples/redis/express-tracer-handlers.js b/examples/redis/express-tracer-handlers.js index 25918318a10..1e15608ab58 100644 --- a/examples/redis/express-tracer-handlers.js +++ b/examples/redis/express-tracer-handlers.js @@ -1,36 +1,36 @@ -'use strict' +'use strict'; const types = require('@opentelemetry/types'); function getMiddlewareTracer(tracer) { - return function(req, res, next) { + return (req, res, next) => { const span = tracer.startSpan(`express.middleware.tracer(${req.method} ${req.path})`, { parent: tracer.getCurrentSpan(), kind: types.SpanKind.SERVER, }); - + // End this span before sending out the response const originalSend = res.send; - res.send = function send() { + res.send = function send(...args) { span.end(); - originalSend.apply(res, arguments); - } - + originalSend.apply(res, args); + }; + tracer.withSpan(span, next); - } + }; } function getErrorTracer(tracer) { - return function(err, _req, res, _next) { - console.log('Caught error', err.message); + return (err, _req, res, _next) => { + console.error('Caught error', err.message); const span = tracer.getCurrentSpan(); if (span) { span.setStatus({ code: types.CanonicalCode.INTERNAL, message: err.message }); } res.status(500).send(err.message); - } + }; } module.exports = { - getMiddlewareTracer, getErrorTracer -} + getMiddlewareTracer, getErrorTracer, +}; diff --git a/examples/redis/package.json b/examples/redis/package.json index 91bc0a715a7..538dab4d12e 100644 --- a/examples/redis/package.json +++ b/examples/redis/package.json @@ -1,7 +1,7 @@ { "name": "redis-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of HTTP integration with OpenTelemetry", "main": "index.js", "scripts": { @@ -30,14 +30,14 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-jaeger": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/plugin-redis": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-jaeger": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/plugin-redis": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "axios": "^0.19.0", "express": "^4.17.1", "redis": "^2.8.0" diff --git a/examples/redis/server.js b/examples/redis/server.js index 33744b2f747..f293084e2d2 100644 --- a/examples/redis/server.js +++ b/examples/redis/server.js @@ -1,15 +1,13 @@ 'use strict'; -// Setup opentelemetry tracer first so that built-in plugins can hook onto their corresponding modules -const opentelemetry = require('@opentelemetry/core'); -const config = require('./setup'); -config.setupTracerAndExporters('redis-server-service'); -const tracer = opentelemetry.getTracer('example-redis-server'); +// eslint-disable-next-line import/order +const tracer = require('./tracer')('example-redis-server'); // Require in rest of modules const express = require('express'); const axios = require('axios').default; const tracerHandlers = require('./express-tracer-handlers'); +const redisPromise = require('./setup-redis').redis; // Setup express const app = express(); @@ -19,10 +17,15 @@ const PORT = 8080; * Redis Routes are set up async since we resolve the client once it is successfully connected */ async function setupRoutes() { - const redis = await require('./setup-redis').redis; + const redis = await redisPromise; app.get('/run_test', async (req, res) => { - const uuid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + const uuid = Math.random() + .toString(36) + .substring(2, 15) + + Math.random() + .toString(36) + .substring(2, 15); await axios.get(`http://localhost:${PORT}/set?args=uuid,${uuid}`); const body = await axios.get(`http://localhost:${PORT}/get?args=uuid`); @@ -39,12 +42,12 @@ async function setupRoutes() { return; } - const cmd = req.params.cmd; + const { cmd } = req.params; const args = req.query.args.split(','); redis[cmd].call(redis, ...args, (err, result) => { if (err) { res.sendStatus(400); - } else if(result) { + } else if (result) { res.status(200).send(result); } else { throw new Error('Empty redis response'); @@ -58,5 +61,5 @@ app.use(tracerHandlers.getMiddlewareTracer(tracer)); setupRoutes().then(() => { app.use(tracerHandlers.getErrorTracer(tracer)); app.listen(PORT); - console.log(`Listening on http://localhost:${PORT}`) + console.log(`Listening on http://localhost:${PORT}`); }); diff --git a/examples/redis/setup-redis.js b/examples/redis/setup-redis.js index dba4f0ebad3..59b2e189b54 100644 --- a/examples/redis/setup-redis.js +++ b/examples/redis/setup-redis.js @@ -1,13 +1,15 @@ +'use strict'; + const redis = require('redis'); const client = redis.createClient('redis://localhost:6379'); -const redisPromise = new Promise(function(resolve, reject) { +const redisPromise = new Promise(((resolve, reject) => { client.once('ready', () => { resolve(client); }); client.once('error', (error) => { reject(error); }); -}); +})); exports.redis = redisPromise; diff --git a/examples/http/setup.js b/examples/redis/tracer.js similarity index 83% rename from examples/http/setup.js rename to examples/redis/tracer.js index 770cdd5dfd3..fa2680830aa 100644 --- a/examples/http/setup.js +++ b/examples/redis/tracer.js @@ -5,19 +5,21 @@ const { NodeTracerRegistry } = require('@opentelemetry/node'); const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); + const EXPORTER = process.env.EXPORTER || ''; -function setupTracerAndExporters(service) { + +module.exports = (serviceName) => { const registry = new NodeTracerRegistry(); let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ - serviceName: service, + serviceName, }); } else { exporter = new JaegerExporter({ - serviceName: service, + serviceName, }); } @@ -25,6 +27,6 @@ function setupTracerAndExporters(service) { // Initialize the OpenTelemetry APIs to use the BasicTracerRegistry bindings opentelemetry.initGlobalTracerRegistry(registry); -} -exports.setupTracerAndExporters = setupTracerAndExporters; + return opentelemetry.getTracer(); +}; diff --git a/examples/stackdriver-trace/index.js b/examples/stackdriver-trace/index.js index 809fc4e8f0d..277ddba4317 100644 --- a/examples/stackdriver-trace/index.js +++ b/examples/stackdriver-trace/index.js @@ -8,7 +8,7 @@ const { StackdriverTraceExporter } = require('@opentelemetry/exporter-stackdrive // Initialize an exporter const exporter = new StackdriverTraceExporter({ serviceName: 'basic-service', - logger: new opentelemetry.ConsoleLogger() + logger: new opentelemetry.ConsoleLogger(), }); const tracer = new BasicTracer(); @@ -22,17 +22,17 @@ opentelemetry.initGlobalTracer(tracer); // Create a span. A span must be closed. const root = opentelemetry.getTracer().startSpan('main'); const related = opentelemetry.getTracer().startSpan('related', { - links: [{ spanContext: root.context() }] + links: [{ spanContext: root.context() }], }); -for (let i = 0; i < 10; i++) { +for (let i = 0; i < 10; i += 1) { doWork(root); doWork(related); } // Be sure to end the span. root.setStatus({ - code: CanonicalCode.UNKNOWN -}) + code: CanonicalCode.UNKNOWN, +}); root.end(); related.end(); @@ -43,17 +43,19 @@ function doWork(parent) { // Start another span. In this example, the main method already started a // span, so that'll be the parent span, and this will be a child span. const span = opentelemetry.getTracer().startSpan('doWork', { - parent: parent + parent, }); // simulate some random work. const work = Math.floor(Math.random() * 40000000); - for (let i = 0; i <= work; i++) { } + for (let i = 0; i <= work; i += 1) { + // empty + } if (work % 2 === 1) { span.setStatus({ - code: CanonicalCode.UNKNOWN - }) + code: CanonicalCode.UNKNOWN, + }); } // Set attributes to the span. diff --git a/examples/stackdriver-trace/package.json b/examples/stackdriver-trace/package.json index d464707d564..a670009ef69 100644 --- a/examples/stackdriver-trace/package.json +++ b/examples/stackdriver-trace/package.json @@ -1,7 +1,7 @@ { "name": "example-stackdriver-trace", "private": true, - "version": "0.3.1", + "version": "0.3.3", "description": "Example of using @opentelemetry/exporter-stackdriver-trace in Node.js", "main": "index.js", "scripts": { @@ -25,10 +25,10 @@ "url": "https://github.com/open-telemetry/opentelemetry-js/issues" }, "dependencies": { - "@opentelemetry/core": "^0.3.1", - "@opentelemetry/exporter-stackdriver-trace": "^0.3.1", - "@opentelemetry/tracing": "^0.3.1", - "@opentelemetry/types": "^0.3.1" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-stackdriver-trace": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/examples/tracer-web/.eslintrc b/examples/tracer-web/.eslintrc new file mode 100644 index 00000000000..e2338e5e0b6 --- /dev/null +++ b/examples/tracer-web/.eslintrc @@ -0,0 +1,16 @@ +{ + "env": { + "node": true + }, + "extends": "airbnb-base", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "strict": ["error", "global"], + "no-use-before-define": ["error", "nofunc"], + "no-console": "off", + "import/no-unresolved": "off", + "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] + } +} diff --git a/examples/tracer-web/examples/document-load/index.js b/examples/tracer-web/examples/document-load/index.js index bd42b14797c..77b7248825d 100644 --- a/examples/tracer-web/examples/document-load/index.js +++ b/examples/tracer-web/examples/document-load/index.js @@ -2,43 +2,61 @@ import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing import { WebTracerRegistry } from '@opentelemetry/web'; import { DocumentLoad } from '@opentelemetry/plugin-document-load'; import { ZoneScopeManager } from '@opentelemetry/scope-zone'; -import { CollectorExporter } from '@opentelemetry/exporter-collector' +import { CollectorExporter } from '@opentelemetry/exporter-collector'; const registry = new WebTracerRegistry({ plugins: [ - new DocumentLoad() - ] + new DocumentLoad(), + ], }); registry.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); const registryWithZone = new WebTracerRegistry({ scopeManager: new ZoneScopeManager(), plugins: [ - new DocumentLoad() - ] + new DocumentLoad(), + ], }); registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); registryWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); const tracerWithZone = registryWithZone.getTracer('example-tracer-web'); +let window; console.log('Current span is window', tracerWithZone.getCurrentSpan() === window); +const getData = (url) => new Promise((resolve, reject) => { + // eslint-disable-next-line no-undef + const req = new XMLHttpRequest(); + req.open('GET', url, true); + req.send(); + req.onload = () => { + let json; + try { + json = JSON.parse(req.responseText); + } catch (e) { + reject(e); + } + resolve(json); + }; +}); + // example of keeping track of scope between async operations const prepareClickEvent = () => { const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/package.json'; const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/packages/opentelemetry-web/package.json'; + let document; const element = document.getElementById('button1'); - let mainSpan = tracerWithZone.startSpan('main-span'); + const mainSpan = tracerWithZone.startSpan('main-span'); tracerWithZone.bind(element, mainSpan); const onClick = () => { - const span1 = tracerWithZone.startSpan(`files-series-info-1`, { - parent: tracerWithZone.getCurrentSpan() + const span1 = tracerWithZone.startSpan('files-series-info-1', { + parent: tracerWithZone.getCurrentSpan(), }); - const span2 = tracerWithZone.startSpan(`files-series-info-2`, { - parent: tracerWithZone.getCurrentSpan() + const span2 = tracerWithZone.startSpan('files-series-info-2', { + parent: tracerWithZone.getCurrentSpan(), }); tracerWithZone.withSpan(span1, () => { @@ -64,21 +82,4 @@ const prepareClickEvent = () => { element.addEventListener('click', onClick); }; -const getData = (url) => { - return new Promise(async (resolve, reject) => { - const req = new XMLHttpRequest(); - req.open('GET', url, true); - req.send(); - req.onload = function () { - let json; - try { - json = JSON.parse(req.responseText); - } catch (e) { - reject(e); - } - resolve(json); - }; - }); -}; - window.addEventListener('load', prepareClickEvent); diff --git a/examples/tracer-web/examples/xml-http-request/index.js b/examples/tracer-web/examples/xml-http-request/index.js index 9e5ff9d2e3b..d6698223d6a 100644 --- a/examples/tracer-web/examples/xml-http-request/index.js +++ b/examples/tracer-web/examples/xml-http-request/index.js @@ -1,4 +1,3 @@ -'use strict'; import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; import { WebTracer } from '@opentelemetry/web'; @@ -14,28 +13,41 @@ const webTracerWithZone = new WebTracer({ new XMLHttpRequestPlugin({ ignoreUrls: [/localhost:8090\/sockjs-node/], propagateTraceHeaderCorsUrls: [ - 'https://httpbin.org/get' - ] - }) - ] + 'https://httpbin.org/get', + ], + }), + ], }); webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); +const getData = (url) => new Promise((resolve, _reject) => { + // eslint-disable-next-line no-undef + const req = new XMLHttpRequest(); + req.open('GET', url, true); + req.setRequestHeader('Content-Type', 'application/json'); + req.setRequestHeader('Accept', 'application/json'); + req.send(); + req.onload = () => { + resolve(); + }; +}); + // example of keeping track of scope between async operations const prepareClickEvent = () => { const url1 = 'https://httpbin.org/get'; + let document; const element = document.getElementById('button1'); const onClick = () => { - for (let i = 0, j = 5; i < j; i++) { + for (let i = 0, j = 5; i < j; i += 1) { const span1 = webTracerWithZone.startSpan(`files-series-info-${i}`, { - parent: webTracerWithZone.getCurrentSpan() + parent: webTracerWithZone.getCurrentSpan(), }); webTracerWithZone.withSpan(span1, () => { - getData(url1).then((data) => { + getData(url1).then((_data) => { webTracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed'); span1.end(); }); @@ -45,17 +57,5 @@ const prepareClickEvent = () => { element.addEventListener('click', onClick); }; -const getData = (url) => { - return new Promise(async (resolve, reject) => { - const req = new XMLHttpRequest(); - req.open('GET', url, true); - req.setRequestHeader('Content-Type', 'application/json'); - req.setRequestHeader('Accept', 'application/json'); - req.send(); - req.onload = function () { - resolve(); - }; - }); -}; - +let window; window.addEventListener('load', prepareClickEvent); diff --git a/examples/tracer-web/package.json b/examples/tracer-web/package.json index f4b30248677..ac246d9c1a8 100644 --- a/examples/tracer-web/package.json +++ b/examples/tracer-web/package.json @@ -1,7 +1,7 @@ { "name": "web-tracer-example", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Example of using @opentelemetry/web in browser", "main": "index.js", "scripts": { @@ -34,12 +34,12 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/exporter-collector": "^0.3.2", - "@opentelemetry/plugin-document-load": "^0.3.2", - "@opentelemetry/plugin-xml-http-request": "^0.3.2", - "@opentelemetry/scope-zone": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/web": "^0.3.2" + "@opentelemetry/exporter-collector": "^0.3.3", + "@opentelemetry/plugin-document-load": "^0.3.3", + "@opentelemetry/plugin-xml-http-request": "^0.3.3", + "@opentelemetry/scope-zone": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/web": "^0.3.3" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme" } diff --git a/examples/tracer-web/webpack.config.js b/examples/tracer-web/webpack.config.js index a73bffb8e6d..8f7fed9410e 100644 --- a/examples/tracer-web/webpack.config.js +++ b/examples/tracer-web/webpack.config.js @@ -1,18 +1,19 @@ const webpack = require('webpack'); const webpackMerge = require('webpack-merge'); const path = require('path'); + const directory = path.resolve(__dirname); const common = { mode: 'development', entry: { 'document-load': 'examples/document-load/index.js', - 'xml-http-request': 'examples/xml-http-request/index.js' + 'xml-http-request': 'examples/xml-http-request/index.js', }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js', - sourceMapFilename: '[file].map' + sourceMapFilename: '[file].map', }, target: 'web', module: { @@ -21,35 +22,35 @@ const common = { test: /\.js[x]?$/, exclude: /(node_modules)/, use: { - loader: 'babel-loader' - } + loader: 'babel-loader', + }, }, { test: /\.ts$/, exclude: /(node_modules)/, use: { - loader: 'ts-loader' - } - } - ] + loader: 'ts-loader', + }, + }, + ], }, resolve: { modules: [ path.resolve(directory), - 'node_modules' + 'node_modules', ], - extensions: ['.ts', '.js', '.jsx', '.json'] - } + extensions: ['.ts', '.js', '.jsx', '.json'], + }, }; module.exports = webpackMerge(common, { devtool: 'eval-source-map', devServer: { - contentBase: path.resolve(__dirname) + contentBase: path.resolve(__dirname), }, plugins: [ new webpack.DefinePlugin({ - 'process.env.NODE_ENV': JSON.stringify('development') - }) - ] + 'process.env.NODE_ENV': JSON.stringify('development'), + }), + ], }); diff --git a/getting-started/README.md b/getting-started/README.md index e5129c46941..61ae41d7e88 100644 --- a/getting-started/README.md +++ b/getting-started/README.md @@ -74,13 +74,13 @@ Create a file named `tracing.js` and add the following code: 'use strict'; const opentelemetry = require("@opentelemetry/core"); -const { NodeTracer } = require("@opentelemetry/node"); +const { NodeTracerRegistry } = require("@opentelemetry/node"); -const tracer = new NodeTracer({ +const tracerRegistry = new NodeTracerRegistry({ logLevel: opentelemetry.LogLevel.ERROR }); -opentelemetry.initGlobalTracer(tracer); +opentelemetry.initGlobalTracerRegistry(tracerRegistry); ``` If you run your application now with `node -r ./tracing.js app.js`, your application will create and propagate traces over HTTP. If an already instrumented service that supports [Trace Context](https://www.w3.org/TR/trace-context/) headers calls your application using HTTP, and you call another application using HTTP, the Trace Context headers will be correctly propagated. @@ -110,18 +110,18 @@ After these dependencies are installed, we will need to initialize and register 'use strict'; const opentelemetry = require("@opentelemetry/core"); -const { NodeTracer } = require("@opentelemetry/node"); +const { NodeTracerRegistry } = require("@opentelemetry/node"); const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); -const tracer = new NodeTracer({ +const tracerRegistry = new NodeTracerRegistry({ logLevel: opentelemetry.LogLevel.ERROR }); -opentelemetry.initGlobalTracer(tracer); +opentelemetry.initGlobalTracerRegistry(tracerRegistry); -tracer.addSpanProcessor( +tracerRegistry.addSpanProcessor( new SimpleSpanProcessor( new ZipkinExporter({ serviceName: "getting-started", @@ -238,9 +238,9 @@ Create a file named `monitoring.js` and add the following code: ```javascript 'use strict'; -const { Meter } = require("@opentelemetry/metrics"); +const { MeterRegistry } = require('@opentelemetry/metrics'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); ``` Now, you can require this file from your application code and use the `Meter` to create and manage metrics. The simplest of these metrics is a counter. Let's create and export from our `monitoring.js` file a middleware function that express can use to count all requests by route. Modify the `monitoring.js` file so that it looks like this: @@ -248,9 +248,9 @@ Now, you can require this file from your application code and use the `Meter` to ```javascript 'use strict'; -const { Meter } = require("@opentelemetry/metrics"); +const { MeterRegistry } = require('@opentelemetry/metrics'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const requestCount = meter.createCounter("requests", { monotonic: true, @@ -301,10 +301,10 @@ Next, modify your `monitoring.js` file to look like this: ```javascript "use strict"; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); meter.addExporter( new PrometheusExporter( diff --git a/getting-started/monitored-example/monitoring.js b/getting-started/monitored-example/monitoring.js index 8eb1984f68f..4567c158d15 100644 --- a/getting-started/monitored-example/monitoring.js +++ b/getting-started/monitored-example/monitoring.js @@ -1,9 +1,9 @@ "use strict"; -const { Meter } = require("@opentelemetry/metrics"); -const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus"); +const { MeterRegistry } = require('@opentelemetry/metrics'); +const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-monitored'); meter.addExporter( new PrometheusExporter( diff --git a/getting-started/monitored-example/package.json b/getting-started/monitored-example/package.json index df4bedf42d9..17e17a8c895 100644 --- a/getting-started/monitored-example/package.json +++ b/getting-started/monitored-example/package.json @@ -9,7 +9,7 @@ "author": "OpenTelemetry Authors", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/metrics": "^0.3.2", + "@opentelemetry/metrics": "^0.3.3", "axios": "^0.19.0", "express": "^4.17.1" } diff --git a/getting-started/traced-example/package.json b/getting-started/traced-example/package.json index 3114281b73c..2161b7bd20c 100644 --- a/getting-started/traced-example/package.json +++ b/getting-started/traced-example/package.json @@ -9,11 +9,11 @@ "author": "OpenTelemetry Authors", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "axios": "^0.19.0", "express": "^4.17.1" } diff --git a/getting-started/traced-example/tracing.js b/getting-started/traced-example/tracing.js index 6a4007f3073..4f265d05393 100644 --- a/getting-started/traced-example/tracing.js +++ b/getting-started/traced-example/tracing.js @@ -1,13 +1,13 @@ "use strict"; const opentelemetry = require("@opentelemetry/core"); -const { NodeTracer } = require("@opentelemetry/node"); +const { NodeTracerRegistry } = require("@opentelemetry/node"); const { SimpleSpanProcessor } = require("@opentelemetry/tracing"); const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin"); -const tracer = new NodeTracer({ logLevel: opentelemetry.LogLevel.ERROR }); -opentelemetry.initGlobalTracer(tracer); +const tracerRegistry = new NodeTracerRegistry({ logLevel: opentelemetry.LogLevel.ERROR }); +opentelemetry.initGlobalTracerRegistry(tracerRegistry); tracer.addSpanProcessor( new SimpleSpanProcessor( diff --git a/getting-started/ts-example/README.md b/getting-started/ts-example/README.md index 0a76f4a6589..ac188fcfb46 100644 --- a/getting-started/ts-example/README.md +++ b/getting-started/ts-example/README.md @@ -72,8 +72,8 @@ All tracing initialization should happen before your application’s code runs. Create a file named `tracing.ts` and add the following code: ```typescript -import * as opentelemetry from "@opentelemetry/core"; -import { NodeTracer } from "@opentelemetry/node"; +import * as opentelemetry from '@opentelemetry/core'; +import { NodeTracer } from '@opentelemetry/node'; const tracer: NodeTracer = new NodeTracer({ logLevel: opentelemetry.LogLevel.ERROR @@ -106,13 +106,13 @@ $ # npm install @opentelemetry/exporter-jaeger After these dependencies are installed, we will need to initialize and register them. Modify `tracing.ts` so that it matches the following code snippet, replacing the service name `"getting-started"` with your own service name if you wish. ```typescript -import * as opentelemetry from "@opentelemetry/core"; -import { NodeTracer } from "@opentelemetry/node"; +import * as opentelemetry from '@opentelemetry/core'; +import { NodeTracer } from '@opentelemetry/node'; -import { SimpleSpanProcessor } from "@opentelemetry/tracing"; -import { ZipkinExporter } from "@opentelemetry/exporter-zipkin"; +import { SimpleSpanProcessor } from '@opentelemetry/tracing'; +import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; // For Jaeger, use the following line instead: -// import { JaegerExporter } from "@opentelemetry/exporter-jaeger"; +// import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; const tracer: NodeTracer = new NodeTracer({ logLevel: opentelemetry.LogLevel.ERROR @@ -236,18 +236,18 @@ In order to create and monitor metrics, we will need a `Meter`. In OpenTelemetry Create a file named `monitoring.ts` and add the following code: ```typescript -import { Meter } from "@opentelemetry/metrics"; +import { MeterRegistry } from '@opentelemetry/metrics'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); ``` Now, you can require this file from your application code and use the `Meter` to create and manage metrics. The simplest of these metrics is a counter. Let's create and export from our `monitoring.ts` file a middleware function that express can use to count all requests by route. Modify the `monitoring.ts` file so that it looks like this: ```typescript -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const requestCount: Metric = meter.createCounter("requests", { monotonic: true, @@ -296,11 +296,11 @@ $ npm install @opentelemetry/exporter-prometheus Next, modify your `monitoring.ts` file to look like this: ```typescript -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; -import { PrometheusExporter } from "@opentelemetry/exporter-prometheus"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; +import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); meter.addExporter( new PrometheusExporter({ startServer: true }, () => { diff --git a/getting-started/ts-example/monitoring.ts b/getting-started/ts-example/monitoring.ts index e510eccdde1..1dd3b570376 100644 --- a/getting-started/ts-example/monitoring.ts +++ b/getting-started/ts-example/monitoring.ts @@ -1,8 +1,8 @@ -import { Meter } from "@opentelemetry/metrics"; -import { Metric, BoundCounter } from "@opentelemetry/types"; -import { PrometheusExporter } from "@opentelemetry/exporter-prometheus"; +import { MeterRegistry } from '@opentelemetry/metrics'; +import { Metric, BoundCounter } from '@opentelemetry/types'; +import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('example-ts'); meter.addExporter( new PrometheusExporter({ startServer: true }, () => { diff --git a/getting-started/ts-example/package.json b/getting-started/ts-example/package.json index 20c0da256b7..cb80ec9eada 100644 --- a/getting-started/ts-example/package.json +++ b/getting-started/ts-example/package.json @@ -13,14 +13,14 @@ "ts-node": "^8.6.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/exporter-prometheus": "^0.3.2", - "@opentelemetry/exporter-zipkin": "^0.3.2", - "@opentelemetry/metrics": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/exporter-prometheus": "^0.3.3", + "@opentelemetry/exporter-zipkin": "^0.3.3", + "@opentelemetry/metrics": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "axios": "^0.19.1", "express": "^4.17.1" } diff --git a/getting-started/ts-example/tracing.ts b/getting-started/ts-example/tracing.ts index 056217fb769..ddaac1a760e 100644 --- a/getting-started/ts-example/tracing.ts +++ b/getting-started/ts-example/tracing.ts @@ -1,16 +1,15 @@ import * as opentelemetry from "@opentelemetry/core"; -import { NodeTracer } from "@opentelemetry/node"; - +import { NodeTracerRegistry } from "@opentelemetry/node"; import { SimpleSpanProcessor } from "@opentelemetry/tracing"; import { ZipkinExporter } from "@opentelemetry/exporter-zipkin"; -const tracer: NodeTracer = new NodeTracer({ +const tracerRegistry: NodeTracerRegistry = new NodeTracerRegistry({ logLevel: opentelemetry.LogLevel.ERROR }); -opentelemetry.initGlobalTracer(tracer); +opentelemetry.initGlobalTracerRegistry(tracerRegistry); -tracer.addSpanProcessor( +tracerRegistry.addSpanProcessor( new SimpleSpanProcessor( new ZipkinExporter({ serviceName: "getting-started" diff --git a/lerna.json b/lerna.json index 2af68777c06..80588a388ba 100644 --- a/lerna.json +++ b/lerna.json @@ -6,7 +6,7 @@ "packages/*", "packages/opentelemetry-plugin-postgres/*" ], - "version": "0.3.2", + "version": "0.3.3", "changelog": { "repo": "open-telemetry/opentelemetry-js", "labels": { diff --git a/package.json b/package.json index 052b201c210..8f7b383bd11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opentelemetry-base", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry is a distributed tracing and stats collection framework.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -23,7 +23,9 @@ "predocs-test": "yarn docs", "docs-test": "lerna run docs-test", "docs": "lerna run docs", - "docs-deploy": "gh-pages --dist packages/opentelemetry-types/docs/out" + "docs-deploy": "gh-pages --dist packages/opentelemetry-types/docs/out", + "lint-examples": "eslint ./examples/**/*.js", + "fix-examples": "eslint ./examples/**/*.js --fix" }, "repository": "open-telemetry/opentelemetry-js", "keywords": [ @@ -40,6 +42,9 @@ "@commitlint/config-conventional": "^8.2.0", "beautify-benchmark": "^0.2.4", "benchmark": "^2.1.4", + "eslint": "^6.8.0", + "eslint-config-airbnb-base": "^14.0.0", + "eslint-plugin-import": "^2.19.1", "gh-pages": "^2.1.1", "gts": "^1.1.0", "husky": "^3.0.9", diff --git a/packages/opentelemetry-base/package.json b/packages/opentelemetry-base/package.json index 5d5d79e1f2a..927eaf09a78 100644 --- a/packages/opentelemetry-base/package.json +++ b/packages/opentelemetry-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/base", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry base provides base code for the SDK packages", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/packages/opentelemetry-base/src/version.ts b/packages/opentelemetry-base/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-base/src/version.ts +++ b/packages/opentelemetry-base/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index a4fdab6e2cc..a96e8caea4e 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/core", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Core provides default and no-op implementations of the OpenTelemetry types for trace and metrics", "main": "build/src/index.js", "browser": { @@ -78,7 +78,7 @@ "webpack": "^4.35.2" }, "dependencies": { - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/types": "^0.3.3", "semver": "^6.3.0" } } diff --git a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts index b003572f2bc..9e42f991c2f 100644 --- a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts +++ b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts @@ -14,15 +14,12 @@ * limitations under the License. */ -import { SpanContext, HttpTextFormat, TraceFlags } from '@opentelemetry/types'; +import { HttpTextFormat, SpanContext, TraceFlags } from '@opentelemetry/types'; import { TraceState } from '../../trace/TraceState'; export const TRACE_PARENT_HEADER = 'traceparent'; export const TRACE_STATE_HEADER = 'tracestate'; -const VALID_TRACE_PARENT_REGEX = /^[\da-f]{2}-[\da-f]{32}-[\da-f]{16}-[\da-f]{2}$/; -const VALID_TRACEID_REGEX = /^[0-9a-f]{32}$/i; -const VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i; -const INVALID_ID_REGEX = /^0+$/i; +const VALID_TRACE_PARENT_REGEX = /^00-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})$/; const VERSION = '00'; /** @@ -37,33 +34,19 @@ const VERSION = '00'; */ export function parseTraceParent(traceParent: string): SpanContext | null { const match = traceParent.match(VALID_TRACE_PARENT_REGEX); - if (!match) return null; - const parts = traceParent.split('-'); - const [version, traceId, spanId, option] = parts; - // tslint:disable-next-line:ban Needed to parse hexadecimal. - const traceFlags = parseInt(option, 16); - if ( - !isValidVersion(version) || - !isValidTraceId(traceId) || - !isValidSpanId(spanId) + !match || + match[1] === '00000000000000000000000000000000' || + match[2] === '0000000000000000' ) { return null; } - return { traceId, spanId, traceFlags }; -} - -function isValidVersion(version: string): boolean { - return version === VERSION; -} - -function isValidTraceId(traceId: string): boolean { - return VALID_TRACEID_REGEX.test(traceId) && !INVALID_ID_REGEX.test(traceId); -} - -function isValidSpanId(spanId: string): boolean { - return VALID_SPANID_REGEX.test(spanId) && !INVALID_ID_REGEX.test(spanId); + return { + traceId: match[1], + spanId: match[2], + traceFlags: parseInt(match[3], 16), + }; } /** diff --git a/packages/opentelemetry-core/src/metrics/NoopMeter.ts b/packages/opentelemetry-core/src/metrics/NoopMeter.ts index 4f67d4c2d6c..5e63905ae57 100644 --- a/packages/opentelemetry-core/src/metrics/NoopMeter.ts +++ b/packages/opentelemetry-core/src/metrics/NoopMeter.ts @@ -165,6 +165,8 @@ export class NoopBoundMeasure implements BoundMeasure { } } +export const noopMeter = new NoopMeter(); + export const NOOP_BOUND_GAUGE = new NoopBoundGauge(); export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_BOUND_GAUGE); diff --git a/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts b/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts new file mode 100644 index 00000000000..ab2a28e0ec9 --- /dev/null +++ b/packages/opentelemetry-core/src/metrics/NoopMeterRegistry.ts @@ -0,0 +1,28 @@ +/*! + * 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. + */ + +import * as types from '@opentelemetry/types'; +import { noopMeter } from './NoopMeter'; + +/** + * An implementation of the {@link MeterRegistry} which returns an impotent Meter + * for all calls to `getMeter` + */ +export class NoopMeterRegistry implements types.MeterRegistry { + getMeter(_name?: string, _version?: string): types.Meter { + return noopMeter; + } +} diff --git a/packages/opentelemetry-core/src/trace/NoopSpan.ts b/packages/opentelemetry-core/src/trace/NoopSpan.ts index 84a5cf4241e..a6fb36da30d 100644 --- a/packages/opentelemetry-core/src/trace/NoopSpan.ts +++ b/packages/opentelemetry-core/src/trace/NoopSpan.ts @@ -15,7 +15,6 @@ */ import * as types from '@opentelemetry/types'; -import { SpanContext } from '@opentelemetry/types'; import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils'; /** @@ -25,7 +24,7 @@ import { INVALID_SPAN_CONTEXT } from '../trace/spancontext-utils'; */ export class NoopSpan implements types.Span { constructor( - private readonly _spanContext: SpanContext = INVALID_SPAN_CONTEXT + private readonly _spanContext: types.SpanContext = INVALID_SPAN_CONTEXT ) {} // Returns a SpanContext. diff --git a/packages/opentelemetry-core/src/version.ts b/packages/opentelemetry-core/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-core/src/version.ts +++ b/packages/opentelemetry-core/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts b/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts index ade4d930259..1e15fdb6b5b 100644 --- a/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts +++ b/packages/opentelemetry-core/test/metrics/NoopMeter.test.ts @@ -16,7 +16,6 @@ import * as assert from 'assert'; import { - NoopMeter, NOOP_BOUND_GAUGE, NOOP_GAUGE_METRIC, NOOP_BOUND_COUNTER, @@ -25,10 +24,11 @@ import { NOOP_MEASURE_METRIC, } from '../../src/metrics/NoopMeter'; import { Labels } from '@opentelemetry/types'; +import { NoopMeterRegistry } from '../../src/metrics/NoopMeterRegistry'; describe('NoopMeter', () => { it('should not crash', () => { - const meter = new NoopMeter(); + const meter = new NoopMeterRegistry().getMeter('test-noop'); const counter = meter.createCounter('some-name'); const labels = {} as Labels; const labelSet = meter.labels(labels); diff --git a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts index 4fc5ae0c05a..71f1051ebad 100644 --- a/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts +++ b/packages/opentelemetry-core/test/trace/globaltracer-utils.test.ts @@ -21,7 +21,6 @@ import { initGlobalTracerRegistry, } from '../../src/trace/globaltracer-utils'; import { NoopTracer, NoopSpan } from '../../src'; -import { TraceFlags } from '@opentelemetry/types'; import { NoopTracerRegistry } from '../../src/trace/NoopTracerRegistry'; describe('globaltracer-utils', () => { @@ -43,7 +42,7 @@ describe('globaltracer-utils', () => { const spanContext = { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', - traceFlags: TraceFlags.UNSAMPLED, + traceFlags: types.TraceFlags.UNSAMPLED, }; const dummySpan = new NoopSpan(spanContext); diff --git a/packages/opentelemetry-exporter-collector/package.json b/packages/opentelemetry-exporter-collector/package.json index 93a25ac5eb7..7f978bfcb6a 100644 --- a/packages/opentelemetry-exporter-collector/package.json +++ b/packages/opentelemetry-exporter-collector/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-collector", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -79,9 +79,9 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2" + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3" } } diff --git a/packages/opentelemetry-exporter-collector/src/version.ts b/packages/opentelemetry-exporter-collector/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-exporter-collector/src/version.ts +++ b/packages/opentelemetry-exporter-collector/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index 0a024da993e..a1285e8b90b 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-jaeger", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Exporter Jaeger allows user to send collected traces to Jaeger", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -21,7 +21,8 @@ "opentelemetry", "nodejs", "tracing", - "profiling" + "profiling", + "jaeger" ], "author": "OpenTelemetry Authors", "license": "Apache-2.0", @@ -53,10 +54,10 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "jaeger-client": "^3.15.0" } } diff --git a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts index 1b1f50e6b37..4ae500f74eb 100644 --- a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts +++ b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import { SpanExporter, ReadableSpan } from '@opentelemetry/tracing'; import { ExportResult } from '@opentelemetry/base'; -import * as jaegerTypes from './types'; import { NoopLogger } from '@opentelemetry/core'; +import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing'; import * as types from '@opentelemetry/types'; +import { Socket } from 'dgram'; import { spanToThrift } from './transform'; +import * as jaegerTypes from './types'; /** * Format and sends span information to Jaeger Exporter. @@ -40,6 +41,11 @@ export class JaegerExporter implements SpanExporter { typeof config.flushTimeout === 'number' ? config.flushTimeout : 2000; this._sender = new jaegerTypes.UDPSender(config); + if (this._sender._client instanceof Socket) { + // unref socket to prevent it from keeping the process running + this._sender._client.unref(); + } + this._process = { serviceName: config.serviceName, tags: jaegerTypes.ThriftUtils.getThriftTags(tags), diff --git a/packages/opentelemetry-exporter-jaeger/src/version.ts b/packages/opentelemetry-exporter-jaeger/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-exporter-jaeger/src/version.ts +++ b/packages/opentelemetry-exporter-jaeger/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-exporter-prometheus/README.md b/packages/opentelemetry-exporter-prometheus/README.md index 67cb64ba4d4..0fddcd8bfc2 100644 --- a/packages/opentelemetry-exporter-prometheus/README.md +++ b/packages/opentelemetry-exporter-prometheus/README.md @@ -22,14 +22,14 @@ Create & register the exporter on your application. ```js const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Add your port and startServer to the Prometheus options const options = {port: 9464, startServer: true}; const exporter = new PrometheusExporter(options); // Register the exporter -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('exporter-prometheus'); meter.addExporter(exporter); // Now, start recording data diff --git a/packages/opentelemetry-exporter-prometheus/package.json b/packages/opentelemetry-exporter-prometheus/package.json index ab4e1cf4d88..b0d657da60e 100644 --- a/packages/opentelemetry-exporter-prometheus/package.json +++ b/packages/opentelemetry-exporter-prometheus/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-prometheus", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -53,10 +53,10 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/metrics": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/metrics": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "prom-client": "^11.5.3" } } diff --git a/packages/opentelemetry-exporter-prometheus/src/version.ts b/packages/opentelemetry-exporter-prometheus/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-exporter-prometheus/src/version.ts +++ b/packages/opentelemetry-exporter-prometheus/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts b/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts index 16cec538850..a019dc84204 100644 --- a/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts +++ b/packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { CounterMetric, GaugeMetric, Meter } from '@opentelemetry/metrics'; +import { + CounterMetric, + GaugeMetric, + Meter, + MeterRegistry, +} from '@opentelemetry/metrics'; import * as assert from 'assert'; import * as http from 'http'; import { PrometheusExporter } from '../src'; @@ -166,7 +171,7 @@ describe('PrometheusExporter', () => { beforeEach(done => { exporter = new PrometheusExporter(); - meter = new Meter(); + meter = new MeterRegistry().getMeter('test-prometheus'); exporter.startServer(done); }); @@ -382,7 +387,7 @@ describe('PrometheusExporter', () => { let exporter: PrometheusExporter | undefined; beforeEach(() => { - meter = new Meter(); + meter = new MeterRegistry().getMeter('test-prometheus'); gauge = meter.createGauge('gauge') as GaugeMetric; gauge.bind(meter.labels({ key1: 'labelValue1' })).set(10); }); diff --git a/packages/opentelemetry-exporter-stackdriver-trace/package.json b/packages/opentelemetry-exporter-stackdriver-trace/package.json index a6d0e2b5d9f..d914773f510 100644 --- a/packages/opentelemetry-exporter-stackdriver-trace/package.json +++ b/packages/opentelemetry-exporter-stackdriver-trace/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-stackdriver-trace", - "version": "0.3.1", + "version": "0.3.3", "description": "OpenTelemetry StackDriver Trace Exporter allows the user to send collected traces to StackDriver Trace.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -59,10 +59,10 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.1", - "@opentelemetry/core": "^0.3.1", - "@opentelemetry/tracing": "^0.3.1", - "@opentelemetry/types": "^0.3.1", + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "google-auth-library": "^5.7.0", "googleapis": "^46.0.0" } diff --git a/packages/opentelemetry-exporter-stackdriver-trace/src/version.ts b/packages/opentelemetry-exporter-stackdriver-trace/src/version.ts index 60ca3ab548f..d2d10b02a61 100644 --- a/packages/opentelemetry-exporter-stackdriver-trace/src/version.ts +++ b/packages/opentelemetry-exporter-stackdriver-trace/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.1'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index b323a0dd9be..ba53d81b703 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/exporter-zipkin", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Zipkin Exporter allows the user to send collected traces to Zipkin.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -55,9 +55,9 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2" + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3" } } diff --git a/packages/opentelemetry-exporter-zipkin/src/version.ts b/packages/opentelemetry-exporter-zipkin/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-exporter-zipkin/src/version.ts +++ b/packages/opentelemetry-exporter-zipkin/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-metrics/README.md b/packages/opentelemetry-metrics/README.md index a1c3b7a11b8..c48868ced6f 100644 --- a/packages/opentelemetry-metrics/README.md +++ b/packages/opentelemetry-metrics/README.md @@ -19,10 +19,10 @@ npm install --save @opentelemetry/metrics Choose this kind of metric when the value is a quantity, the sum is of primary interest, and the event count and value distribution are not of primary interest. Counters are defined as `Monotonic = true` by default, meaning that positive values are expected. ```js -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Initialize the Meter to capture measurements in various ways. -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const counter = meter.createCounter('metric_name', { labelKeys: ["pid"], @@ -40,10 +40,10 @@ boundCounter.add(10); Gauge metrics express a pre-calculated value. Generally, this kind of metric should be used when the metric cannot be expressed as a sum or because the measurement interval is arbitrary. Use this kind of metric when the measurement is not a quantity, and the sum and event count are not of interest. Gauges are defined as `Monotonic = false` by default, meaning that new values are permitted to make positive or negative changes to the gauge. There is no restriction on the sign of the input for gauges. ```js -const { Meter } = require('@opentelemetry/metrics'); +const { MeterRegistry } = require('@opentelemetry/metrics'); // Initialize the Meter to capture measurements in various ways. -const meter = new Meter(); +const meter = new MeterRegistry().getMeter('your-meter-name'); const gauge = meter.createGauge('metric_name', { labelKeys: ["pid"], diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index 967fc53abe4..6336ad4c9ee 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/metrics", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry metrics SDK", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -56,8 +56,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2" + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3" } } diff --git a/packages/opentelemetry-metrics/src/MeterRegistry.ts b/packages/opentelemetry-metrics/src/MeterRegistry.ts new file mode 100644 index 00000000000..c9eb6836635 --- /dev/null +++ b/packages/opentelemetry-metrics/src/MeterRegistry.ts @@ -0,0 +1,46 @@ +/*! + * 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. + */ + +import { ConsoleLogger } from '@opentelemetry/core'; +import * as types from '@opentelemetry/types'; +import { Meter } from '.'; +import { DEFAULT_CONFIG, MeterConfig } from './types'; + +/** + * This class represents a meter registry which platform libraries can extend + */ +export class MeterRegistry implements types.MeterRegistry { + private readonly _meters: Map = new Map(); + readonly logger: types.Logger; + + constructor(private _config: MeterConfig = DEFAULT_CONFIG) { + this.logger = _config.logger || new ConsoleLogger(_config.logLevel); + } + + /** + * Returns a Meter, creating one if one with the given name and version is not already created + * + * @returns Meter A Meter with the given name and version + */ + getMeter(name: string, version = '*', config?: MeterConfig): Meter { + const key = `${name}@${version}`; + if (!this._meters.has(key)) { + this._meters.set(key, new Meter(config || this._config)); + } + + return this._meters.get(key)!; + } +} diff --git a/packages/opentelemetry-metrics/src/index.ts b/packages/opentelemetry-metrics/src/index.ts index 0cd212f0b5b..9a8b7f26d21 100644 --- a/packages/opentelemetry-metrics/src/index.ts +++ b/packages/opentelemetry-metrics/src/index.ts @@ -17,5 +17,6 @@ export * from './BoundInstrument'; export * from './Meter'; export * from './Metric'; +export * from './MeterRegistry'; export * from './export/ConsoleMetricExporter'; export * from './export/types'; diff --git a/packages/opentelemetry-metrics/src/version.ts b/packages/opentelemetry-metrics/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-metrics/src/version.ts +++ b/packages/opentelemetry-metrics/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-metrics/test/Meter.test.ts b/packages/opentelemetry-metrics/test/Meter.test.ts index 57e19ceffe1..f0269a5b24a 100644 --- a/packages/opentelemetry-metrics/test/Meter.test.ts +++ b/packages/opentelemetry-metrics/test/Meter.test.ts @@ -31,6 +31,7 @@ import { hrTimeToMilliseconds, } from '@opentelemetry/core'; import { NoopExporter } from './mocks/Exporter'; +import { MeterRegistry } from '../src/MeterRegistry'; const performanceTimeOrigin = hrTime(); @@ -43,9 +44,9 @@ describe('Meter', () => { const hrTime: types.HrTime = [22, 400000000]; beforeEach(() => { - meter = new Meter({ + meter = new MeterRegistry({ logger: new NoopLogger(), - }); + }).getMeter('test-meter'); labelSet = meter.labels(labels); }); diff --git a/packages/opentelemetry-metrics/test/MeterRegistry.test.ts b/packages/opentelemetry-metrics/test/MeterRegistry.test.ts new file mode 100644 index 00000000000..e90b6c9baa4 --- /dev/null +++ b/packages/opentelemetry-metrics/test/MeterRegistry.test.ts @@ -0,0 +1,68 @@ +/*! + * 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. + */ + +import { NoopLogger } from '@opentelemetry/core'; +import * as assert from 'assert'; +import { MeterRegistry, Meter } from '../src'; + +describe('MeterRegistry', () => { + describe('constructor', () => { + it('should construct an instance without any options', () => { + const registry = new MeterRegistry(); + assert.ok(registry instanceof MeterRegistry); + }); + + it('should construct an instance with logger', () => { + const registry = new MeterRegistry({ + logger: new NoopLogger(), + }); + assert.ok(registry instanceof MeterRegistry); + }); + }); + + describe('getMeter', () => { + it('should return an instance of Meter', () => { + const meter = new MeterRegistry().getMeter('test-meter-registry'); + assert.ok(meter instanceof Meter); + }); + + it('should return the meter with default version without a version option', () => { + const registry = new MeterRegistry(); + const meter1 = registry.getMeter('default'); + const meter2 = registry.getMeter('default', '*'); + assert.deepEqual(meter1, meter2); + }); + + it('should return the same Meter instance with same name & version', () => { + const registry = new MeterRegistry(); + const meter1 = registry.getMeter('meter1', 'ver1'); + const meter2 = registry.getMeter('meter1', 'ver1'); + assert.deepEqual(meter1, meter2); + }); + + it('should return different Meter instance with different name or version', () => { + const registry = new MeterRegistry(); + + const meter1 = registry.getMeter('meter1', 'ver1'); + const meter2 = registry.getMeter('meter1'); + assert.notEqual(meter1, meter2); + + const meter3 = registry.getMeter('meter2', 'ver2'); + const meter4 = registry.getMeter('meter3', 'ver2'); + assert.notEqual(meter3, meter4); + }); + }); +}); diff --git a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts index 996b4238538..4c9e17e001d 100644 --- a/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts +++ b/packages/opentelemetry-metrics/test/export/ConsoleMetricExporter.test.ts @@ -16,7 +16,8 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; -import { ConsoleMetricExporter, Meter } from '../../src'; +import { ConsoleMetricExporter } from '../../src'; +import { MeterRegistry } from '../../src/MeterRegistry'; describe('ConsoleMetricExporter', () => { let consoleExporter: ConsoleMetricExporter; @@ -36,7 +37,9 @@ describe('ConsoleMetricExporter', () => { it('should export information about metrics', () => { const spyConsole = sinon.spy(console, 'log'); - const meter = new Meter(); + const meter = new MeterRegistry().getMeter( + 'test-console-metric-exporter' + ); meter.addExporter(consoleExporter); const gauge = meter.createGauge('gauge', { description: 'a test description', diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index cd8f8f85771..ab112d2f3a7 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/node", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Node SDK provides automatic telemetry (tracing, metrics, etc) for Node.js applications", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -58,10 +58,10 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/scope-async-hooks": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/scope-async-hooks": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "require-in-the-middle": "^5.0.0", "semver": "^6.2.0" } diff --git a/packages/opentelemetry-node/src/version.ts b/packages/opentelemetry-node/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-node/src/version.ts +++ b/packages/opentelemetry-node/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-dns/package.json b/packages/opentelemetry-plugin-dns/package.json index 428b6dc127f..453d64d1868 100644 --- a/packages/opentelemetry-plugin-dns/package.json +++ b/packages/opentelemetry-plugin-dns/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-dns", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry dns automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,8 +41,8 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.7.12", "@types/semver": "^6.2.0", @@ -61,8 +61,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "semver": "^6.3.0", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-dns/src/version.ts b/packages/opentelemetry-plugin-dns/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-dns/src/version.ts +++ b/packages/opentelemetry-plugin-dns/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-document-load/package.json b/packages/opentelemetry-plugin-document-load/package.json index 5c0baa62f71..d2a4116b979 100644 --- a/packages/opentelemetry-plugin-document-load/package.json +++ b/packages/opentelemetry-plugin-document-load/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-document-load", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry document-load automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -72,9 +72,9 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", - "@opentelemetry/web": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", + "@opentelemetry/web": "^0.3.3" } } diff --git a/packages/opentelemetry-plugin-document-load/src/version.ts b/packages/opentelemetry-plugin-document-load/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-document-load/src/version.ts +++ b/packages/opentelemetry-plugin-document-load/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 5553e7fdfc2..d8340c5fd37 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-grpc", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry grpc automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,8 +41,8 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "@types/semver": "^6.2.0", @@ -63,8 +63,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-grpc/src/version.ts b/packages/opentelemetry-plugin-grpc/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-grpc/src/version.ts +++ b/packages/opentelemetry-plugin-grpc/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-http/package.json b/packages/opentelemetry-plugin-http/package.json index 4ecd9161456..adeee6a5881 100644 --- a/packages/opentelemetry-plugin-http/package.json +++ b/packages/opentelemetry-plugin-http/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-http", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry http automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,9 +41,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/scope-base": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/scope-base": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/got": "^9.6.7", "@types/mocha": "^5.2.7", "@types/nock": "^11.1.0", @@ -72,8 +72,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "semver": "^6.3.0", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-http/src/version.ts b/packages/opentelemetry-plugin-http/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-http/src/version.ts +++ b/packages/opentelemetry-plugin-http/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-https/package.json b/packages/opentelemetry-plugin-https/package.json index 512779adff0..d4ef6e79b96 100644 --- a/packages/opentelemetry-plugin-https/package.json +++ b/packages/opentelemetry-plugin-https/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-https", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry https automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,9 +41,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/scope-base": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/scope-base": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/got": "^9.6.7", "@types/mocha": "^5.2.7", "@types/nock": "^11.1.0", @@ -72,9 +72,9 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/plugin-http": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/plugin-http": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "semver": "^6.3.0", "shimmer": "^1.2.1" } diff --git a/packages/opentelemetry-plugin-https/src/version.ts b/packages/opentelemetry-plugin-https/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-https/src/version.ts +++ b/packages/opentelemetry-plugin-https/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-ioredis/package.json b/packages/opentelemetry-plugin-ioredis/package.json index e226ec68f56..ec16e8cd3c9 100644 --- a/packages/opentelemetry-plugin-ioredis/package.json +++ b/packages/opentelemetry-plugin-ioredis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-ioredis", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry ioredis automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -44,9 +44,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/test-utils": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/test-utils": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/ioredis": "^4.14.3", "@types/mocha": "^5.2.7", "@types/node": "^13.1.0", @@ -65,8 +65,8 @@ "typescript": "3.7.4" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-ioredis/src/ioredis.ts b/packages/opentelemetry-plugin-ioredis/src/ioredis.ts index 428e174057f..7d08fd0fed8 100644 --- a/packages/opentelemetry-plugin-ioredis/src/ioredis.ts +++ b/packages/opentelemetry-plugin-ioredis/src/ioredis.ts @@ -44,7 +44,7 @@ export class IORedisPlugin extends BasePlugin { this._patchConnection() ); - return this._moduleExports.prototype; + return this._moduleExports; } protected unpatch(): void { diff --git a/packages/opentelemetry-plugin-ioredis/src/version.ts b/packages/opentelemetry-plugin-ioredis/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-ioredis/src/version.ts +++ b/packages/opentelemetry-plugin-ioredis/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-mongodb/package.json b/packages/opentelemetry-plugin-mongodb/package.json index 3adcd2db513..a1cfd453f25 100644 --- a/packages/opentelemetry-plugin-mongodb/package.json +++ b/packages/opentelemetry-plugin-mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-mongodb", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry mongodb automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,8 +41,8 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/mongodb": "^3.2.3", "@types/node": "^12.7.2", @@ -60,8 +60,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-mongodb/src/version.ts b/packages/opentelemetry-plugin-mongodb/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-mongodb/src/version.ts +++ b/packages/opentelemetry-plugin-mongodb/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-mysql/package.json b/packages/opentelemetry-plugin-mysql/package.json index 119acf60b43..8cf5529cedf 100644 --- a/packages/opentelemetry-plugin-mysql/package.json +++ b/packages/opentelemetry-plugin-mysql/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-mysql", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry mysql automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -41,9 +41,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/test-utils": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/test-utils": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/mysql": "^2.15.4", "@types/node": "^12.6.9", @@ -61,8 +61,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-mysql/src/version.ts b/packages/opentelemetry-plugin-mysql/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-mysql/src/version.ts +++ b/packages/opentelemetry-plugin-mysql/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json index 0e11029dcdd..03058deffdf 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-pg-pool", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry postgres pool automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -46,8 +46,8 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/plugin-pg": "^0.3.2", - "@opentelemetry/test-utils": "^0.3.2", + "@opentelemetry/plugin-pg": "^0.3.3", + "@opentelemetry/test-utils": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "@types/pg": "^7.11.2", @@ -68,10 +68,10 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json index d21f8ef29e5..eecd8bc925b 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-pg", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry postgres automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -45,9 +45,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/test-utils": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/test-utils": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "@types/pg": "^7.11.2", @@ -65,8 +65,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-redis/package.json b/packages/opentelemetry-plugin-redis/package.json index e3dd7db93fc..675b5afdb31 100644 --- a/packages/opentelemetry-plugin-redis/package.json +++ b/packages/opentelemetry-plugin-redis/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-redis", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry redis automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,9 +43,9 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/node": "^0.3.2", - "@opentelemetry/test-utils": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/node": "^0.3.3", + "@opentelemetry/test-utils": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "@types/redis": "^2.8.14", @@ -64,8 +64,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-redis/src/version.ts b/packages/opentelemetry-plugin-redis/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-redis/src/version.ts +++ b/packages/opentelemetry-plugin-redis/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-xml-http-request/package.json b/packages/opentelemetry-plugin-xml-http-request/package.json index 099aa105356..3f7124d3975 100644 --- a/packages/opentelemetry-plugin-xml-http-request/package.json +++ b/packages/opentelemetry-plugin-xml-http-request/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/plugin-xml-http-request", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry XMLHttpRequest automatic instrumentation package.", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -44,8 +44,8 @@ }, "devDependencies": { "@babel/core": "^7.6.0", - "@opentelemetry/scope-zone": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/scope-zone": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.5", "@types/node": "^12.6.8", "@types/shimmer": "^1.0.1", @@ -76,10 +76,10 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", - "@opentelemetry/web": "^0.3.2", + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", + "@opentelemetry/web": "^0.3.3", "shimmer": "^1.2.1" } } diff --git a/packages/opentelemetry-plugin-xml-http-request/src/version.ts b/packages/opentelemetry-plugin-xml-http-request/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-plugin-xml-http-request/src/version.ts +++ b/packages/opentelemetry-plugin-xml-http-request/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts index 931e31756d6..d21736db087 100644 --- a/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts +++ b/packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts @@ -34,7 +34,6 @@ import { import { AttributeNames } from '../src/enums/AttributeNames'; import { EventNames } from '../src/enums/EventNames'; import { XMLHttpRequestPlugin } from '../src/xhr'; -import { Tracer } from '@opentelemetry/types'; class DummySpanExporter implements tracing.SpanExporter { export(spans: any) {} @@ -101,7 +100,7 @@ describe('xhr', () => { let clearData: any; describe('when request is successful', () => { - let webTracerWithZone: Tracer; + let webTracerWithZone: types.Tracer; let webTracerRegistryWithZone: WebTracerRegistry; let dummySpanExporter: DummySpanExporter; let exportSpy: any; @@ -410,7 +409,7 @@ describe('xhr', () => { describe('when request is NOT successful', () => { let webTracerWithZoneRegistry: WebTracerRegistry; - let webTracerWithZone: Tracer; + let webTracerWithZone: types.Tracer; let dummySpanExporter: DummySpanExporter; let exportSpy: any; let rootSpan: types.Span; diff --git a/packages/opentelemetry-propagator-jaeger/.npmignore b/packages/opentelemetry-propagator-jaeger/.npmignore new file mode 100644 index 00000000000..9505ba9450f --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/.npmignore @@ -0,0 +1,4 @@ +/bin +/coverage +/doc +/test diff --git a/packages/opentelemetry-propagator-jaeger/LICENSE b/packages/opentelemetry-propagator-jaeger/LICENSE new file mode 100644 index 00000000000..261eeb9e9f8 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + http://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. diff --git a/packages/opentelemetry-propagator-jaeger/README.md b/packages/opentelemetry-propagator-jaeger/README.md new file mode 100644 index 00000000000..5c6771c3a35 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/README.md @@ -0,0 +1,58 @@ +# OpenTelemetry Propagator Jaeger +[![Gitter chat][gitter-image]][gitter-url] +[![NPM Published Version][npm-img]][npm-url] +[![dependencies][dependencies-image]][dependencies-url] +[![devDependencies][devDependencies-image]][devDependencies-url] +[![Apache License][license-image]][license-image] + +OpenTelemetry Jaeger propagator provides HTTP header propagation for systems that are using Jaeger HTTP header format. + +Format: +{trace-id}:{span-id}:{parent-span-id}:{flags} + +* {trace-id} + * 64-bit or 128-bit random number in base16 format. + * Can be variable length, shorter values are 0-padded on the left. + * Value of 0 is invalid. + +* {span-id} + * 64-bit random number in base16 format. + +* {parent-span-id} + * Set to 0 because this field is deprecated. +* {flags} + * One byte bitmap, as two hex digits. + +Example of usage: +```javascript +const { NodeTracerRegistry } = require('@opentelemetry/node'); +const { JaegerHttpTraceFormat } = require('@opentelemetry/propagator-jaeger'); + +const registry = new NodeTracerRegistry({ + httpTextFormat: new JaegerHttpTraceFormat() +}); +``` + +## Trace on Jaeger UI + +![example image](jaeger-tracing.png) + +## Useful links +- For more information on OpenTelemetry, visit: +- For more about OpenTelemetry JavaScript: +- 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/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-propagator-jaeger +[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-propagator-jaeger +[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-propagator-jaeger +[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-propagator-jaeger&type=dev +[npm-url]: https://www.npmjs.com/package/@opentelemetry/propagator-jaeger +[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fpropagator-jaeger.svg diff --git a/packages/opentelemetry-propagator-jaeger/jaeger-tracing.png b/packages/opentelemetry-propagator-jaeger/jaeger-tracing.png new file mode 100644 index 00000000000..0c8693a2b51 Binary files /dev/null and b/packages/opentelemetry-propagator-jaeger/jaeger-tracing.png differ diff --git a/packages/opentelemetry-propagator-jaeger/karma.conf.js b/packages/opentelemetry-propagator-jaeger/karma.conf.js new file mode 100644 index 00000000000..edcd9f055fd --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/karma.conf.js @@ -0,0 +1,24 @@ +/*! + * Copyright 2020, 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 + * + * http://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. + */ + +const karmaWebpackConfig = require('../../karma.webpack'); +const karmaBaseConfig = require('../../karma.base'); + +module.exports = (config) => { + config.set(Object.assign({}, karmaBaseConfig, { + webpack: karmaWebpackConfig + })) +}; diff --git a/packages/opentelemetry-propagator-jaeger/package.json b/packages/opentelemetry-propagator-jaeger/package.json new file mode 100644 index 00000000000..7d77e5a5f2e --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/package.json @@ -0,0 +1,75 @@ +{ + "name": "@opentelemetry/propagator-jaeger", + "version": "0.3.3", + "description": "OpenTelemetry Jaeger propagator provides HTTP header propagation for systems that are using Jaeger HTTP header format.", + "main": "build/src/index.js", + "types": "build/src/index.d.ts", + "repository": "open-telemetry/opentelemetry-js", + "scripts": { + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts' --exclude 'test/index-webpack.ts'", + "test:browser": "nyc karma start --single-run", + "tdd": "yarn tdd:node", + "tdd:node": "yarn test -- --watch-extensions ts --watch", + "tdd:browser": "karma start", + "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", + "clean": "rimraf build/*", + "check": "gts check", + "precompile": "tsc --version", + "compile": "npm run version:update && tsc -p .", + "fix": "gts fix", + "prepare": "npm run compile", + "version:update": "node ../../scripts/version-update.js", + "watch": "tsc -w" + }, + "keywords": [ + "opentelemetry", + "nodejs", + "tracing", + "profiling", + "jaeger" + ], + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + }, + "files": [ + "build/src/**/*.js", + "build/src/**/*.d.ts", + "doc", + "LICENSE", + "README.md" + ], + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@types/mocha": "^5.2.5", + "@types/node": "^12.6.8", + "@types/sinon": "^7.0.13", + "@types/webpack-env": "1.13.9", + "codecov": "^3.6.1", + "gts": "^1.1.0", + "istanbul-instrumenter-loader": "^3.0.1", + "karma": "^4.4.1", + "karma-chrome-launcher": "^3.1.0", + "karma-coverage-istanbul-reporter": "^2.1.0", + "karma-mocha": "^1.3.0", + "karma-spec-reporter": "^0.0.32", + "karma-webpack": "^4.0.2", + "mocha": "^6.1.0", + "nyc": "^14.1.1", + "rimraf": "^3.0.0", + "sinon": "^7.5.0", + "ts-loader": "^6.0.4", + "ts-mocha": "^6.0.0", + "ts-node": "^8.6.2", + "tslint-consistent-codestyle": "^1.16.0", + "tslint-microsoft-contrib": "^6.2.0", + "typescript": "3.7.2", + "webpack": "^4.35.2" + }, + "dependencies": { + "@opentelemetry/types": "^0.3.3" + } +} diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts new file mode 100644 index 00000000000..811c6d9d410 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts @@ -0,0 +1,98 @@ +/*! + * Copyright 2020, 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. + */ + +import { SpanContext, HttpTextFormat, TraceFlags } from '@opentelemetry/types'; + +export const UBER_TRACE_ID_HEADER = 'uber-trace-id'; + +/** + * Propagates {@link SpanContext} through Trace Context format propagation. + * {trace-id}:{span-id}:{parent-span-id}:{flags} + * {trace-id} + * 64-bit or 128-bit random number in base16 format. + * Can be variable length, shorter values are 0-padded on the left. + * Value of 0 is invalid. + * {span-id} + * 64-bit random number in base16 format. + * {parent-span-id} + * Set to 0 because this field is deprecated. + * {flags} + * One byte bitmap, as two hex digits. + * Inspired by jaeger-client-node project. + */ +export class JaegerHttpTraceFormat implements HttpTextFormat { + private readonly _jaegerTraceHeader: string; + + /** + * @param {string} [customTraceHeader="uber-trace-id"] - HTTP header to inject\extract trace from. + **/ + constructor(customTraceHeader?: string) { + this._jaegerTraceHeader = customTraceHeader || UBER_TRACE_ID_HEADER; + } + + /** + * @param {SpanContext} spanContext - context from which we take information to inject in carrier. + * @param {string} format - unused. + * @param { [key: string]: unknown } carrier - a carrier to which span information will be injected. + **/ + inject( + spanContext: SpanContext, + format: string, + carrier: { [key: string]: unknown } + ) { + const traceFlags = `0${( + spanContext.traceFlags || TraceFlags.UNSAMPLED + ).toString(16)}`; + + carrier[ + this._jaegerTraceHeader + ] = `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}`; + } + + /** + * @param {string} format - unused. + * @param { [key: string]: unknown } carrier - a carrier from which span context will be constructed. + * @return {SpanContext} - returns a span context extracted from carrier. + **/ + extract( + format: string, + carrier: { [key: string]: unknown } + ): SpanContext | null { + const uberTraceIdHeader = carrier[this._jaegerTraceHeader]; + if (!uberTraceIdHeader) return null; + const uberTraceId = Array.isArray(uberTraceIdHeader) + ? uberTraceIdHeader[0] + : uberTraceIdHeader; + + return deserializeSpanContext(uberTraceId); + } +} + +/** + * @param {string} serializedString - a serialized span context. + * @return {SpanContext} - returns a span context represented by the serializedString. + **/ +function deserializeSpanContext(serializedString: string): SpanContext | null { + let headers = serializedString.split(':'); + if (headers.length !== 4) { + return null; + } + const [traceId, spanId, , flags] = headers; + + const traceFlags = flags.match(/^[0-9a-f]{2}$/i) ? parseInt(flags) & 1 : 1; + + return { traceId, spanId, isRemote: true, traceFlags }; +} diff --git a/packages/opentelemetry-propagator-jaeger/src/index.ts b/packages/opentelemetry-propagator-jaeger/src/index.ts new file mode 100644 index 00000000000..620c254f237 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/src/index.ts @@ -0,0 +1,17 @@ +/*! + * Copyright 2020, 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. + */ + +export * from './JaegerHttpTraceFormat'; diff --git a/packages/opentelemetry-propagator-jaeger/src/version.ts b/packages/opentelemetry-propagator-jaeger/src/version.ts new file mode 100644 index 00000000000..d2d10b02a61 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/src/version.ts @@ -0,0 +1,18 @@ +/*! + * 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.3'; diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts new file mode 100644 index 00000000000..a81dc92ffa8 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts @@ -0,0 +1,119 @@ +/*! + * Copyright 2020, 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. + */ + +import * as assert from 'assert'; +import { + JaegerHttpTraceFormat, + UBER_TRACE_ID_HEADER, +} from '../src/JaegerHttpTraceFormat'; +import { SpanContext, TraceFlags } from '@opentelemetry/types'; + +describe('JaegerHttpTraceFormat', () => { + const jaegerHttpTraceFormat = new JaegerHttpTraceFormat(); + const customHeader = 'new-header'; + const customJaegerHttpTraceFormat = new JaegerHttpTraceFormat(customHeader); + let carrier: { [key: string]: unknown }; + + beforeEach(() => { + carrier = {}; + }); + + describe('.inject()', () => { + it('should set uber trace id header', () => { + const spanContext: SpanContext = { + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + spanId: '6e0c63257de34c92', + traceFlags: TraceFlags.SAMPLED, + }; + + jaegerHttpTraceFormat.inject(spanContext, '', carrier); + assert.deepStrictEqual( + carrier[UBER_TRACE_ID_HEADER], + 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01' + ); + }); + + it('should use custom header if provided', () => { + const spanContext: SpanContext = { + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + spanId: '6e0c63257de34c92', + traceFlags: TraceFlags.SAMPLED, + }; + + customJaegerHttpTraceFormat.inject(spanContext, '', carrier); + assert.deepStrictEqual( + carrier[customHeader], + 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01' + ); + }); + }); + + describe('.extract()', () => { + it('should extract context of a sampled span from carrier', () => { + carrier[UBER_TRACE_ID_HEADER] = + 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01'; + const extractedSpanContext = jaegerHttpTraceFormat.extract('', carrier); + + assert.deepStrictEqual(extractedSpanContext, { + spanId: '6e0c63257de34c92', + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + isRemote: true, + traceFlags: TraceFlags.SAMPLED, + }); + }); + + it('should extract context of a sampled span from carrier with 1 bit flag', () => { + carrier[UBER_TRACE_ID_HEADER] = + '9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:1'; + const extractedSpanContext = jaegerHttpTraceFormat.extract('', carrier); + + assert.deepStrictEqual(extractedSpanContext, { + spanId: '45fd2a9709dadcf1', + traceId: '9c41e35aeb6d1272', + isRemote: true, + traceFlags: TraceFlags.SAMPLED, + }); + }); + + it('should use custom header if provided', () => { + carrier[customHeader] = + 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01'; + const extractedSpanContext = customJaegerHttpTraceFormat.extract( + '', + carrier + ); + + assert.deepStrictEqual(extractedSpanContext, { + spanId: '6e0c63257de34c92', + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + isRemote: true, + traceFlags: TraceFlags.SAMPLED, + }); + }); + + it('returns null if UBER_TRACE_ID_HEADER header is missing', () => { + assert.deepStrictEqual(jaegerHttpTraceFormat.extract('', carrier), null); + }); + + it('returns null if UBER_TRACE_ID_HEADER header is invalid', () => { + carrier[UBER_TRACE_ID_HEADER] = 'invalid!'; + assert.deepStrictEqual( + jaegerHttpTraceFormat.extract('HttpTraceContext', carrier), + null + ); + }); + }); +}); diff --git a/packages/opentelemetry-propagator-jaeger/test/index-webpack.ts b/packages/opentelemetry-propagator-jaeger/test/index-webpack.ts new file mode 100644 index 00000000000..2709346bf14 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/test/index-webpack.ts @@ -0,0 +1,23 @@ +/*! + * Copyright 2020, 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 file is the webpack entry point for the browser Karma tests. It requires +// all modules ending in "test" from the current folder and all its subfolders. +const testsContext = require.context('.', true, /test$/); +testsContext.keys().forEach(testsContext); + +const srcContext = require.context('.', true, /src$/); +srcContext.keys().forEach(srcContext); diff --git a/packages/opentelemetry-propagator-jaeger/tsconfig-release.json b/packages/opentelemetry-propagator-jaeger/tsconfig-release.json new file mode 100644 index 00000000000..ffc0f77968b --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/tsconfig-release.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": [] + }, + "include": ["src/**/*.ts"] +} diff --git a/packages/opentelemetry-propagator-jaeger/tsconfig.json b/packages/opentelemetry-propagator-jaeger/tsconfig.json new file mode 100644 index 00000000000..a2042cd68b1 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../tsconfig.base", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ] +} diff --git a/packages/opentelemetry-propagator-jaeger/tslint.json b/packages/opentelemetry-propagator-jaeger/tslint.json new file mode 100644 index 00000000000..0710b135d07 --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/tslint.json @@ -0,0 +1,4 @@ +{ + "rulesDirectory": ["node_modules/tslint-microsoft-contrib"], + "extends": ["../../tslint.base.js", "./node_modules/tslint-consistent-codestyle"] +} diff --git a/packages/opentelemetry-scope-async-hooks/package.json b/packages/opentelemetry-scope-async-hooks/package.json index 2cbaf8b53d7..0928607c9dc 100644 --- a/packages/opentelemetry-scope-async-hooks/package.json +++ b/packages/opentelemetry-scope-async-hooks/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/scope-async-hooks", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry AsyncHooks-based Scope Manager", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -56,6 +56,6 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/scope-base": "^0.3.2" + "@opentelemetry/scope-base": "^0.3.3" } } diff --git a/packages/opentelemetry-scope-async-hooks/src/version.ts b/packages/opentelemetry-scope-async-hooks/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-scope-async-hooks/src/version.ts +++ b/packages/opentelemetry-scope-async-hooks/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-scope-base/package.json b/packages/opentelemetry-scope-base/package.json index b85877885a9..c0a3f87bd6c 100644 --- a/packages/opentelemetry-scope-base/package.json +++ b/packages/opentelemetry-scope-base/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/scope-base", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Base Scope Manager", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/packages/opentelemetry-scope-base/src/version.ts b/packages/opentelemetry-scope-base/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-scope-base/src/version.ts +++ b/packages/opentelemetry-scope-base/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-scope-zone-peer-dep/package.json b/packages/opentelemetry-scope-zone-peer-dep/package.json index 5c8e3b24f98..48d3cc7b1e7 100644 --- a/packages/opentelemetry-scope-zone-peer-dep/package.json +++ b/packages/opentelemetry-scope-zone-peer-dep/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/scope-zone-peer-dep", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Scope Zone with peer dependency for zone.js", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -72,7 +72,7 @@ "zone.js": "^0.10.2" }, "dependencies": { - "@opentelemetry/scope-base": "^0.3.2" + "@opentelemetry/scope-base": "^0.3.3" }, "peerDependencies": { "zone.js": "^0.10.2" diff --git a/packages/opentelemetry-scope-zone-peer-dep/src/version.ts b/packages/opentelemetry-scope-zone-peer-dep/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-scope-zone-peer-dep/src/version.ts +++ b/packages/opentelemetry-scope-zone-peer-dep/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-scope-zone/package.json b/packages/opentelemetry-scope-zone/package.json index d8789b69670..f1cfd539563 100644 --- a/packages/opentelemetry-scope-zone/package.json +++ b/packages/opentelemetry-scope-zone/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/scope-zone", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Scope Zone", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -66,7 +66,7 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/scope-zone-peer-dep": "^0.3.2", + "@opentelemetry/scope-zone-peer-dep": "^0.3.3", "zone.js": "^0.10.2" }, "sideEffects": true diff --git a/packages/opentelemetry-scope-zone/src/version.ts b/packages/opentelemetry-scope-zone/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-scope-zone/src/version.ts +++ b/packages/opentelemetry-scope-zone/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index a36d7a53a70..c931c3c3767 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/shim-opentracing", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTracing to OpenTelemetry shim", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -39,7 +39,7 @@ "access": "public" }, "devDependencies": { - "@opentelemetry/tracing": "^0.3.2", + "@opentelemetry/tracing": "^0.3.3", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "codecov": "^3.6.1", @@ -54,8 +54,8 @@ "typescript": "3.7.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "opentracing": "^0.14.4" } } diff --git a/packages/opentelemetry-shim-opentracing/src/version.ts b/packages/opentelemetry-shim-opentracing/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-shim-opentracing/src/version.ts +++ b/packages/opentelemetry-shim-opentracing/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-test-utils/package.json b/packages/opentelemetry-test-utils/package.json index ba130f1a4b6..b79f45943e0 100644 --- a/packages/opentelemetry-test-utils/package.json +++ b/packages/opentelemetry-test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/test-utils", - "version": "0.3.2", + "version": "0.3.3", "description": "Test utilities.", "main": "build/testUtils.js", "scripts": { @@ -22,9 +22,9 @@ }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3", "gts": "^1.1.2", "ts-node": "^8.6.2", "tslint-consistent-codestyle": "^1.16.0", diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index c6c98f187e2..179ca5d330a 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/tracing", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Tracing", "main": "build/src/index.js", "browser": { @@ -73,9 +73,9 @@ "webpack": "^4.35.2" }, "dependencies": { - "@opentelemetry/base": "^0.3.2", - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/scope-base": "^0.3.2", - "@opentelemetry/types": "^0.3.2" + "@opentelemetry/base": "^0.3.3", + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/scope-base": "^0.3.3", + "@opentelemetry/types": "^0.3.3" } } diff --git a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts index b646b4a5161..64b09843045 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerRegistry.ts @@ -16,7 +16,6 @@ import { ConsoleLogger } from '@opentelemetry/core'; import * as types from '@opentelemetry/types'; -import { Logger } from '@opentelemetry/types'; import { SpanProcessor, Tracer } from '.'; import { DEFAULT_CONFIG } from './config'; import { MultiSpanProcessor } from './MultiSpanProcessor'; @@ -31,7 +30,7 @@ export class BasicTracerRegistry implements types.TracerRegistry { private readonly _tracers: Map = new Map(); activeSpanProcessor = new NoopSpanProcessor(); - readonly logger: Logger; + readonly logger: types.Logger; constructor(private _config: TracerConfig = DEFAULT_CONFIG) { this.logger = _config.logger || new ConsoleLogger(_config.logLevel); diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index 504df8b5881..00debfb8032 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -22,12 +22,6 @@ import { NoRecordingSpan, ConsoleLogger, } from '@opentelemetry/core'; -import { - BinaryFormat, - HttpTextFormat, - TraceFlags, - Logger, -} from '@opentelemetry/types'; import { TracerConfig, TraceParams } from './types'; import { ScopeManager } from '@opentelemetry/scope-base'; import { Span } from './Span'; @@ -45,7 +39,7 @@ export class Tracer implements types.Tracer { private readonly _sampler: types.Sampler; private readonly _scopeManager: ScopeManager; private readonly _traceParams: TraceParams; - readonly logger: Logger; + readonly logger: types.Logger; /** * Constructs a new Tracer instance. @@ -84,8 +78,8 @@ export class Tracer implements types.Tracer { traceState = parentContext.traceState; } const traceFlags = samplingDecision - ? TraceFlags.SAMPLED - : TraceFlags.UNSAMPLED; + ? types.TraceFlags.SAMPLED + : types.TraceFlags.UNSAMPLED; const spanContext = { traceId, spanId, traceFlags, traceState }; const recordEvents = options.isRecording || false; if (!recordEvents && !samplingDecision) { @@ -145,14 +139,14 @@ export class Tracer implements types.Tracer { /** * Returns the binary format interface which can serialize/deserialize Spans. */ - getBinaryFormat(): BinaryFormat { + getBinaryFormat(): types.BinaryFormat { return this._binaryFormat; } /** * Returns the HTTP text format interface which can inject/extract Spans. */ - getHttpTextFormat(): HttpTextFormat { + getHttpTextFormat(): types.HttpTextFormat { return this._httpTextFormat; } diff --git a/packages/opentelemetry-tracing/src/version.ts b/packages/opentelemetry-tracing/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-tracing/src/version.ts +++ b/packages/opentelemetry-tracing/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-types/package.json b/packages/opentelemetry-types/package.json index 82466c636bf..8c8ae8bd88c 100644 --- a/packages/opentelemetry-types/package.json +++ b/packages/opentelemetry-types/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/types", - "version": "0.3.2", + "version": "0.3.3", "description": "TypeScript types for OpenTelemetry", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index e73c896f2e6..e8f77714d30 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -22,6 +22,7 @@ export * from './distributed_context/DistributedContext'; export * from './distributed_context/EntryValue'; export * from './metrics/BoundInstrument'; export * from './metrics/Meter'; +export * from './metrics/MeterRegistry'; export * from './metrics/Metric'; export * from './trace/attributes'; export * from './trace/Event'; diff --git a/packages/opentelemetry-types/src/metrics/MeterRegistry.ts b/packages/opentelemetry-types/src/metrics/MeterRegistry.ts new file mode 100644 index 00000000000..75a36272da8 --- /dev/null +++ b/packages/opentelemetry-types/src/metrics/MeterRegistry.ts @@ -0,0 +1,29 @@ +/*! + * 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. + */ + +import { Meter } from './Meter'; + +/** + * MeterRegistry provides an interface for creating {@link Meter}s + */ +export interface MeterRegistry { + /** + * Returns a Meter, creating one if one with the given name and version is not already created + * + * @returns Meter A Meter with the given name and version + */ + getMeter(name: string, version?: string): Meter; +} diff --git a/packages/opentelemetry-types/src/version.ts b/packages/opentelemetry-types/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-types/src/version.ts +++ b/packages/opentelemetry-types/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3'; diff --git a/packages/opentelemetry-web/package.json b/packages/opentelemetry-web/package.json index e49f917474a..968a5e91b75 100644 --- a/packages/opentelemetry-web/package.json +++ b/packages/opentelemetry-web/package.json @@ -1,6 +1,6 @@ { "name": "@opentelemetry/web", - "version": "0.3.2", + "version": "0.3.3", "description": "OpenTelemetry Web Tracer", "main": "build/src/index.js", "types": "build/src/index.d.ts", @@ -43,7 +43,7 @@ }, "devDependencies": { "@babel/core": "^7.6.0", - "@opentelemetry/scope-zone": "^0.3.2", + "@opentelemetry/scope-zone": "^0.3.3", "@types/mocha": "^5.2.5", "@types/node": "^12.6.8", "@types/sinon": "^7.0.13", @@ -73,9 +73,9 @@ "webpack-merge": "^4.2.2" }, "dependencies": { - "@opentelemetry/core": "^0.3.2", - "@opentelemetry/scope-base": "^0.3.2", - "@opentelemetry/tracing": "^0.3.2", - "@opentelemetry/types": "^0.3.2" + "@opentelemetry/core": "^0.3.3", + "@opentelemetry/scope-base": "^0.3.3", + "@opentelemetry/tracing": "^0.3.3", + "@opentelemetry/types": "^0.3.3" } } diff --git a/packages/opentelemetry-web/src/version.ts b/packages/opentelemetry-web/src/version.ts index 2efbb00dcbe..d2d10b02a61 100644 --- a/packages/opentelemetry-web/src/version.ts +++ b/packages/opentelemetry-web/src/version.ts @@ -15,4 +15,4 @@ */ // this is autogenerated file, see scripts/version-update.js -export const VERSION = '0.3.2'; +export const VERSION = '0.3.3';