Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/http-sender' into http-sender
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodalcin committed Jun 3, 2020
2 parents 8d51800 + a528a1e commit abcfcc7
Show file tree
Hide file tree
Showing 104 changed files with 1,065 additions and 682 deletions.
41 changes: 0 additions & 41 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,6 @@ browsers_unit_tests: &browsers_unit_tests
command: if [ "$CIRCLE_NODE_VERSION" = "v12" ]; then npm run codecov:browser; fi

jobs:
lint_&_docs:
docker:
- image: node:12
environment:
NPM_CONFIG_UNSAFE_PERM: true
steps:
- checkout
- run:
name: Install minimal doc and lint modules globally
command: npm i -g eslint@^6.8.0 eslint-plugin-node @typescript-eslint/eslint-plugin@^2.23.0 @typescript-eslint/parser@^2.23.0 eslint-plugin-header@^3.0.0 eslint-plugin-import@^2.19.1 eslint-plugin-prettier prettier lerna typedoc linkinator typescript@^3.7.2
- run:
name: Install gts version 2.0.0 globally
command: npm i -g [email protected]
- run:
name: Symlink global modules into all lerna packages
command: lerna exec 'npm link eslint gts eslint-plugin-node @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-header eslint-plugin-import eslint-plugin-prettier prettier lerna typedoc linkinator typescript'
- run:
name: Check code style and linting
command: npm run lint
- run:
name: Install doc dependencies
command: lerna bootstrap --no-ci --scope @opentelemetry/api --include-filtered-dependencies -- --only dev
- run:
name: Docs tests
command: npm run docs-test
- run:
name: Install minimal modules to lint examples
command: npm i --no-save eslint eslint-plugin-import eslint-config-airbnb-base
- run:
name: Lint examples
command: npm run lint:examples
node8:
docker:
- image: node:8
Expand All @@ -161,11 +130,6 @@ jobs:
- image: node:12
environment: *node_test_env
<<: *node_unit_tests
node13:
docker:
- image: node:13
environment: *node_test_env
<<: *node_unit_tests
node14:
docker:
- image: node:14
Expand All @@ -180,14 +144,9 @@ workflows:
version: 2
build:
jobs:
- lint_&_docs:
filters:
branches:
only: /.*/
- node8
- node10
- node12
- node13
- node14
- node12-browsers

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# https://help.github.com/en/articles/about-code-owners
#

* @dyladan @mayurkale22 @rochdev @bg451 @OlivierAlbertini @vmarchaud @markwolff @obecny @mwear
* @dyladan @mayurkale22 @rochdev @bg451 @OlivierAlbertini @vmarchaud @markwolff @obecny @mwear @naseemkullah
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: restore lerna
uses: actions/cache@master # must use unreleased master to cache multiple paths
id: cache
with:
path: |
node_modules
packages/*/node_modules
metapackages/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}

- name: Bootstrap
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install --only=dev --ignore-scripts
npx lerna bootstrap --no-ci --ignore-scripts -- --only=dev
- name: Lint
run: |
npm run lint
npm run lint:examples
- name: Install and Build API Dependencies
run: npx lerna bootstrap --no-ci --scope @opentelemetry/api --include-filtered-dependencies

- name: Test Docs
run: npm run docs-test
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.

## Unreleased

## 0.8.3

#### :rocket: (Enhancement)
* `opentelemetry-node`
* [#980](https://github.com/open-telemetry/opentelemetry-js/pull/980) feat: merge user supplied and default plugin configs ([@naseemkullah](https://github.com/naseemkullah))

#### :bug: (Bug Fix)
* `opentelemetry-context-async-hooks`
* [#1099](https://github.com/open-telemetry/opentelemetry-js/pull/1099) fix(asynchooks-scope): fix context loss using .with() #1101 ([@vmarchaud](https://github.com/vmarchaud))

#### :books: (Refine Doc)
* Other
* [#1100](https://github.com/open-telemetry/opentelemetry-js/pull/1100) docs(batcher): document how to configure custom aggregators #989 ([@vmarchaud](https://github.com/vmarchaud))
* `opentelemetry-api`
* [#1106](https://github.com/open-telemetry/opentelemetry-js/pull/1106) chore: improve API documentation ([@mayurkale22](https://github.com/mayurkale22))

#### Committers: 7
- Bartlomiej Obecny ([@obecny](https://github.com/obecny))
- Daniel Dyla ([@dyladan](https://github.com/dyladan))
- Kanika Shah ([@kanikashah90](https://github.com/kanikashah90))
- Mayur Kale ([@mayurkale22](https://github.com/mayurkale22))
- Naseem ([@naseemkullah](https://github.com/naseemkullah))
- Valentin Marchaud ([@vmarchaud](https://github.com/vmarchaud))
- [@shivkanya9146](https://github.com/shivkanya9146)


## 0.8.2

#### :rocket: (Enhancement)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ If you are a library author looking to build OpenTelemetry into your library, pl
| Platform Version | Supported |
|------------------|-------------------------------------------------|
| Node.JS `v14` ||
| Node.JS `v13` ||
| Node.JS `v12` ||
| Node.JS `v10` ||
| Node.JS `v8` | See [Node Support](#node-support) below |
Expand Down Expand Up @@ -134,6 +133,7 @@ Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry
- [Mark Wolff](https://github.com/markwolff), Microsoft
- [Bartlomiej Obecny](https://github.com/obecny), LightStep
- [Matthew Wear](https://github.com/mwear), LightStep
- [Naseem K. Ullah](https://github.com/naseemkullah), Transit

*Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#approver).*

Expand Down Expand Up @@ -261,4 +261,3 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[otel-contrib-plugin-express]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/node/opentelemetry-plugin-express
[otel-contrib-plugin-user-interaction]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/web/opentelemetry-plugin-user-interaction
[otel-contrib-plugin-document-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/web/opentelemetry-plugin-document-load

143 changes: 143 additions & 0 deletions doc/batcher-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Batcher API Guide

[The batcher](https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-metrics/src/export/Batcher.ts?rgh-link-date=2020-05-25T18%3A43%3A57Z) has two responsibilities: choosing which aggregator to choose for a metric instrument and store the last record for each metric ready to be exported.

## Selecting a specific aggregator for metrics

Sometimes you may want to use a specific aggregator for one of your metric, export an average of the last X values instead of just the last one.

Here is what an aggregator that does that would look like:
```ts
import { Aggregator } from '@opentelemetry/metrics';
import { hrTime } from '@opentelemetry/core';

export class AverageAggregator implements Aggregator {

private _values: number[] = [];
private _limit: number;

constructor (limit?: number) {
this._limit = limit ?? 10;
}

update (value: number) {
this._values.push(value);
if (this._values.length >= this._limit) {
this._values = this._values.slice(0, 10);
}
}

toPoint() {
const sum =this._values.reduce((agg, value) => {
agg += value;
return agg;
}, 0);
return {
value: this._values.length > 0 ? sum / this._values.length : 0,
timestamp: hrTime(),
}
}
}
```

Now we will need to implement our own batcher to configure the sdk to use our new aggregator. To simplify even more, we will just extend the `UngroupedBatcher` (which is the default) to avoid re-implementing the whole `Aggregator` interface.

Here the result:
```ts
import {
UngroupedBatcher,
MetricDescriptor,
CounterSumAggregator,
ObserverAggregator,
MeasureExactAggregator,
} from '@opentelemetry/metrics';

export class CustomBatcher extends UngroupedBatcher {
aggregatorFor (metricDescriptor: MetricDescriptor) {
if (metricDescriptor.labels === 'metricToBeAveraged') {
return new AverageAggregator(10);
}
// this is exactly what the "UngroupedBatcher" does, we will re-use it
// to fallback on the default behavior
switch (metricDescriptor.metricKind) {
case MetricKind.COUNTER:
return new CounterSumAggregator();
case MetricKind.OBSERVER:
return new ObserverAggregator();
default:
return new MeasureExactAggregator();
}
}
}
```

Finally, we need to specify to the `MeterProvider` to use our `CustomBatcher` when creating new meter:

```ts
import {
UngroupedBatcher,
MetricDescriptor,
CounterSumAggregator,
ObserverAggregator,
MeasureExactAggregator,
MeterProvider,
Aggregator,
} from '@opentelemetry/metrics';
import { hrTime } from '@opentelemetry/core';

export class AverageAggregator implements Aggregator {

private _values: number[] = [];
private _limit: number;

constructor (limit?: number) {
this._limit = limit ?? 10;
}

update (value: number) {
this._values.push(value);
if (this._values.length >= this._limit) {
this._values = this._values.slice(0, 10);
}
}

toPoint() {
const sum =this._values.reduce((agg, value) => {
agg += value;
return agg;
}, 0);
return {
value: this._values.length > 0 ? sum / this._values.length : 0,
timestamp: hrTime(),
}
}
}

export class CustomBatcher extends UngroupedBatcher {
aggregatorFor (metricDescriptor: MetricDescriptor) {
if (metricDescriptor.name === 'requests') {
return new AverageAggregator(10);
}
// this is exactly what the "UngroupedBatcher" does, we will re-use it
// to fallback on the default behavior
switch (metricDescriptor.metricKind) {
case MetricKind.COUNTER:
return new CounterSumAggregator();
case MetricKind.OBSERVER:
return new ObserverAggregator();
default:
return new MeasureExactAggregator();
}
}
}

const meter = new MeterProvider({
batcher: new CustomBatcher(),
interval: 1000,
}).getMeter('example-custom-batcher');

const requestsLatency = meter.createMeasure('requests', {
monotonic: true,
description: 'Average latency'
});
```
8 changes: 4 additions & 4 deletions examples/basic-tracer-node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example-basic-tracer-node",
"private": true,
"version": "0.8.2",
"version": "0.8.3",
"description": "Example of using @opentelemetry/tracing in Node.js",
"main": "index.js",
"scripts": {
Expand All @@ -24,9 +24,9 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.8.2",
"@opentelemetry/exporter-jaeger": "^0.8.2",
"@opentelemetry/tracing": "^0.8.2"
"@opentelemetry/api": "^0.8.3",
"@opentelemetry/exporter-jaeger": "^0.8.3",
"@opentelemetry/tracing": "^0.8.3"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme"
}
8 changes: 4 additions & 4 deletions examples/collector-exporter-node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example-collector-exporter-node",
"private": true,
"version": "0.8.2",
"version": "0.8.3",
"description": "Example of using @opentelemetry/collector-exporter in Node.js",
"main": "index.js",
"scripts": {
Expand All @@ -26,9 +26,9 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.8.2",
"@opentelemetry/exporter-collector": "^0.8.2",
"@opentelemetry/tracing": "^0.8.2"
"@opentelemetry/api": "^0.8.3",
"@opentelemetry/exporter-collector": "^0.8.3",
"@opentelemetry/tracing": "^0.8.3"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme"
}
14 changes: 7 additions & 7 deletions examples/grpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grpc-example",
"private": true,
"version": "0.8.2",
"version": "0.8.3",
"description": "Example of gRPC integration with OpenTelemetry",
"main": "index.js",
"scripts": {
Expand All @@ -28,12 +28,12 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"@opentelemetry/api": "^0.8.2",
"@opentelemetry/exporter-jaeger": "^0.8.2",
"@opentelemetry/exporter-zipkin": "^0.8.2",
"@opentelemetry/node": "^0.8.2",
"@opentelemetry/plugin-grpc": "^0.8.2",
"@opentelemetry/tracing": "^0.8.2",
"@opentelemetry/api": "^0.8.3",
"@opentelemetry/exporter-jaeger": "^0.8.3",
"@opentelemetry/exporter-zipkin": "^0.8.3",
"@opentelemetry/node": "^0.8.3",
"@opentelemetry/plugin-grpc": "^0.8.3",
"@opentelemetry/tracing": "^0.8.3",
"google-protobuf": "^3.9.2",
"grpc": "^1.23.3",
"node-pre-gyp": "0.12.0"
Expand Down
Loading

0 comments on commit abcfcc7

Please sign in to comment.