Skip to content

Commit

Permalink
feat!: Split metric and trace exporters into new experimental packages (
Browse files Browse the repository at this point in the history
#2485)

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
Co-authored-by: Rauno Viskus <Rauno56@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 2, 2021
1 parent 4e311bd commit c307949
Show file tree
Hide file tree
Showing 157 changed files with 2,911 additions and 889 deletions.
14 changes: 10 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[submodule "experimental/packages/opentelemetry-exporter-otlp-proto/protos"]
path = experimental/packages/opentelemetry-exporter-otlp-proto/protos
[submodule "experimental/packages/opentelemetry-exporter-trace-otlp-proto/protos"]
path = experimental/packages/opentelemetry-exporter-trace-otlp-proto/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/opentelemetry-exporter-otlp-grpc/protos"]
path = experimental/packages/opentelemetry-exporter-otlp-grpc/protos
[submodule "experimental/packages/opentelemetry-exporter-trace-otlp-grpc/protos"]
path = experimental/packages/opentelemetry-exporter-trace-otlp-grpc/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/protos"]
path = experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/opentelemetry-exporter-metrics-otlp-proto/protos"]
path = experimental/packages/opentelemetry-exporter-metrics-otlp-proto/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ To request automatic tracing support for a module not on this list, please [file

### 0.26.x to 0.27.x

Metric and trace exporters are split into separate packages:

- `@opentelemetry/exporter-otlp-http` => `@opentelemetry/exporter-trace-otlp-http` and `@opentelemetry/exporter-metrics-otlp-http`
- `@opentelemetry/exporter-otlp-grpc` => `@opentelemetry/exporter-trace-otlp-grpc` and `@opentelemetry/exporter-metrics-otlp-grpc`
- `@opentelemetry/exporter-otlp-proto` => `@opentelemetry/exporter-trace-otlp-proto` and `@opentelemetry/exporter-metrics-otlp-proto`

Metric types are renamed:

- `@openetelemetry/api-metrics`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# OpenTelemetry Collector Metrics Exporter for node with grpc

[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]

This module provides exporter for web and node to be used with [opentelemetry-collector][opentelemetry-collector-url] - last tested with version **0.25.0**.

## Installation

```bash
npm install --save @opentelemetry/exporter-metrics-otlp-grpc
```

## Service Name

The OpenTelemetry Collector Exporter does not have a service name configuration.
In order to set the service name, use the `service.name` resource attribute as prescribed in the [OpenTelemetry Resource Semantic Conventions][semconv-resource-service-name].
To see sample code and documentation for the traces exporter, as well as instructions for using TLS, visit the [Collector Trace Exporter for web and node][trace-exporter-url].

## Metrics in Node - GRPC

The OTLPTraceExporter in Node expects the URL to only be the hostname. It will not work with `/v1/metrics`. All options that work with trace also work with metrics.

```js
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const collectorOptions = {
// url is optional and can be omitted - default is grpc://localhost:4317
url: 'grpc://<collector-hostname>:<port>',
};
const exporter = new OTLPMetricExporter(collectorOptions);

// Register the exporter
const provider = new MeterProvider({
exporter,
interval: 60000,
})
['SIGINT', 'SIGTERM'].forEach(signal => {
process.on(signal, () => provider.shutdown().catch(console.error));
});

// Now, start recording data
const meter = provider.getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });
```

## Running opentelemetry-collector locally to see the metrics

1. Go to examples/otlp-exporter-node
2. run `npm run docker:start`
3. Open page at `http://localhost:9411/zipkin/` to observe the metrics

## Useful links

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

## License

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

[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=experimental%2Fpackages%2Fopentelemetry-exporter-metrics-otlp-grpc
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=experimental%2Fpackages%2Fopentelemetry-exporter-metrics-otlp-grpc
[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=experimental%2Fpackages%2Fopentelemetry-exporter-metrics-otlp-grpc&type=dev
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=experimental%2Fpackages%2Fopentelemetry-exporter-metrics-otlp-grpc&type=dev
[npm-url]: https://www.npmjs.com/package/@opentelemetry/exporter-metrics-otlp-grpc
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fexporter-metrics-otlp-grpc.svg
[opentelemetry-collector-url]: https://github.com/open-telemetry/opentelemetry-collector
[semconv-resource-service-name]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service
[trace-exporter-url]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-exporter-trace-otlp-grpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "@opentelemetry/exporter-metrics-otlp-grpc",
"version": "0.26.0",
"description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"compile": "tsc --build",
"clean": "tsc --build --clean",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"postcompile": "npm run submodule && npm run protos:copy",
"protos:copy": "cpx protos/opentelemetry/**/*.* build/protos/opentelemetry",
"submodule": "git submodule sync --recursive && git submodule update --init --recursive",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"version": "node ../../../scripts/version-update.js",
"watch": "npm run protos:copy && tsc -w",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"prewatch": "npm run precompile"
},
"keywords": [
"opentelemetry",
"nodejs",
"grpc",
"tracing",
"profiling",
"metrics",
"stats"
],
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"engines": {
"node": ">=8.0.0"
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"build/protos/**/*.proto",
"doc",
"LICENSE",
"README.md"
],
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@babel/core": "7.15.0",
"@opentelemetry/api": "^1.0.3",
"@opentelemetry/api-metrics": "0.26.0",
"@types/mocha": "8.2.3",
"@types/node": "14.17.11",
"@types/sinon": "10.0.2",
"codecov": "3.8.3",
"cpx": "1.5.0",
"mocha": "7.2.0",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "11.1.2",
"ts-loader": "8.3.0",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.3"
},
"dependencies": {
"@grpc/grpc-js": "^1.3.7",
"@grpc/proto-loader": "^0.6.4",
"@opentelemetry/core": "1.0.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.26.0",
"@opentelemetry/exporter-trace-otlp-http": "0.26.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.26.0",
"@opentelemetry/sdk-metrics-base": "0.26.0",
"@opentelemetry/resources": "1.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/

import {
otlpTypes,
toOTLPExportMetricServiceRequest,
} from '@opentelemetry/exporter-otlp-http';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'
import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base';
import { OTLPExporterConfigNode, ServiceClientType } from './types';
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
import {
OTLPExporterConfigNode,
OTLPExporterNodeBase,
ServiceClientType,
validateAndNormalizeUrl
} from '@opentelemetry/exporter-trace-otlp-grpc';
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { validateAndNormalizeUrl } from './util';
import { Metadata } from '@grpc/grpc-js';

const DEFAULT_COLLECTOR_URL = 'localhost:4317';
Expand Down Expand Up @@ -58,7 +59,7 @@ export class OTLPMetricExporter
);
}

getDefaultUrl(config: OTLPExporterConfigNode) {
getDefaultUrl(config: OTLPExporterConfigNode): string {
return typeof config.url === 'string'
? validateAndNormalizeUrl(config.url)
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
Expand All @@ -68,7 +69,7 @@ export class OTLPMetricExporter
: DEFAULT_COLLECTOR_URL;
}

getServiceClientType() {
getServiceClientType(): ServiceClientType {
return ServiceClientType.METRICS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
* limitations under the License.
*/

export * from './OTLPTraceExporter';
export * from './OTLPMetricExporter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Important

**Submodule is always pointing to certain revision number. So updating the submodule repo will not have impact on your code.
Knowing this if you want to change the submodule to point to a different version (when for example proto has changed) here is how to do it:**

## Updating submodule to point to certain revision number

1. Make sure you are in the same folder as this instruction

2. Update your submodules by running this command

```shell script
git submodule sync --recursive
git submodule update --init --recursive
```

3. Find the commit SHA which you want to update to and copy it (the long one)

4. Enter a submodule directory from this directory

```shell script
cd protos
```

5. Updates files in the submodule tree to given commit:

```shell script
git checkout -q <sha>
```

6. Return to the main directory:

```shell script
cd ../
```

7. Please run `git status` you should see something like `Head detached at`. This is correct, go to next step

8. Now thing which is very important. You have to commit this to apply these changes

```shell script
git commit -am "chore: updating submodule for opentelemetry-proto"
```

9. If you look now at git log you will notice that the folder `protos` has been changed and it will show what was the previous sha and what is current one.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
Histogram,
} from '@opentelemetry/api-metrics';
import { diag } from '@opentelemetry/api';
import { otlpTypes } from '@opentelemetry/exporter-otlp-http';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import * as metrics from '@opentelemetry/sdk-metrics-base';
import * as assert from 'assert';
import * as fs from 'fs';
Expand All @@ -38,7 +38,7 @@ import {
mockCounter,
mockObservableGauge,
mockHistogram,
} from './helper';
} from './metricsHelper';

const metricsServiceProtoPath =
'opentelemetry/proto/collector/metrics/v1/metrics_service.proto';
Expand Down
Loading

0 comments on commit c307949

Please sign in to comment.