Skip to content

Commit

Permalink
Merge branch 'main' into santi/instrumentation_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored May 27, 2022
2 parents 68e1caa + 7196b7f commit eec579a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 87 deletions.
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ All notable changes to experimental packages in this project will be documented
* fix(otlp-exporter-base): include esm and esnext in package files #2952 @dyladan
* fix(otlp-http-exporter): update endpoint to match spec #2895 @svetlanabrennan
* fix(instrumentation): only patch core modules if enabled #2993 @santigimeno
* fix(otlp-transformer): include esm and esnext in package files and update README #2992 @pichlermarc
* fix(metrics): specification compliant default metric unit #2983 @andyfleming

### :books: (Refine Doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function ensureExportedCounterIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-counter',
description: 'sample counter description',
unit: '1',
unit: '',
data: 'sum',
sum: {
dataPoints: [
Expand Down Expand Up @@ -159,7 +159,7 @@ export function ensureExportedObservableGaugeIsCorrect(
assert.deepStrictEqual(metric, {
name: 'double-observable-gauge',
description: 'sample observable gauge description',
unit: '1',
unit: '',
data: 'gauge',
gauge: {
dataPoints: [
Expand Down Expand Up @@ -187,7 +187,7 @@ export function ensureExportedHistogramIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-histogram',
description: 'sample histogram description',
unit: '1',
unit: '',
data: 'histogram',
histogram: {
dataPoints: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function ensureCounterIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-counter',
description: 'sample counter description',
unit: '1',
unit: '',
sum: {
dataPoints: [
{
Expand All @@ -261,7 +261,7 @@ export function ensureDoubleCounterIsCorrect(
assert.deepStrictEqual(metric, {
name: 'double-counter',
description: 'sample counter description',
unit: '1',
unit: '',
doubleSum: {
dataPoints: [
{
Expand All @@ -287,7 +287,7 @@ export function ensureObservableGaugeIsCorrect(
assert.deepStrictEqual(metric, {
name,
description: 'sample observable gauge description',
unit: '1',
unit: '',
gauge: {
dataPoints: [
{
Expand All @@ -311,7 +311,7 @@ export function ensureObservableCounterIsCorrect(
assert.deepStrictEqual(metric, {
name,
description: 'sample observable counter description',
unit: '1',
unit: '',
doubleSum: {
isMonotonic: true,
dataPoints: [
Expand All @@ -337,7 +337,7 @@ export function ensureObservableUpDownCounterIsCorrect(
assert.deepStrictEqual(metric, {
name,
description: 'sample observable up down counter description',
unit: '1',
unit: '',
doubleSum: {
isMonotonic: false,
dataPoints: [
Expand All @@ -363,7 +363,7 @@ export function ensureHistogramIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-histogram',
description: 'sample histogram description',
unit: '1',
unit: '',
histogram: {
dataPoints: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function ensureExportedCounterIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-counter',
description: 'sample counter description',
unit: '1',
unit: '',
sum: {
dataPoints: [
{
Expand All @@ -158,7 +158,7 @@ export function ensureExportedObservableGaugeIsCorrect(
assert.deepStrictEqual(metric, {
name: 'double-observable-gauge',
description: 'sample observable gauge description',
unit: '1',
unit: '',
gauge: {
dataPoints: [
{
Expand All @@ -181,7 +181,7 @@ export function ensureExportedHistogramIsCorrect(
assert.deepStrictEqual(metric, {
name: 'int-histogram',
description: 'sample histogram description',
unit: '1',
unit: '',
histogram: {
dataPoints: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createInstrumentDescriptor(name: string, type: InstrumentType, o
name,
type,
description: options?.description ?? '',
unit: options?.unit ?? '1',
unit: options?.unit ?? '',
valueType: options?.valueType ?? ValueType.DOUBLE,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The 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 {createInstrumentDescriptor, InstrumentType} from '../src/InstrumentDescriptor';

describe('InstrumentDescriptor', () => {
describe('createInstrumentDescriptor', () => {
for (const val of [null, undefined]) {
it(`should interpret an empty unit value as a blank string (${val})`, () => {
const result = createInstrumentDescriptor('example', InstrumentType.COUNTER, {
unit: val as any,
});
assert.strictEqual(result.unit, '');
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Instruments', () => {
descriptor: {
name: 'test',
description: '',
unit: '1',
unit: '',
type: InstrumentType.COUNTER,
valueType: ValueType.INT,
},
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('Instruments', () => {
descriptor: {
name: 'test',
description: '',
unit: '1',
unit: '',
type: InstrumentType.UP_DOWN_COUNTER,
valueType: ValueType.INT,
},
Expand Down Expand Up @@ -265,7 +265,7 @@ describe('Instruments', () => {
descriptor: {
name: 'test',
description: '',
unit: '1',
unit: '',
type: InstrumentType.HISTOGRAM,
valueType: ValueType.INT,
},
Expand Down
75 changes: 4 additions & 71 deletions experimental/packages/otlp-transformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]

This package provides everything needed to serialize [OpenTelemetry SDK][sdk] traces and metrics into the [OpenTelemetry Protocol][otlp] format using [protocol buffers][protobuf] or JSON.
It also contains service clients for exporting traces and metrics to the OpenTelemetry Collector or a compatible receiver using using OTLP over [gRPC][grpc].
This module uses [`protobufjs`][protobufjs] for serialization and is compatible with [`@grpc/grpc-js`][grpc-js].
**NOTE: This package is intended for internal use only.**

This package provides everything needed to serialize [OpenTelemetry SDK][sdk] traces and metrics into the [OpenTelemetry Protocol][otlp] format.

## Quick Start

Expand All @@ -14,9 +14,7 @@ To get started you will need to install a compatible OpenTelemetry API.
### Install Peer Dependencies

```sh
npm install \
@opentelemetry/api \
@grpc/grpc-js # only required if you are using gRPC
npm install @opentelemetry/api
```

### Serialize Traces and Metrics
Expand All @@ -30,65 +28,6 @@ const serializedSpans = createExportTraceServiceRequest(readableSpans);
const serializedMetrics = createExportMetricsServiceRequest(readableMetrics);
```

### Create gRPC Service Clients

This module also contains gRPC service clients for exporting traces and metrics to an OpenTelemetry collector or compatible receiver over gRPC.
In order to avoid bundling a gRPC module with this module, it is required to construct an RPC implementation to pass to the constructor of the service clients.
Any RPC implementation compatible with `grpc` or `@grpc/grpc-js` may be used, but `@grpc/grpc-js` is recommended.

```typescript
import type { RPCImpl } from 'protobufjs';
import { makeGenericClientConstructor, credentials } from '@gprc/grpc-js';
import { MetricServiceClient, TraceServiceClient } from "@opentelemetry/otlp-transformer";

// Construct a RPC Implementation according to protobufjs docs
const GrpcClientConstructor = makeGenericClientConstructor({});

const metricGRPCClient = new GrpcClientConstructor(
"http://localhost:4317/v1/metrics", // default collector metrics endpoint
credentials.createInsecure(),
);

const traceGRPCClient = new GrpcClientConstructor(
"http://localhost:4317/v1/traces", // default collector traces endpoint
credentials.createInsecure(),
);

const metricRpc: RPCImpl = function(method, requestData, callback) {
metricGRPCClient.makeUnaryRequest(
method.name,
arg => arg,
arg => arg,
requestData,
callback
);
}

const traceRpc: RPCImpl = function(method, requestData, callback) {
traceGRPCClient.makeUnaryRequest(
method.name,
arg => arg,
arg => arg,
requestData,
callback
);
}

// Construct service clients to use RPC Implementations
const metricServiceClient = new MetricServiceClient({
rpcImpl: metricRpc,
startTime: Date.now(), // exporter start time in milliseconds
});

const traceServiceClient = new TraceServiceClient({
rpcImpl: traceRpc,
});

// Export ReadableSpan[] and ReadableMetric[] over gRPC
await metricServiceClient.export(readableMetrics);
await traceServiceClient.export(readableSpans);
```

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand All @@ -107,9 +46,3 @@ Apache 2.0 - See [LICENSE][license-url] for more information.

[sdk]: https://github.com/open-telemetry/opentelemetry-js
[otlp]: https://github.com/open-telemetry/opentelemetry-proto

[protobuf]: https://developers.google.com/protocol-buffers
[grpc]: https://grpc.io/

[protobufjs]: https://www.npmjs.com/package/protobufjs
[grpc-js]: https://www.npmjs.com/package/@grpc/grpc-js
6 changes: 6 additions & 0 deletions experimental/packages/otlp-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
"node": ">=8.12.0"
},
"files": [
"build/esm/**/*.js",
"build/esm/**/*.js.map",
"build/esm/**/*.d.ts",
"build/esnext/**/*.js",
"build/esnext/**/*.js.map",
"build/esnext/**/*.d.ts",
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
Expand Down

0 comments on commit eec579a

Please sign in to comment.