From e213ecfaccf65f856f565480b3e49705085a003e Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Wed, 11 May 2022 15:13:36 +0200 Subject: [PATCH 1/8] feat(otlp-transformer): extract otlp-transformer-metrics. --- .../otlp-transformer-metrics/.eslintignore | 2 + .../otlp-transformer-metrics/.eslintrc.js | 8 + .../otlp-transformer-metrics/.gitignore | 1 + .../otlp-transformer-metrics/README.md | 115 +++++ .../otlp-transformer-metrics/karma.conf.js | 24 ++ .../otlp-transformer-metrics/package.json | 78 ++++ .../otlp-transformer-metrics/src/index.ts | 19 + .../src/metrics/index.ts | 24 ++ .../src/metrics/internal.ts | 169 ++++++++ .../src/metrics/types.ts | 352 ++++++++++++++++ .../test/index-webpack.ts | 20 + .../test/metrics.test.ts | 393 ++++++++++++++++++ .../tsconfig.all.json | 9 + .../tsconfig.esm.json | 11 + .../tsconfig.esnext.json | 11 + .../otlp-transformer-metrics/tsconfig.json | 25 ++ 16 files changed, 1261 insertions(+) create mode 100644 experimental/packages/otlp-transformer-metrics/.eslintignore create mode 100644 experimental/packages/otlp-transformer-metrics/.eslintrc.js create mode 100644 experimental/packages/otlp-transformer-metrics/.gitignore create mode 100644 experimental/packages/otlp-transformer-metrics/README.md create mode 100644 experimental/packages/otlp-transformer-metrics/karma.conf.js create mode 100644 experimental/packages/otlp-transformer-metrics/package.json create mode 100644 experimental/packages/otlp-transformer-metrics/src/index.ts create mode 100644 experimental/packages/otlp-transformer-metrics/src/metrics/index.ts create mode 100644 experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts create mode 100644 experimental/packages/otlp-transformer-metrics/src/metrics/types.ts create mode 100644 experimental/packages/otlp-transformer-metrics/test/index-webpack.ts create mode 100644 experimental/packages/otlp-transformer-metrics/test/metrics.test.ts create mode 100644 experimental/packages/otlp-transformer-metrics/tsconfig.all.json create mode 100644 experimental/packages/otlp-transformer-metrics/tsconfig.esm.json create mode 100644 experimental/packages/otlp-transformer-metrics/tsconfig.esnext.json create mode 100644 experimental/packages/otlp-transformer-metrics/tsconfig.json diff --git a/experimental/packages/otlp-transformer-metrics/.eslintignore b/experimental/packages/otlp-transformer-metrics/.eslintignore new file mode 100644 index 00000000000..345f1a599ed --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/.eslintignore @@ -0,0 +1,2 @@ +build +src/generated diff --git a/experimental/packages/otlp-transformer-metrics/.eslintrc.js b/experimental/packages/otlp-transformer-metrics/.eslintrc.js new file mode 100644 index 00000000000..b9004d20258 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + "env": { + "mocha": true, + "commonjs": true, + "shared-node-browser": true + }, + ...require('../../../eslint.config.js') +} diff --git a/experimental/packages/otlp-transformer-metrics/.gitignore b/experimental/packages/otlp-transformer-metrics/.gitignore new file mode 100644 index 00000000000..c83f90a2b01 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/.gitignore @@ -0,0 +1 @@ +src/generated diff --git a/experimental/packages/otlp-transformer-metrics/README.md b/experimental/packages/otlp-transformer-metrics/README.md new file mode 100644 index 00000000000..2c53ce82cac --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/README.md @@ -0,0 +1,115 @@ +# OpenTelemetry Protocol + +[![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]. + +## Quick Start + +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 +``` + +### Serialize Traces and Metrics + +This module exports functions to serialize traces and metrics from the OpenTelemetry SDK into protocol buffers which can be sent over HTTP to the OpenTelemetry collector or a compatible receiver. + +```typescript +import { createExportTraceServiceRequest, createExportMetricsServiceRequest } from "@opentelemetry/otlp-transformer"; + +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: +- For more about OpenTelemetry JavaScript: +- 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 +[npm-url]: https://www.npmjs.com/package/@opentelemetry/otlp-transformer +[npm-img]: https://badge.fury.io/js/%40opentelemetry%otlp-transformer.svg + +[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 diff --git a/experimental/packages/otlp-transformer-metrics/karma.conf.js b/experimental/packages/otlp-transformer-metrics/karma.conf.js new file mode 100644 index 00000000000..6174839d651 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/karma.conf.js @@ -0,0 +1,24 @@ +/*! + * 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 + * + * 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/experimental/packages/otlp-transformer-metrics/package.json b/experimental/packages/otlp-transformer-metrics/package.json new file mode 100644 index 00000000000..353cb4119ec --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/package.json @@ -0,0 +1,78 @@ +{ + "name": "@opentelemetry/otlp-transformer-metrics", + "private": false, + "publishConfig": { + "access": "public" + }, + "version": "0.28.0", + "description": "Transform OpenTelemetry Metrics SDK data into OTLP", + "module": "build/esm/index.js", + "esnext": "build/esnext/index.js", + "types": "build/src/index.d.ts", + "main": "build/src/index.js", + "repository": "open-telemetry/opentelemetry-js", + "scripts": { + "compile": "tsc --build tsconfig.all.json", + "clean": "tsc --build --clean tsconfig.all.json", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "tdd": "npm run test -- --watch-extensions ts --watch", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "test:browser": "nyc karma start --single-run", + "watch": "tsc --build -w tsconfig.all.json", + "peer-api-check": "node ../../../scripts/peer-api-check.js", + "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../" + }, + "keywords": [ + "opentelemetry", + "nodejs", + "grpc", + "protobuf", + "otlp", + "tracing", + "metrics" + ], + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=8.12.0" + }, + "files": [ + "build/src/**/*.js", + "build/src/**/*.js.map", + "build/src/**/*.d.ts", + "LICENSE", + "README.md" + ], + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.2.0" + }, + "devDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.2.0", + "@types/mocha": "8.2.3", + "@types/webpack-env": "1.16.3", + "codecov": "3.8.3", + "istanbul-instrumenter-loader": "3.0.1", + "karma": "6.3.16", + "karma-chrome-launcher": "3.1.0", + "karma-coverage-istanbul-reporter": "3.0.3", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.32", + "karma-webpack": "4.0.2", + "mkdirp": "1.0.4", + "mocha": "7.2.0", + "nyc": "15.1.0", + "protobufjs": "6.11.2", + "rimraf": "3.0.2", + "ts-loader": "8.3.0", + "ts-mocha": "9.0.2", + "typescript": "4.4.4", + "webpack": "4.46.0" + }, + "dependencies": { + "@opentelemetry/api-metrics": "0.28.0", + "@opentelemetry/core": "1.2.0", + "@opentelemetry/sdk-metrics-base": "0.28.0", + "@opentelemetry/otlp-transformer": "0.28.0" + } +} diff --git a/experimental/packages/otlp-transformer-metrics/src/index.ts b/experimental/packages/otlp-transformer-metrics/src/index.ts new file mode 100644 index 00000000000..4b5f599bbed --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/src/index.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +export * from './metrics/types'; + +export { createExportMetricsServiceRequest } from './metrics'; diff --git a/experimental/packages/otlp-transformer-metrics/src/metrics/index.ts b/experimental/packages/otlp-transformer-metrics/src/metrics/index.ts new file mode 100644 index 00000000000..28337c3cd41 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/src/metrics/index.ts @@ -0,0 +1,24 @@ +/* + * 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 type { ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; +import type { IExportMetricsServiceRequest } from './types'; +import { toResourceMetrics } from './internal'; + +export function createExportMetricsServiceRequest(resourceMetrics: ResourceMetrics[]): IExportMetricsServiceRequest { + return { + resourceMetrics: resourceMetrics.map(metrics => toResourceMetrics(metrics)) + }; +} diff --git a/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts b/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts new file mode 100644 index 00000000000..e03ade73915 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts @@ -0,0 +1,169 @@ +/* + * 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 { ValueType } from '@opentelemetry/api-metrics'; +import { hrTimeToNanoseconds } from '@opentelemetry/core'; +import { + AggregationTemporality, + DataPoint, + DataPointType, + Histogram, + ScopeMetrics, + InstrumentType, + MetricData, + ResourceMetrics +} from '@opentelemetry/sdk-metrics-base'; +import { + EAggregationTemporality, + IHistogramDataPoint, + IMetric, + INumberDataPoint, + IResourceMetrics, + IScopeMetrics +} from './types'; +import { toAttributes } from '@opentelemetry/otlp-transformer'; + +export function toResourceMetrics(resourceMetrics: ResourceMetrics): IResourceMetrics { + return { + resource: { + attributes: toAttributes(resourceMetrics.resource.attributes), + droppedAttributesCount: 0 + }, + schemaUrl: undefined, // TODO: Schema Url does not exist yet in the SDK. + scopeMetrics: toScopeMetrics(resourceMetrics.scopeMetrics) + }; +} + +export function toScopeMetrics(scopeMetrics: ScopeMetrics[]): IScopeMetrics[]{ + return Array.from(scopeMetrics.map(metrics => { + const scopeMetrics : IScopeMetrics = { + scope: { + name: metrics.scope.name, + version: metrics.scope.version, + }, + metrics: metrics.metrics.map(metricData => toMetric(metricData)), + schemaUrl: metrics.scope.schemaUrl + }; + return scopeMetrics; + })); +} + +export function toMetric(metricData: MetricData): IMetric { + const out: IMetric = { + name: metricData.descriptor.name, + description: metricData.descriptor.description, + unit: metricData.descriptor.unit, + }; + + const aggregationTemporality = toAggregationTemporality(metricData.aggregationTemporality); + + if (metricData.dataPointType === DataPointType.SINGULAR) { + const dataPoints = toSingularDataPoints(metricData); + const isMonotonic = metricData.descriptor.type === InstrumentType.COUNTER || + metricData.descriptor.type === InstrumentType.OBSERVABLE_COUNTER; + if (isSum(metricData)) { + out.sum = { + aggregationTemporality, + isMonotonic, + dataPoints + }; + + } else { + // Instrument is a gauge. + out.gauge = { + dataPoints + }; + } + } else if (isHistogram(metricData)) { + out.histogram = { + aggregationTemporality, + dataPoints: toHistogramDataPoints(metricData) + }; + } + + return out; +} + +function toSingularDataPoint(dataPoint: DataPoint | DataPoint, valueType: ValueType) { + const out: INumberDataPoint = { + attributes: toAttributes(dataPoint.attributes), + startTimeUnixNano: hrTimeToNanoseconds( + dataPoint.startTime + ), + timeUnixNano: hrTimeToNanoseconds( + dataPoint.endTime + ), + }; + + if (valueType === ValueType.INT) { + out.asInt = dataPoint.value as number; + } else if (valueType === ValueType.DOUBLE) { + out.asDouble = dataPoint.value as number; + } + + return out; +} + +function toSingularDataPoints( + metricData: MetricData +): INumberDataPoint[] { + return metricData.dataPoints.map(dataPoint => { + return toSingularDataPoint(dataPoint, metricData.descriptor.valueType); + }); +} + +function toHistogramDataPoints( + metricData: MetricData +): IHistogramDataPoint[] { + return metricData.dataPoints.map(dataPoint => { + const histogram = dataPoint.value as Histogram; + return { + attributes: toAttributes(dataPoint.attributes), + bucketCounts: histogram.buckets.counts, + explicitBounds: histogram.buckets.boundaries, + count: histogram.count, + sum: histogram.sum, + startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime), + timeUnixNano: hrTimeToNanoseconds( + dataPoint.endTime + ), + }; + }); +} + +function isSum(metric: MetricData) { + return (metric.descriptor.type === InstrumentType.COUNTER || + metric.descriptor.type === InstrumentType.UP_DOWN_COUNTER || + metric.descriptor.type === InstrumentType.OBSERVABLE_COUNTER || + metric.descriptor.type === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER); +} + +function isHistogram(metric: MetricData) { + return metric.dataPointType === DataPointType.HISTOGRAM; +} + +function toAggregationTemporality( + temporality: AggregationTemporality, +): EAggregationTemporality { + if (temporality === AggregationTemporality.DELTA) { + return EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA; + } + + if (temporality === AggregationTemporality.CUMULATIVE) { + return EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE; + } + + return EAggregationTemporality.AGGREGATION_TEMPORALITY_UNSPECIFIED; +} diff --git a/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts b/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts new file mode 100644 index 00000000000..3aff9c7dc79 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts @@ -0,0 +1,352 @@ +/* + * 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 { IResource, IInstrumentationScope } from '@opentelemetry/otlp-transformer'; +import { IKeyValue } from '@opentelemetry/otlp-transformer'; + +/** Properties of an ExportMetricsServiceRequest. */ +export interface IExportMetricsServiceRequest { + + /** ExportMetricsServiceRequest resourceMetrics */ + resourceMetrics: IResourceMetrics[] +} + +/** Properties of a ResourceMetrics. */ +export interface IResourceMetrics { + + /** ResourceMetrics resource */ + resource?: IResource; + + /** ResourceMetrics scopeMetrics */ + scopeMetrics: IScopeMetrics[] + + /** ResourceMetrics schemaUrl */ + schemaUrl?: string; +} + +/** Properties of an IScopeMetrics. */ +export interface IScopeMetrics { + + /** ScopeMetrics scope */ + scope?: IInstrumentationScope; + + /** ScopeMetrics metrics */ + metrics: IMetric[]; + + /** ScopeMetrics schemaUrl */ + schemaUrl?: string; +} + +/** Properties of a Metric. */ +export interface IMetric { + + /** Metric name */ + name: string; + + /** Metric description */ + description?: string; + + /** Metric unit */ + unit?: string; + + /** Metric gauge */ + gauge?: IGauge; + + /** Metric sum */ + sum?: ISum; + + /** Metric histogram */ + histogram?: IHistogram; + + /** Metric exponentialHistogram */ + exponentialHistogram?: IExponentialHistogram; + + /** Metric summary */ + summary?: ISummary; +} + +/** Properties of a Gauge. */ +export interface IGauge { + /** Gauge dataPoints */ + dataPoints: INumberDataPoint[] +} + +/** Properties of a Sum. */ +export interface ISum { + + /** Sum dataPoints */ + dataPoints: INumberDataPoint[]; + + /** Sum aggregationTemporality */ + aggregationTemporality: EAggregationTemporality + + /** Sum isMonotonic */ + isMonotonic?: (boolean | null); +} + +/** Properties of a Histogram. */ +export interface IHistogram { + /** Histogram dataPoints */ + dataPoints: IHistogramDataPoint[] + + /** Histogram aggregationTemporality */ + aggregationTemporality?: EAggregationTemporality +} + +/** Properties of an ExponentialHistogram. */ +export interface IExponentialHistogram { + /** ExponentialHistogram dataPoints */ + dataPoints: IExponentialHistogramDataPoint[]; + + /** ExponentialHistogram aggregationTemporality */ + aggregationTemporality?: EAggregationTemporality; +} + +/** Properties of a Summary. */ +export interface ISummary { + /** Summary dataPoints */ + dataPoints: ISummaryDataPoint[]; +} + +/** Properties of a NumberDataPoint. */ +export interface INumberDataPoint { + + /** NumberDataPoint attributes */ + attributes: IKeyValue[] + + /** NumberDataPoint startTimeUnixNano */ + startTimeUnixNano?: number; + + /** NumberDataPoint timeUnixNano */ + timeUnixNano?: number; + + /** NumberDataPoint asDouble */ + asDouble?: (number | null); + + /** NumberDataPoint asInt */ + asInt?: number; + + /** NumberDataPoint exemplars */ + exemplars?: IExemplar[]; + + /** NumberDataPoint flags */ + flags?: number; +} + + +/** Properties of a HistogramDataPoint. */ +export interface IHistogramDataPoint { + /** HistogramDataPoint attributes */ + attributes?: IKeyValue[]; + + /** HistogramDataPoint startTimeUnixNano */ + startTimeUnixNano?: number; + + /** HistogramDataPoint timeUnixNano */ + timeUnixNano?: number; + + /** HistogramDataPoint count */ + count?: number; + + /** HistogramDataPoint sum */ + sum?: number; + + /** HistogramDataPoint bucketCounts */ + bucketCounts?: number[] + + /** HistogramDataPoint explicitBounds */ + explicitBounds?: number[] + + /** HistogramDataPoint exemplars */ + exemplars?: IExemplar[]; + + /** HistogramDataPoint flags */ + flags?: number; +} + +/** Properties of an ExponentialHistogramDataPoint. */ +export interface IExponentialHistogramDataPoint { + + /** ExponentialHistogramDataPoint attributes */ + attributes?: IKeyValue[]; + + /** ExponentialHistogramDataPoint startTimeUnixNano */ + startTimeUnixNano?: number; + + /** ExponentialHistogramDataPoint timeUnixNano */ + timeUnixNano?: string; + + /** ExponentialHistogramDataPoint count */ + count?: number; + + /** ExponentialHistogramDataPoint sum */ + sum?: number; + + /** ExponentialHistogramDataPoint scale */ + scale?: number; + + /** ExponentialHistogramDataPoint zeroCount */ + zeroCount?: number; + + /** ExponentialHistogramDataPoint positive */ + positive?: IBuckets; + + /** ExponentialHistogramDataPoint negative */ + negative?: IBuckets; + + /** ExponentialHistogramDataPoint flags */ + flags?: number; + + /** ExponentialHistogramDataPoint exemplars */ + exemplars?: IExemplar[] +} + + +/** Properties of a SummaryDataPoint. */ +export interface ISummaryDataPoint { + /** SummaryDataPoint attributes */ + attributes?: IKeyValue[]; + + /** SummaryDataPoint startTimeUnixNano */ + startTimeUnixNano?: number; + + /** SummaryDataPoint timeUnixNano */ + timeUnixNano?: string; + + /** SummaryDataPoint count */ + count?: number; + + /** SummaryDataPoint sum */ + sum?: number; + + /** SummaryDataPoint quantileValues */ + quantileValues?: IValueAtQuantile[]; + + /** SummaryDataPoint flags */ + flags?: number; +} + +/** Properties of a ValueAtQuantile. */ +export interface IValueAtQuantile { + /** ValueAtQuantile quantile */ + quantile?: number; + + /** ValueAtQuantile value */ + value?: number; +} + +/** Properties of a Buckets. */ +export interface IBuckets { + /** Buckets offset */ + offset?: number; + + /** Buckets bucketCounts */ + bucketCounts?: number[]; +} + +/** Properties of an Exemplar. */ +export interface IExemplar { + /** Exemplar filteredAttributes */ + filteredAttributes?: IKeyValue[]; + + /** Exemplar timeUnixNano */ + timeUnixNano?: string; + + /** Exemplar asDouble */ + asDouble?: number; + + /** Exemplar asInt */ + asInt?: number; + + /** Exemplar spanId */ + spanId?: string; + + /** Exemplar traceId */ + traceId?: string; +} + +/** + * AggregationTemporality defines how a metric aggregator reports aggregated + * values. It describes how those values relate to the time interval over + * which they are aggregated. + */ +export const enum EAggregationTemporality { + /* UNSPECIFIED is the default AggregationTemporality, it MUST not be used. */ + AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, + + /** DELTA is an AggregationTemporality for a metric aggregator which reports + changes since last report time. Successive metrics contain aggregation of + values from continuous and non-overlapping intervals. + + The values for a DELTA metric are based only on the time interval + associated with one measurement cycle. There is no dependency on + previous measurements like is the case for CUMULATIVE metrics. + + For example, consider a system measuring the number of requests that + it receives and reports the sum of these requests every second as a + DELTA metric: + + 1. The system starts receiving at time=t_0. + 2. A request is received, the system measures 1 request. + 3. A request is received, the system measures 1 request. + 4. A request is received, the system measures 1 request. + 5. The 1 second collection cycle ends. A metric is exported for the + number of requests received over the interval of time t_0 to + t_0+1 with a value of 3. + 6. A request is received, the system measures 1 request. + 7. A request is received, the system measures 1 request. + 8. The 1 second collection cycle ends. A metric is exported for the + number of requests received over the interval of time t_0+1 to + t_0+2 with a value of 2. */ + AGGREGATION_TEMPORALITY_DELTA = 1, + + /** CUMULATIVE is an AggregationTemporality for a metric aggregator which + reports changes since a fixed start time. This means that current values + of a CUMULATIVE metric depend on all previous measurements since the + start time. Because of this, the sender is required to retain this state + in some form. If this state is lost or invalidated, the CUMULATIVE metric + values MUST be reset and a new fixed start time following the last + reported measurement time sent MUST be used. + + For example, consider a system measuring the number of requests that + it receives and reports the sum of these requests every second as a + CUMULATIVE metric: + + 1. The system starts receiving at time=t_0. + 2. A request is received, the system measures 1 request. + 3. A request is received, the system measures 1 request. + 4. A request is received, the system measures 1 request. + 5. The 1 second collection cycle ends. A metric is exported for the + number of requests received over the interval of time t_0 to + t_0+1 with a value of 3. + 6. A request is received, the system measures 1 request. + 7. A request is received, the system measures 1 request. + 8. The 1 second collection cycle ends. A metric is exported for the + number of requests received over the interval of time t_0 to + t_0+2 with a value of 5. + 9. The system experiences a fault and loses state. + 10. The system recovers and resumes receiving at time=t_1. + 11. A request is received, the system measures 1 request. + 12. The 1 second collection cycle ends. A metric is exported for the + number of requests received over the interval of time t_1 to + t_0+1 with a value of 1. + + Note: Even though, when reporting changes since last report time, using + CUMULATIVE is valid, it is not recommended. This may cause problems for + systems that do not use start_time to determine when the aggregation + value was reset (e.g. Prometheus). */ + AGGREGATION_TEMPORALITY_CUMULATIVE = 2 +} diff --git a/experimental/packages/otlp-transformer-metrics/test/index-webpack.ts b/experimental/packages/otlp-transformer-metrics/test/index-webpack.ts new file mode 100644 index 00000000000..061a48ccfa7 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/test/index-webpack.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ +const testsContext = require.context('.', true, /test$/); +testsContext.keys().forEach(testsContext); + +const srcContext = require.context('.', true, /src$/); +srcContext.keys().forEach(srcContext); diff --git a/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts b/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts new file mode 100644 index 00000000000..ff8bc4100a2 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts @@ -0,0 +1,393 @@ +/* + * 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 { ValueType } from '@opentelemetry/api-metrics'; +import { Resource } from '@opentelemetry/resources'; +import { + AggregationTemporality, + DataPointType, + InstrumentType, + MetricData, + ResourceMetrics +} from '@opentelemetry/sdk-metrics-base'; +import * as assert from 'assert'; +import { createExportMetricsServiceRequest } from '../src/metrics'; +import { EAggregationTemporality } from '../src/metrics/types'; +import { hrTime, hrTimeToNanoseconds } from '@opentelemetry/core'; + +const START_TIME = hrTime(); +const END_TIME = hrTime(); + +describe('Metrics', () => { + describe('createExportMetricsServiceRequest', () => { + function createCounterData(value: number, aggregationTemporality: AggregationTemporality): MetricData { + return { + descriptor: { + description: 'this is a description', + type: InstrumentType.COUNTER, + name: 'counter', + unit: '1', + valueType: ValueType.INT, + }, + aggregationTemporality, + dataPointType: DataPointType.SINGULAR, + dataPoints: [ + { + value: value, + startTime: START_TIME, + endTime: END_TIME, + attributes: { 'string-attribute': 'some attribute value' } + } + ] + }; + } + + function createObservableCounterData(value: number, aggregationTemporality: AggregationTemporality): MetricData { + return { + descriptor: { + description: 'this is a description', + type: InstrumentType.OBSERVABLE_COUNTER, + name: 'observable-counter', + unit: '1', + valueType: ValueType.INT, + }, + aggregationTemporality, + dataPointType: DataPointType.SINGULAR, + dataPoints: [ + { + value: value, + startTime: START_TIME, + endTime: END_TIME, + attributes: { 'string-attribute': 'some attribute value' } + } + ] + }; + } + + function createObservableGaugeData(value: number): MetricData { + return { + descriptor: { + description: 'this is a description', + type: InstrumentType.OBSERVABLE_GAUGE, + name: 'gauge', + unit: '1', + valueType: ValueType.DOUBLE, + }, + aggregationTemporality: AggregationTemporality.CUMULATIVE, + dataPointType: DataPointType.SINGULAR, + dataPoints: [ + { + value: value, + startTime: START_TIME, + endTime: END_TIME, + attributes: { 'string-attribute': 'some attribute value' } + } + ] + }; + } + + function createHistogramMetrics(count: number, sum: number, boundaries: number[], counts: number[], aggregationTemporality: AggregationTemporality): MetricData { + return { + descriptor: { + description: 'this is a description', + type: InstrumentType.HISTOGRAM, + name: 'hist', + unit: '1', + valueType: ValueType.INT, + }, + aggregationTemporality, + dataPointType: DataPointType.HISTOGRAM, + dataPoints: [ + { + value: { + sum: sum, + count: count, + buckets: { + boundaries: boundaries, + counts: counts + } + }, + startTime: START_TIME, + endTime: END_TIME, + attributes: { 'string-attribute': 'some attribute value' }, + } + ] + }; + } + + function createResourceMetrics(metricData: MetricData[]): ResourceMetrics { + const resource = new Resource({ + 'resource-attribute': 'resource attribute value', + }); + return { + resource: resource, + scopeMetrics: + [ + { + scope: { + name: 'mylib', + version: '0.1.0', + schemaUrl: 'http://url.to.schema' + }, + metrics: metricData + } + ] + }; + } + + it('serializes a sum metric record', () => { + const metrics = createResourceMetrics([createCounterData(10, AggregationTemporality.DELTA)]); + const exportRequest = createExportMetricsServiceRequest([metrics]); + assert.ok(exportRequest); + + assert.deepStrictEqual(exportRequest, { + resourceMetrics: [ + { + resource: { + attributes: [ + { + key: 'resource-attribute', + value: { + stringValue: 'resource attribute value', + }, + }, + ], + droppedAttributesCount: 0, + }, + schemaUrl: undefined, + scopeMetrics: [ + { + scope: { + name: 'mylib', + version: '0.1.0', + }, + schemaUrl: 'http://url.to.schema', + metrics: [ + { + name: 'counter', + description: 'this is a description', + unit: '1', + sum: { + dataPoints: [ + { + attributes: [ + { + key: 'string-attribute', + value: { + stringValue: 'some attribute value', + }, + }, + ], + startTimeUnixNano: hrTimeToNanoseconds(START_TIME), + timeUnixNano: hrTimeToNanoseconds(END_TIME), + asInt: 10, + }, + ], + aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA, + isMonotonic: true, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it('serializes an observable sum metric record', () => { + const exportRequest = createExportMetricsServiceRequest( + [createResourceMetrics([createObservableCounterData(10, AggregationTemporality.DELTA)])] + ); + assert.ok(exportRequest); + + assert.deepStrictEqual(exportRequest, { + resourceMetrics: [ + { + resource: { + attributes: [ + { + key: 'resource-attribute', + value: { + stringValue: 'resource attribute value', + }, + }, + ], + droppedAttributesCount: 0, + }, + schemaUrl: undefined, + scopeMetrics: [ + { + scope: { + name: 'mylib', + version: '0.1.0', + }, + schemaUrl: 'http://url.to.schema', + metrics: [ + { + name: 'observable-counter', + description: 'this is a description', + unit: '1', + sum: { + dataPoints: [ + { + attributes: [ + { + key: 'string-attribute', + value: { + stringValue: 'some attribute value', + }, + }, + ], + startTimeUnixNano: hrTimeToNanoseconds(START_TIME), + timeUnixNano: hrTimeToNanoseconds(END_TIME), + asInt: 10, + }, + ], + aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA, + isMonotonic: true, + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it('serializes a gauge metric record', () => { + const exportRequest = createExportMetricsServiceRequest( + [createResourceMetrics([createObservableGaugeData(10.5)])] + ); + assert.ok(exportRequest); + + assert.deepStrictEqual(exportRequest, { + resourceMetrics: [ + { + resource: { + attributes: [ + { + key: 'resource-attribute', + value: { + stringValue: 'resource attribute value', + }, + }, + ], + droppedAttributesCount: 0, + }, + schemaUrl: undefined, + scopeMetrics: [ + { + scope: { + name: 'mylib', + version: '0.1.0', + }, + schemaUrl: 'http://url.to.schema', + metrics: [ + { + name: 'gauge', + description: 'this is a description', + unit: '1', + gauge: { + dataPoints: [ + { + attributes: [ + { + key: 'string-attribute', + value: { + stringValue: 'some attribute value', + }, + }, + ], + startTimeUnixNano: hrTimeToNanoseconds(START_TIME), + timeUnixNano: hrTimeToNanoseconds(END_TIME), + asDouble: 10.5, + }, + ], + }, + }, + ], + }, + ], + }, + ], + }); + }); + + it('serializes a histogram metric record', () => { + const exportRequest = createExportMetricsServiceRequest( + [createResourceMetrics([createHistogramMetrics(2, 9, [5], [1,1], AggregationTemporality.CUMULATIVE)])] + ); + assert.ok(exportRequest); + + assert.deepStrictEqual(exportRequest, { + resourceMetrics: [ + { + resource: { + attributes: [ + { + key: 'resource-attribute', + value: { + stringValue: 'resource attribute value', + }, + }, + ], + droppedAttributesCount: 0, + }, + schemaUrl: undefined, + scopeMetrics: [ + { + scope: { + name: 'mylib', + version: '0.1.0', + }, + schemaUrl: 'http://url.to.schema', + metrics: [ + { + name: 'hist', + description: 'this is a description', + unit: '1', + histogram: { + aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE, + dataPoints: [ + { + attributes: [ + { + key: 'string-attribute', + value: { + stringValue: 'some attribute value', + }, + }, + ], + bucketCounts: [1, 1], + count: 2, + explicitBounds: [5], + sum: 9, + startTimeUnixNano: hrTimeToNanoseconds(START_TIME), + timeUnixNano: hrTimeToNanoseconds(END_TIME), + }, + ], + }, + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/experimental/packages/otlp-transformer-metrics/tsconfig.all.json b/experimental/packages/otlp-transformer-metrics/tsconfig.all.json new file mode 100644 index 00000000000..06c54913342 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/tsconfig.all.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.base.json", + "files": [], + "references": [ + { "path": "./tsconfig.json" }, + { "path": "./tsconfig.esm.json" }, + { "path": "./tsconfig.esnext.json" } + ] +} diff --git a/experimental/packages/otlp-transformer-metrics/tsconfig.esm.json b/experimental/packages/otlp-transformer-metrics/tsconfig.esm.json new file mode 100644 index 00000000000..379f547a469 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/experimental/packages/otlp-transformer-metrics/tsconfig.esnext.json b/experimental/packages/otlp-transformer-metrics/tsconfig.esnext.json new file mode 100644 index 00000000000..cb78dd6ff39 --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/tsconfig.esnext.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.esnext.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esnext", + "tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/experimental/packages/otlp-transformer-metrics/tsconfig.json b/experimental/packages/otlp-transformer-metrics/tsconfig.json new file mode 100644 index 00000000000..7e4a374d57e --- /dev/null +++ b/experimental/packages/otlp-transformer-metrics/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ], + "references": [ + { + "path": "../../../packages/opentelemetry-core" + }, + { + "path": "../opentelemetry-api-metrics" + }, + { + "path": "../opentelemetry-sdk-metrics-base" + }, + { + "path": "../otlp-transformer" + } + ] +} From 0dbdfe7227a56018399300cc1e7af387e5adab3c Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Wed, 11 May 2022 15:14:18 +0200 Subject: [PATCH 2/8] feat(otlp-transformer): extract otlp-transformer-trace. --- .../otlp-transformer-trace/.eslintignore | 2 + .../otlp-transformer-trace/.eslintrc.js | 8 + .../otlp-transformer-trace/.gitignore | 1 + .../packages/otlp-transformer-trace/README.md | 115 ++++++++ .../otlp-transformer-trace/karma.conf.js | 24 ++ .../otlp-transformer-trace/package.json | 78 ++++++ .../otlp-transformer-trace/src/index.ts | 19 ++ .../otlp-transformer-trace/src/trace/index.ts | 93 +++++++ .../src/trace/internal.ts | 71 +++++ .../otlp-transformer-trace/src/trace/types.ts | 187 +++++++++++++ .../test/index-webpack.ts | 20 ++ .../otlp-transformer-trace/test/trace.test.ts | 252 ++++++++++++++++++ .../otlp-transformer-trace/tsconfig.all.json | 9 + .../otlp-transformer-trace/tsconfig.esm.json | 11 + .../tsconfig.esnext.json | 11 + .../otlp-transformer-trace/tsconfig.json | 25 ++ 16 files changed, 926 insertions(+) create mode 100644 experimental/packages/otlp-transformer-trace/.eslintignore create mode 100644 experimental/packages/otlp-transformer-trace/.eslintrc.js create mode 100644 experimental/packages/otlp-transformer-trace/.gitignore create mode 100644 experimental/packages/otlp-transformer-trace/README.md create mode 100644 experimental/packages/otlp-transformer-trace/karma.conf.js create mode 100644 experimental/packages/otlp-transformer-trace/package.json create mode 100644 experimental/packages/otlp-transformer-trace/src/index.ts create mode 100644 experimental/packages/otlp-transformer-trace/src/trace/index.ts create mode 100644 experimental/packages/otlp-transformer-trace/src/trace/internal.ts create mode 100644 experimental/packages/otlp-transformer-trace/src/trace/types.ts create mode 100644 experimental/packages/otlp-transformer-trace/test/index-webpack.ts create mode 100644 experimental/packages/otlp-transformer-trace/test/trace.test.ts create mode 100644 experimental/packages/otlp-transformer-trace/tsconfig.all.json create mode 100644 experimental/packages/otlp-transformer-trace/tsconfig.esm.json create mode 100644 experimental/packages/otlp-transformer-trace/tsconfig.esnext.json create mode 100644 experimental/packages/otlp-transformer-trace/tsconfig.json diff --git a/experimental/packages/otlp-transformer-trace/.eslintignore b/experimental/packages/otlp-transformer-trace/.eslintignore new file mode 100644 index 00000000000..345f1a599ed --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/.eslintignore @@ -0,0 +1,2 @@ +build +src/generated diff --git a/experimental/packages/otlp-transformer-trace/.eslintrc.js b/experimental/packages/otlp-transformer-trace/.eslintrc.js new file mode 100644 index 00000000000..b9004d20258 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + "env": { + "mocha": true, + "commonjs": true, + "shared-node-browser": true + }, + ...require('../../../eslint.config.js') +} diff --git a/experimental/packages/otlp-transformer-trace/.gitignore b/experimental/packages/otlp-transformer-trace/.gitignore new file mode 100644 index 00000000000..c83f90a2b01 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/.gitignore @@ -0,0 +1 @@ +src/generated diff --git a/experimental/packages/otlp-transformer-trace/README.md b/experimental/packages/otlp-transformer-trace/README.md new file mode 100644 index 00000000000..2c53ce82cac --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/README.md @@ -0,0 +1,115 @@ +# OpenTelemetry Protocol + +[![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]. + +## Quick Start + +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 +``` + +### Serialize Traces and Metrics + +This module exports functions to serialize traces and metrics from the OpenTelemetry SDK into protocol buffers which can be sent over HTTP to the OpenTelemetry collector or a compatible receiver. + +```typescript +import { createExportTraceServiceRequest, createExportMetricsServiceRequest } from "@opentelemetry/otlp-transformer"; + +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: +- For more about OpenTelemetry JavaScript: +- 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 +[npm-url]: https://www.npmjs.com/package/@opentelemetry/otlp-transformer +[npm-img]: https://badge.fury.io/js/%40opentelemetry%otlp-transformer.svg + +[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 diff --git a/experimental/packages/otlp-transformer-trace/karma.conf.js b/experimental/packages/otlp-transformer-trace/karma.conf.js new file mode 100644 index 00000000000..6174839d651 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/karma.conf.js @@ -0,0 +1,24 @@ +/*! + * 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 + * + * 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/experimental/packages/otlp-transformer-trace/package.json b/experimental/packages/otlp-transformer-trace/package.json new file mode 100644 index 00000000000..7facea56c55 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/package.json @@ -0,0 +1,78 @@ +{ + "name": "@opentelemetry/otlp-transformer-trace", + "private": false, + "publishConfig": { + "access": "public" + }, + "version": "0.28.0", + "description": "Transform OpenTelemetry SDK data into OTLP", + "module": "build/esm/index.js", + "esnext": "build/esnext/index.js", + "types": "build/src/index.d.ts", + "main": "build/src/index.js", + "repository": "open-telemetry/opentelemetry-js", + "scripts": { + "compile": "tsc --build tsconfig.all.json", + "clean": "tsc --build --clean tsconfig.all.json", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "tdd": "npm run test -- --watch-extensions ts --watch", + "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", + "test:browser": "nyc karma start --single-run", + "watch": "tsc --build -w tsconfig.all.json", + "peer-api-check": "node ../../../scripts/peer-api-check.js", + "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../" + }, + "keywords": [ + "opentelemetry", + "nodejs", + "grpc", + "protobuf", + "otlp", + "tracing", + "metrics" + ], + "author": "OpenTelemetry Authors", + "license": "Apache-2.0", + "engines": { + "node": ">=8.12.0" + }, + "files": [ + "build/src/**/*.js", + "build/src/**/*.js.map", + "build/src/**/*.d.ts", + "LICENSE", + "README.md" + ], + "peerDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.2.0" + }, + "devDependencies": { + "@opentelemetry/api": ">=1.0.0 <1.2.0", + "@types/mocha": "8.2.3", + "@types/webpack-env": "1.16.3", + "codecov": "3.8.3", + "istanbul-instrumenter-loader": "3.0.1", + "karma": "6.3.16", + "karma-chrome-launcher": "3.1.0", + "karma-coverage-istanbul-reporter": "3.0.3", + "karma-mocha": "2.0.1", + "karma-spec-reporter": "0.0.32", + "karma-webpack": "4.0.2", + "mkdirp": "1.0.4", + "mocha": "7.2.0", + "nyc": "15.1.0", + "protobufjs": "6.11.2", + "rimraf": "3.0.2", + "ts-loader": "8.3.0", + "ts-mocha": "9.0.2", + "typescript": "4.4.4", + "webpack": "4.46.0" + }, + "dependencies": { + "@opentelemetry/core": "1.2.0", + "@opentelemetry/sdk-trace-base": "1.2.0", + "@opentelemetry/resources": "1.2.0", + "@opentelemetry/otlp-transformer": "0.28.0" + } +} diff --git a/experimental/packages/otlp-transformer-trace/src/index.ts b/experimental/packages/otlp-transformer-trace/src/index.ts new file mode 100644 index 00000000000..5ddbe14830e --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/src/index.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +export * from './trace/types'; + +export { createExportTraceServiceRequest } from './trace'; diff --git a/experimental/packages/otlp-transformer-trace/src/trace/index.ts b/experimental/packages/otlp-transformer-trace/src/trace/index.ts new file mode 100644 index 00000000000..577d120e7f9 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/src/trace/index.ts @@ -0,0 +1,93 @@ +/* + * 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 type { Resource } from '@opentelemetry/resources'; +import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; +import { sdkSpanToOtlpSpan } from './internal'; +import { IExportTraceServiceRequest, IResourceSpans, IScopeSpans } from './types'; +import { toAttributes } from '@opentelemetry/otlp-transformer'; + +export function createExportTraceServiceRequest(spans: ReadableSpan[], useHex?: boolean): IExportTraceServiceRequest { + return { + resourceSpans: spanRecordsToResourceSpans(spans, useHex) + }; +} + +function createResourceMap(readableSpans: ReadableSpan[]) { + const resourceMap: Map> = new Map(); + for (const record of readableSpans) { + let ilmMap = resourceMap.get(record.resource); + + if (!ilmMap) { + ilmMap = new Map(); + resourceMap.set(record.resource, ilmMap); + } + + // TODO this is duplicated in basic tracer. Consolidate on a common helper in core + const instrumentationLibraryKey = `${record.instrumentationLibrary.name}@${record.instrumentationLibrary.version || ''}:${record.instrumentationLibrary.schemaUrl || ''}`; + let records = ilmMap.get(instrumentationLibraryKey); + + if (!records) { + records = []; + ilmMap.set(instrumentationLibraryKey, records); + } + + records.push(record); + } + + return resourceMap; +} + +function spanRecordsToResourceSpans(readableSpans: ReadableSpan[], useHex?: boolean): IResourceSpans[] { + const resourceMap = createResourceMap(readableSpans); + const out: IResourceSpans[] = []; + + const entryIterator = resourceMap.entries(); + let entry = entryIterator.next(); + while (!entry.done) { + const [resource, ilmMap] = entry.value; + const scopeResourceSpans: IScopeSpans[] = []; + const ilmIterator = ilmMap.values(); + let ilmEntry = ilmIterator.next(); + while (!ilmEntry.done) { + const scopeSpans = ilmEntry.value; + if (scopeSpans.length > 0) { + const { name, version, schemaUrl } = scopeSpans[0].instrumentationLibrary; + const spans = scopeSpans.map(readableSpan => sdkSpanToOtlpSpan(readableSpan, useHex)); + + scopeResourceSpans.push({ + scope: { name, version }, + spans: spans, + schemaUrl: schemaUrl + }); + } + ilmEntry = ilmIterator.next(); + } + // TODO SDK types don't provide resource schema URL at this time + const transformedSpans: IResourceSpans = { + resource: { + attributes: toAttributes(resource.attributes), + droppedAttributesCount: 0, + }, + scopeSpans: scopeResourceSpans, + schemaUrl: undefined + }; + + out.push(transformedSpans); + entry = entryIterator.next(); + } + + return out; +} diff --git a/experimental/packages/otlp-transformer-trace/src/trace/internal.ts b/experimental/packages/otlp-transformer-trace/src/trace/internal.ts new file mode 100644 index 00000000000..38a8d782bd7 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/src/trace/internal.ts @@ -0,0 +1,71 @@ +/* + * 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 type { Link } from '@opentelemetry/api'; +import { hrTimeToNanoseconds } from '@opentelemetry/core'; +import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; +import { EStatusCode, IEvent, ILink, ISpan } from './types'; +import * as core from '@opentelemetry/core'; +import { toAttributes } from '@opentelemetry/otlp-transformer'; + +export function sdkSpanToOtlpSpan( + span: ReadableSpan, + useHex?: boolean +): ISpan { + const ctx = span.spanContext(); + const status = span.status; + const parentSpanId = useHex? span.parentSpanId : span.parentSpanId != null? core.hexToBase64(span.parentSpanId): undefined; + return { + traceId: useHex? ctx.traceId : core.hexToBase64(ctx.traceId), + spanId: useHex? ctx.spanId : core.hexToBase64(ctx.spanId), + parentSpanId: parentSpanId, + name: span.name, + // Span kind is offset by 1 because the API does not define a value for unset + kind: span.kind == null ? 0 : span.kind + 1, + startTimeUnixNano: hrTimeToNanoseconds(span.startTime), + endTimeUnixNano: hrTimeToNanoseconds(span.endTime), + attributes: toAttributes(span.attributes), + droppedAttributesCount: 0, + events: span.events.map(toOtlpSpanEvent), + droppedEventsCount: 0, + status: { + // API and proto enums share the same values + code: status.code as unknown as EStatusCode, + message: status.message, + }, + links: span.links.map(link => toOtlpLink(link, useHex)), + droppedLinksCount: 0, + }; +} + +export function toOtlpLink(link: Link, useHex?: boolean): ILink { + return { + attributes: link.attributes ? toAttributes(link.attributes) : [], + spanId: useHex? link.context.spanId : core.hexToBase64(link.context.spanId), + traceId: useHex? link.context.traceId : core.hexToBase64(link.context.traceId), + droppedAttributesCount: 0, + }; +} + +export function toOtlpSpanEvent( + timedEvent: TimedEvent +): IEvent { + return { + attributes: timedEvent.attributes ? toAttributes(timedEvent.attributes) : [], + name: timedEvent.name, + timeUnixNano: hrTimeToNanoseconds(timedEvent.time), + droppedAttributesCount: 0, + }; +} diff --git a/experimental/packages/otlp-transformer-trace/src/trace/types.ts b/experimental/packages/otlp-transformer-trace/src/trace/types.ts new file mode 100644 index 00000000000..e3acfad3a26 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/src/trace/types.ts @@ -0,0 +1,187 @@ +/* + * 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 { IInstrumentationScope, IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; + +/** Properties of an ExportTraceServiceRequest. */ +export interface IExportTraceServiceRequest { + + /** ExportTraceServiceRequest resourceSpans */ + resourceSpans?: IResourceSpans[]; +} + +/** Properties of a ResourceSpans. */ +export interface IResourceSpans { + + /** ResourceSpans resource */ + resource?: IResource; + + /** ResourceSpans scopeSpans */ + scopeSpans: IScopeSpans[]; + + /** ResourceSpans schemaUrl */ + schemaUrl?: string; +} + +/** Properties of an ScopeSpans. */ +export interface IScopeSpans { + + /** IScopeSpans scope */ + scope?: IInstrumentationScope; + + /** IScopeSpans spans */ + spans?: ISpan[] + + /** IScopeSpans schemaUrl */ + schemaUrl?: (string | null); +} + +/** Properties of a Span. */ +export interface ISpan { + /** Span traceId */ + traceId: string; + + /** Span spanId */ + spanId: string; + + /** Span traceState */ + traceState?: (string | null); + + /** Span parentSpanId */ + parentSpanId?: string; + + /** Span name */ + name: string; + + /** Span kind */ + kind: ESpanKind; + + /** Span startTimeUnixNano */ + startTimeUnixNano: number; + + /** Span endTimeUnixNano */ + endTimeUnixNano: number; + + /** Span attributes */ + attributes: IKeyValue[]; + + /** Span droppedAttributesCount */ + droppedAttributesCount: number + + /** Span events */ + events: IEvent[]; + + /** Span droppedEventsCount */ + droppedEventsCount: number + + /** Span links */ + links: ILink[]; + + /** Span droppedLinksCount */ + droppedLinksCount: number + + /** Span status */ + status: IStatus; +} + +/** + * SpanKind is the type of span. Can be used to specify additional relationships between spans + * in addition to a parent/child relationship. + */ +export enum ESpanKind { + /** Unspecified. Do NOT use as default. Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. */ + SPAN_KIND_UNSPECIFIED = 0, + + /** Indicates that the span represents an internal operation within an application, + * as opposed to an operation happening at the boundaries. Default value. + */ + SPAN_KIND_INTERNAL = 1, + + /** Indicates that the span covers server-side handling of an RPC or other + * remote network request. + */ + SPAN_KIND_SERVER = 2, + + /** Indicates that the span describes a request to some remote service. + */ + SPAN_KIND_CLIENT = 3, + + /** Indicates that the span describes a producer sending a message to a broker. + * Unlike CLIENT and SERVER, there is often no direct critical path latency relationship + * between producer and consumer spans. A PRODUCER span ends when the message was accepted + * by the broker while the logical processing of the message might span a much longer time. + */ + SPAN_KIND_PRODUCER = 4, + + /** Indicates that the span describes consumer receiving a message from a broker. + * Like the PRODUCER kind, there is often no direct critical path latency relationship + * between producer and consumer spans. + */ + SPAN_KIND_CONSUMER = 5, +} + +/** Properties of a Status. */ +export interface IStatus { + /** Status message */ + message?: string; + + /** Status code */ + code: EStatusCode; +} + +/** StatusCode enum. */ +export const enum EStatusCode { + /** The default status. */ + STATUS_CODE_UNSET = 0, + /** The Span has been evaluated by an Application developers or Operator to have completed successfully. */ + STATUS_CODE_OK = 1, + /** The Span contains an error. */ + STATUS_CODE_ERROR = 2, +} + +/** Properties of an Event. */ +export interface IEvent { + /** Event timeUnixNano */ + timeUnixNano: number; + + /** Event name */ + name: string; + + /** Event attributes */ + attributes: IKeyValue[]; + + /** Event droppedAttributesCount */ + droppedAttributesCount: number; +} + +/** Properties of a Link. */ +export interface ILink { + /** Link traceId */ + traceId: string; + + /** Link spanId */ + spanId: string; + + /** Link traceState */ + traceState?: string; + + /** Link attributes */ + attributes: IKeyValue[]; + + /** Link droppedAttributesCount */ + droppedAttributesCount: number; +} diff --git a/experimental/packages/otlp-transformer-trace/test/index-webpack.ts b/experimental/packages/otlp-transformer-trace/test/index-webpack.ts new file mode 100644 index 00000000000..061a48ccfa7 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/test/index-webpack.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ +const testsContext = require.context('.', true, /test$/); +testsContext.keys().forEach(testsContext); + +const srcContext = require.context('.', true, /src$/); +srcContext.keys().forEach(srcContext); diff --git a/experimental/packages/otlp-transformer-trace/test/trace.test.ts b/experimental/packages/otlp-transformer-trace/test/trace.test.ts new file mode 100644 index 00000000000..b47dcaf1e9c --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/test/trace.test.ts @@ -0,0 +1,252 @@ +/* + * 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 { SpanKind, SpanStatusCode } from '@opentelemetry/api'; +import { TraceState, hexToBase64 } from '@opentelemetry/core'; +import { Resource } from '@opentelemetry/resources'; +import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; +import * as assert from 'assert'; +import { createExportTraceServiceRequest, ESpanKind, EStatusCode } from '../src'; + +function createExpectedSpanJson(useHex: boolean){ + const traceId = useHex? '00000000000000000000000000000001' : hexToBase64('00000000000000000000000000000001'); + const spanId = useHex? '0000000000000002' : hexToBase64('0000000000000002'); + const parentSpanId = useHex? '0000000000000001' : hexToBase64('0000000000000001'); + const linkSpanId = useHex? '0000000000000003' : hexToBase64('0000000000000003'); + const linkTraceId = useHex? '00000000000000000000000000000002' : hexToBase64('00000000000000000000000000000002'); + + return { + resourceSpans: [ + { + resource: { + attributes: [ + { + key: 'resource-attribute', + value: { stringValue: 'resource attribute value' }, + }, + ], + droppedAttributesCount: 0, + }, + schemaUrl: undefined, + scopeSpans: [ + { + scope: { name: 'myLib', version: '0.1.0' }, + spans: [ + { + traceId: traceId, + spanId: spanId, + parentSpanId: parentSpanId, + name: 'span-name', + kind: ESpanKind.SPAN_KIND_CLIENT, + links: [ + { + droppedAttributesCount: 0, + spanId: linkSpanId, + traceId: linkTraceId, + attributes: [ + { + key: 'link-attribute', + value: { + stringValue: 'string value' + } + } + ] + } + ], + // eslint-disable-next-line @typescript-eslint/no-loss-of-precision + startTimeUnixNano: 1640715557342725388, + // eslint-disable-next-line @typescript-eslint/no-loss-of-precision + endTimeUnixNano: 1640715558642725388, + events: [ + { + droppedAttributesCount: 0, + attributes: [ + { + key: 'event-attribute', + value: { + stringValue: 'some string value' + } + } + ], + name: 'some event', + timeUnixNano: 1640715558542725400 + } + ], + attributes: [ + { + key: 'string-attribute', + value: { stringValue: 'some attribute value' }, + }, + ], + droppedAttributesCount: 0, + droppedEventsCount: 0, + droppedLinksCount: 0, + status: { + code: EStatusCode.STATUS_CODE_OK, + message: undefined, + }, + }, + ], + schemaUrl: 'http://url.to.schema', + }, + ], + }, + ], + }; +} + +describe('Trace', () => { + describe('createExportTraceServiceRequest', () => { + let resource: Resource; + let span: ReadableSpan; + + beforeEach(() => { + resource = new Resource({ + 'resource-attribute': 'resource attribute value', + }); + span = { + spanContext: () => ({ + spanId: '0000000000000002', + traceFlags: 1, + traceId: '00000000000000000000000000000001', + isRemote: false, + traceState: new TraceState(''), + }), + parentSpanId: '0000000000000001', + attributes: { 'string-attribute': 'some attribute value' }, + duration: [1, 300000000], + endTime: [1640715558, 642725388], + ended: true, + events: [ + { + name: 'some event', + time: [1640715558, 542725388], + attributes: { + 'event-attribute': 'some string value' + } + } + ], + instrumentationLibrary: { + name: 'myLib', + version: '0.1.0', + schemaUrl: 'http://url.to.schema', + }, + kind: SpanKind.CLIENT, + links: [ + { + context: { + spanId: '0000000000000003', + traceId: '00000000000000000000000000000002', + traceFlags: 1, + isRemote: false, + traceState: new TraceState('') + }, + attributes: { + 'link-attribute': 'string value' + } + } + ], + name: 'span-name', + resource, + startTime: [1640715557, 342725388], + status: { + code: SpanStatusCode.OK, + }, + }; + }); + + it('returns null on an empty list', () => { + assert.deepStrictEqual(createExportTraceServiceRequest([], true), { resourceSpans: [] }); + }); + + it('serializes a span with useHex = true', () => { + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.deepStrictEqual(exportRequest, createExpectedSpanJson(true)); + }); + + it('serializes a span with useHex = false', () => { + const exportRequest = createExportTraceServiceRequest([span], false); + assert.ok(exportRequest); + assert.deepStrictEqual(exportRequest, createExpectedSpanJson(false)); + }); + + it('serializes a span without a parent with useHex = true', () => { + (span as any).parentSpanId = undefined; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId, undefined); + }); + + it('serializes a span without a parent with useHex = false', () => { + (span as any).parentSpanId = undefined; + const exportRequest = createExportTraceServiceRequest([span], false); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId, undefined); + }); + + describe('status code', () => { + it('error', () => { + span.status.code = SpanStatusCode.ERROR; + span.status.message = 'error message'; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + const spanStatus = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].status; + assert.strictEqual(spanStatus?.code, EStatusCode.STATUS_CODE_ERROR); + assert.strictEqual(spanStatus?.message, 'error message'); + }); + + it('unset', () => { + span.status.code = SpanStatusCode.UNSET; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].status.code, EStatusCode.STATUS_CODE_UNSET); + }); + }); + + describe('span kind', () => { + it('consumer', () => { + (span as any).kind = SpanKind.CONSUMER; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_CONSUMER); + }); + it('internal', () => { + (span as any).kind = SpanKind.INTERNAL; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_INTERNAL); + }); + it('producer', () => { + (span as any).kind = SpanKind.PRODUCER; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_PRODUCER); + }); + it('server', () => { + (span as any).kind = SpanKind.SERVER; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_SERVER); + }); + it('unspecified', () => { + (span as any).kind = undefined; + const exportRequest = createExportTraceServiceRequest([span], true); + assert.ok(exportRequest); + assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_UNSPECIFIED); + }); + }); + }); +}); diff --git a/experimental/packages/otlp-transformer-trace/tsconfig.all.json b/experimental/packages/otlp-transformer-trace/tsconfig.all.json new file mode 100644 index 00000000000..06c54913342 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/tsconfig.all.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.base.json", + "files": [], + "references": [ + { "path": "./tsconfig.json" }, + { "path": "./tsconfig.esm.json" }, + { "path": "./tsconfig.esnext.json" } + ] +} diff --git a/experimental/packages/otlp-transformer-trace/tsconfig.esm.json b/experimental/packages/otlp-transformer-trace/tsconfig.esm.json new file mode 100644 index 00000000000..379f547a469 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/experimental/packages/otlp-transformer-trace/tsconfig.esnext.json b/experimental/packages/otlp-transformer-trace/tsconfig.esnext.json new file mode 100644 index 00000000000..cb78dd6ff39 --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/tsconfig.esnext.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.esnext.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esnext", + "tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/experimental/packages/otlp-transformer-trace/tsconfig.json b/experimental/packages/otlp-transformer-trace/tsconfig.json new file mode 100644 index 00000000000..f2e2b65c7bc --- /dev/null +++ b/experimental/packages/otlp-transformer-trace/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ], + "references": [ + { + "path": "../../../packages/opentelemetry-core" + }, + { + "path": "../../../packages/opentelemetry-resources" + }, + { + "path": "../../../packages/opentelemetry-sdk-trace-base" + }, + { + "path": "../otlp-transformer" + } + ] +} From efd03bfd59addfcb6b0061fdd30246cd431bd66b Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Wed, 11 May 2022 15:14:39 +0200 Subject: [PATCH 3/8] feat(otlp-transformer): adapt otlp-transformer for new packages. --- .../otlp-transformer/src/common/index.ts | 24 +++++++++++++++++++ .../otlp-transformer/src/common/internal.ts | 7 ------ .../packages/otlp-transformer/src/index.ts | 1 + .../otlp-transformer/src/metrics/internal.ts | 2 +- .../otlp-transformer/src/trace/index.ts | 2 +- .../otlp-transformer/src/trace/internal.ts | 2 +- tsconfig.json | 6 +++++ 7 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 experimental/packages/otlp-transformer/src/common/index.ts diff --git a/experimental/packages/otlp-transformer/src/common/index.ts b/experimental/packages/otlp-transformer/src/common/index.ts new file mode 100644 index 00000000000..01d50cd92b2 --- /dev/null +++ b/experimental/packages/otlp-transformer/src/common/index.ts @@ -0,0 +1,24 @@ +/* + * 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 { SpanAttributes } from '@opentelemetry/api'; +import { IKeyValue } from './types'; +import { toKeyValue } from './internal'; + +export function toAttributes( + attributes: SpanAttributes +): IKeyValue[] { + return Object.keys(attributes).map(key => toKeyValue(key, attributes[key])); +} diff --git a/experimental/packages/otlp-transformer/src/common/internal.ts b/experimental/packages/otlp-transformer/src/common/internal.ts index 7221f4dce68..517642ae845 100644 --- a/experimental/packages/otlp-transformer/src/common/internal.ts +++ b/experimental/packages/otlp-transformer/src/common/internal.ts @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { SpanAttributes } from '@opentelemetry/api'; import { IAnyValue, IKeyValue } from './types'; -export function toAttributes( - attributes: SpanAttributes -): IKeyValue[] { - return Object.keys(attributes).map(key => toKeyValue(key, attributes[key])); -} - export function toKeyValue( key: string, value: unknown diff --git a/experimental/packages/otlp-transformer/src/index.ts b/experimental/packages/otlp-transformer/src/index.ts index 51408c10d87..bff2629664f 100644 --- a/experimental/packages/otlp-transformer/src/index.ts +++ b/experimental/packages/otlp-transformer/src/index.ts @@ -19,5 +19,6 @@ export * from './metrics/types'; export * from './resource/types'; export * from './trace/types'; +export { toAttributes } from './common'; export { createExportTraceServiceRequest } from './trace'; export { createExportMetricsServiceRequest } from './metrics'; diff --git a/experimental/packages/otlp-transformer/src/metrics/internal.ts b/experimental/packages/otlp-transformer/src/metrics/internal.ts index bd2e67b35b3..08a9b0f1ef4 100644 --- a/experimental/packages/otlp-transformer/src/metrics/internal.ts +++ b/experimental/packages/otlp-transformer/src/metrics/internal.ts @@ -25,7 +25,7 @@ import { MetricData, ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; -import { toAttributes } from '../common/internal'; +import { toAttributes } from '../common'; import { EAggregationTemporality, IHistogramDataPoint, diff --git a/experimental/packages/otlp-transformer/src/trace/index.ts b/experimental/packages/otlp-transformer/src/trace/index.ts index 0601f017a9f..52c24b80929 100644 --- a/experimental/packages/otlp-transformer/src/trace/index.ts +++ b/experimental/packages/otlp-transformer/src/trace/index.ts @@ -15,9 +15,9 @@ */ import type { Resource } from '@opentelemetry/resources'; import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; -import { toAttributes } from '../common/internal'; import { sdkSpanToOtlpSpan } from './internal'; import { IExportTraceServiceRequest, IResourceSpans, IScopeSpans } from './types'; +import { toAttributes } from '../common'; export function createExportTraceServiceRequest(spans: ReadableSpan[], useHex?: boolean): IExportTraceServiceRequest { return { diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts index 87a8182c3f5..ecda330df6d 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal.ts @@ -16,9 +16,9 @@ import type { Link } from '@opentelemetry/api'; import { hrTimeToNanoseconds } from '@opentelemetry/core'; import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; -import { toAttributes } from '../common/internal'; import { EStatusCode, IEvent, ILink, ISpan } from './types'; import * as core from '@opentelemetry/core'; +import { toAttributes } from '../common'; export function sdkSpanToOtlpSpan( span: ReadableSpan, diff --git a/tsconfig.json b/tsconfig.json index 7b24699251c..a92c1e57601 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -142,6 +142,12 @@ { "path": "experimental/packages/otlp-proto-exporter-base" }, + { + "path": "experimental/packages/otlp-transformer-metrics" + }, + { + "path": "experimental/packages/otlp-transformer-trace" + }, { "path": "experimental/packages/otlp-transformer" }, From 821eff380e11ba730dd0a94a50ea3b53e6a6ca75 Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Wed, 11 May 2022 16:20:25 +0200 Subject: [PATCH 4/8] feat(otlp-transformer): migrate packages to new dependencies. --- .../exporter-trace-otlp-grpc/package.json | 2 +- .../src/OTLPTraceExporter.ts | 5 +- .../test/OTLPTraceExporter.test.ts | 2 +- .../test/traceHelper.ts | 4 +- .../exporter-trace-otlp-grpc/tsconfig.json | 2 +- .../exporter-trace-otlp-http/package.json | 2 +- .../src/platform/browser/OTLPTraceExporter.ts | 5 +- .../src/platform/node/OTLPTraceExporter.ts | 5 +- .../browser/CollectorTraceExporter.test.ts | 2 +- .../test/node/CollectorTraceExporter.test.ts | 2 +- .../test/traceHelper.ts | 8 +- .../exporter-trace-otlp-http/tsconfig.json | 2 +- .../exporter-trace-otlp-proto/package.json | 2 +- .../src/OTLPTraceExporter.ts | 5 +- .../test/OTLPTraceExporter.test.ts | 2 +- .../test/traceHelper.ts | 8 +- .../exporter-trace-otlp-proto/tsconfig.json | 2 +- .../package.json | 2 +- .../src/OTLPMetricExporter.ts | 2 +- .../test/OTLPMetricExporter.test.ts | 2 +- .../test/metricsHelper.ts | 3 +- .../tsconfig.json | 2 +- .../package.json | 2 +- .../src/OTLPMetricExporterBase.ts | 2 +- .../platform/browser/OTLPMetricExporter.ts | 5 +- .../src/platform/node/OTLPMetricExporter.ts | 7 +- .../browser/CollectorMetricExporter.test.ts | 2 +- .../common/CollectorMetricExporter.test.ts | 2 +- .../test/metricsHelper.ts | 3 +- .../test/node/CollectorMetricExporter.test.ts | 2 +- .../tsconfig.json | 2 +- .../package.json | 2 +- .../src/OTLPMetricExporter.ts | 2 +- .../test/OTLPMetricExporter.test.ts | 2 +- .../test/metricsHelper.ts | 3 +- .../tsconfig.json | 2 +- .../otlp-grpc-exporter-base/package.json | 2 +- .../test/traceHelper.ts | 3 +- .../otlp-grpc-exporter-base/tsconfig.json | 2 +- .../packages/otlp-transformer/package.json | 7 - .../packages/otlp-transformer/src/index.ts | 4 - .../otlp-transformer/src/metrics/index.ts | 24 -- .../otlp-transformer/src/metrics/internal.ts | 169 -------- .../otlp-transformer/src/metrics/types.ts | 351 ---------------- .../otlp-transformer/src/trace/index.ts | 93 ----- .../otlp-transformer/src/trace/internal.ts | 71 ---- .../otlp-transformer/src/trace/types.ts | 187 --------- .../otlp-transformer/test/metrics.test.ts | 393 ------------------ .../otlp-transformer/test/trace.test.ts | 252 ----------- .../packages/otlp-transformer/tsconfig.json | 17 - 50 files changed, 70 insertions(+), 1614 deletions(-) delete mode 100644 experimental/packages/otlp-transformer/src/metrics/index.ts delete mode 100644 experimental/packages/otlp-transformer/src/metrics/internal.ts delete mode 100644 experimental/packages/otlp-transformer/src/metrics/types.ts delete mode 100644 experimental/packages/otlp-transformer/src/trace/index.ts delete mode 100644 experimental/packages/otlp-transformer/src/trace/internal.ts delete mode 100644 experimental/packages/otlp-transformer/src/trace/types.ts delete mode 100644 experimental/packages/otlp-transformer/test/metrics.test.ts delete mode 100644 experimental/packages/otlp-transformer/test/trace.test.ts diff --git a/experimental/packages/exporter-trace-otlp-grpc/package.json b/experimental/packages/exporter-trace-otlp-grpc/package.json index fcc3bd3eff3..28663ec53ac 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/package.json +++ b/experimental/packages/exporter-trace-otlp-grpc/package.json @@ -70,7 +70,7 @@ "@opentelemetry/core": "1.2.0", "@grpc/grpc-js": "^1.5.9", "@grpc/proto-loader": "^0.6.9", - "@opentelemetry/otlp-transformer": "0.28.0", + "@opentelemetry/otlp-transformer-trace": "0.28.0", "@opentelemetry/otlp-grpc-exporter-base": "0.28.0", "@opentelemetry/resources": "1.2.0", "@opentelemetry/sdk-trace-base": "1.2.0" diff --git a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts index 5ea0829dc59..03b4b671d65 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/src/OTLPTraceExporter.ts @@ -23,7 +23,10 @@ import { ServiceClientType, validateAndNormalizeUrl } from '@opentelemetry/otlp-grpc-exporter-base'; -import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportTraceServiceRequest, + IExportTraceServiceRequest +} from '@opentelemetry/otlp-transformer-trace'; const DEFAULT_COLLECTOR_URL = 'localhost:4317'; diff --git a/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts index 03e8be4c6eb..3897fd87839 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts @@ -37,7 +37,7 @@ import { import * as core from '@opentelemetry/core'; import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base'; import { GrpcCompressionAlgorithm } from '@opentelemetry/otlp-grpc-exporter-base'; -import { IExportTraceServiceRequest, IResourceSpans } from '@opentelemetry/otlp-transformer'; +import { IExportTraceServiceRequest, IResourceSpans } from '@opentelemetry/otlp-transformer-trace'; const traceServiceProtoPath = 'opentelemetry/proto/collector/trace/v1/trace_service.proto'; diff --git a/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts index 5b0d0444a19..f2efd6df2d3 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts @@ -20,7 +20,9 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; import { VERSION } from '@opentelemetry/core'; -import { IEvent, IKeyValue, ILink, IResource, ISpan } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IEvent, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; + const traceIdArr = [ 31, diff --git a/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json b/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json index 94d47b6e191..3b489c13149 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json @@ -25,7 +25,7 @@ "path": "../otlp-grpc-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-trace" } ] } diff --git a/experimental/packages/exporter-trace-otlp-http/package.json b/experimental/packages/exporter-trace-otlp-http/package.json index f973ae4b43d..5882cdd2325 100644 --- a/experimental/packages/exporter-trace-otlp-http/package.json +++ b/experimental/packages/exporter-trace-otlp-http/package.json @@ -98,6 +98,6 @@ "@opentelemetry/resources": "1.2.0", "@opentelemetry/sdk-trace-base": "1.2.0", "@opentelemetry/otlp-exporter-base": "0.28.0", - "@opentelemetry/otlp-transformer": "0.28.0" + "@opentelemetry/otlp-transformer-trace": "0.28.0" } } diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index 21c78e83680..4528c1a16d4 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -18,7 +18,10 @@ import { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@o import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { getEnv, baggageUtils } from '@opentelemetry/core'; import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportTraceServiceRequest, + IExportTraceServiceRequest +} from '@opentelemetry/otlp-transformer-trace'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 517148717d1..890691fe0af 100644 --- a/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -21,7 +21,10 @@ import { OTLPExporterNodeConfigBase, appendResourcePathToUrlIfNotPresent } from '@opentelemetry/otlp-exporter-base'; -import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportTraceServiceRequest, + IExportTraceServiceRequest +} from '@opentelemetry/otlp-transformer-trace'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index 7970005c083..0af693645b9 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -29,7 +29,7 @@ import { mockedReadableSpan, } from '../traceHelper'; import { OTLPExporterConfigBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base'; -import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer-trace'; describe('OTLPTraceExporter - web', () => { let collectorTraceExporter: OTLPTraceExporter; diff --git a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index 3e9da9370ea..69baeb21d1a 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -37,7 +37,7 @@ import { } from '../traceHelper'; import { nextTick } from 'process'; import { MockedResponse } from './nodeHelpers'; -import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer-trace'; let fakeRequest: PassThrough; diff --git a/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts index e5415fcf6a2..092423333ab 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts @@ -20,14 +20,10 @@ import { Resource } from '@opentelemetry/resources'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import { - ESpanKind, - IEvent, - IExportTraceServiceRequest, IKeyValue, - ILink, - IResource, - ISpan + IResource } from '@opentelemetry/otlp-transformer'; +import { ESpanKind, IEvent, IExportTraceServiceRequest, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; if (typeof Buffer === 'undefined') { (window as any).Buffer = { diff --git a/experimental/packages/exporter-trace-otlp-http/tsconfig.json b/experimental/packages/exporter-trace-otlp-http/tsconfig.json index 087c804079c..7b945943321 100644 --- a/experimental/packages/exporter-trace-otlp-http/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-http/tsconfig.json @@ -22,7 +22,7 @@ "path": "../otlp-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-trace" } ] } diff --git a/experimental/packages/exporter-trace-otlp-proto/package.json b/experimental/packages/exporter-trace-otlp-proto/package.json index c0a652e8696..c52d3b8c536 100644 --- a/experimental/packages/exporter-trace-otlp-proto/package.json +++ b/experimental/packages/exporter-trace-otlp-proto/package.json @@ -73,6 +73,6 @@ "@opentelemetry/otlp-exporter-base": "0.28.0", "@opentelemetry/otlp-proto-exporter-base": "0.28.0", "protobufjs": "^6.9.0", - "@opentelemetry/otlp-transformer": "0.28.0" + "@opentelemetry/otlp-transformer-trace": "0.28.0" } } diff --git a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index 9fcc7f5a3fe..f54cf031917 100644 --- a/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/experimental/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -18,7 +18,10 @@ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { getEnv, baggageUtils } from '@opentelemetry/core'; import { appendResourcePathToUrlIfNotPresent, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { OTLPProtoExporterNodeBase, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base'; -import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportTraceServiceRequest, + IExportTraceServiceRequest +} from '@opentelemetry/otlp-transformer-trace'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts index e68a02e762b..d1bad46e047 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/OTLPTraceExporter.test.ts @@ -31,7 +31,7 @@ import { } from './traceHelper'; import { CompressionAlgorithm, OTLPExporterNodeConfigBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base'; import { getExportRequestProto } from '@opentelemetry/otlp-proto-exporter-base'; -import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer-trace'; let fakeRequest: PassThrough; diff --git a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts index 10a07654585..0a474843454 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts @@ -20,7 +20,13 @@ import { Resource } from '@opentelemetry/resources'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import { Stream } from 'stream'; -import { IEvent, IExportTraceServiceRequest, IKeyValue, ILink, ISpan } from '@opentelemetry/otlp-transformer'; +import { IKeyValue } from '@opentelemetry/otlp-transformer'; +import { + IEvent, + IExportTraceServiceRequest, + ILink, + ISpan +} from '@opentelemetry/otlp-transformer-trace'; const traceIdHex = '1f1008dc8e270e85c40a0d7c3939b278'; const spanIdHex = '5e107261f64fa53e'; diff --git a/experimental/packages/exporter-trace-otlp-proto/tsconfig.json b/experimental/packages/exporter-trace-otlp-proto/tsconfig.json index 3324a8a5298..c7e4514d3fb 100644 --- a/experimental/packages/exporter-trace-otlp-proto/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-proto/tsconfig.json @@ -25,7 +25,7 @@ "path": "../otlp-proto-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-trace" } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json index 0b143e0cf1d..973662ed8f0 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json @@ -72,7 +72,7 @@ "@opentelemetry/core": "1.2.0", "@opentelemetry/exporter-metrics-otlp-http": "0.28.0", "@opentelemetry/otlp-grpc-exporter-base": "0.28.0", - "@opentelemetry/otlp-transformer": "0.28.0", + "@opentelemetry/otlp-transformer-metrics": "0.28.0", "@opentelemetry/resources": "1.2.0", "@opentelemetry/sdk-metrics-base": "0.28.0" } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts index f7f45114be6..f9ff023c43f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -28,7 +28,7 @@ import { } from '@opentelemetry/otlp-grpc-exporter-base'; import { baggageUtils, getEnv } from '@opentelemetry/core'; import { Metadata } from '@grpc/grpc-js'; -import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; const DEFAULT_COLLECTOR_URL = 'localhost:4317'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts index b03a6124365..f86d1c99ddc 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts @@ -34,7 +34,7 @@ import { mockObservableGauge, setUp, shutdown, } from './metricsHelper'; import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; -import { IExportMetricsServiceRequest, IResourceMetrics } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest, IResourceMetrics } from '@opentelemetry/otlp-transformer-metrics'; const metricsServiceProtoPath = 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts index 54bd6ee553d..919cabff82a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts @@ -25,7 +25,8 @@ import { MeterProvider, MetricReader, } from '@opentelemetry/sdk-metrics-base'; -import { IKeyValue, IMetric, IResource } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IMetric } from '@opentelemetry/otlp-transformer-metrics'; class TestMetricReader extends MetricReader { selectAggregationTemporality() { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json index 77f463edd10..2301c17e292 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json @@ -28,7 +28,7 @@ "path": "../otlp-grpc-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-metrics" } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index fa25fe07078..280661785f3 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -96,7 +96,7 @@ "dependencies": { "@opentelemetry/api-metrics": "0.28.0", "@opentelemetry/core": "1.2.0", - "@opentelemetry/otlp-transformer": "0.28.0", + "@opentelemetry/otlp-transformer-metrics": "0.28.0", "@opentelemetry/otlp-exporter-base": "0.28.0", "@opentelemetry/resources": "1.2.0", "@opentelemetry/sdk-metrics-base": "0.28.0" diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts index 059d44eeca6..f58ec0e7008 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts @@ -24,7 +24,7 @@ import { } from '@opentelemetry/sdk-metrics-base'; import { defaultOptions, OTLPMetricExporterOptions } from './OTLPMetricExporterOptions'; import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; -import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; export const CumulativeTemporalitySelector: AggregationTemporalitySelector = () => AggregationTemporality.CUMULATIVE; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts index 16dfd998bf9..cdc5595bbde 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/browser/OTLPMetricExporter.ts @@ -23,7 +23,10 @@ import { OTLPExporterBrowserBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportMetricsServiceRequest, + IExportMetricsServiceRequest +} from '@opentelemetry/otlp-transformer-metrics'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index 10de31aa532..b1e217f0ac1 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -15,7 +15,7 @@ */ import { ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; -import { getEnv, baggageUtils} from '@opentelemetry/core'; +import { getEnv, baggageUtils } from '@opentelemetry/core'; import { defaultOptions, OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions'; import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase'; import { @@ -23,7 +23,10 @@ import { OTLPExporterNodeBase, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { + createExportMetricsServiceRequest, + IExportMetricsServiceRequest +} from '@opentelemetry/otlp-transformer-metrics'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts index 18deb1e16d5..ee447a8bece 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts @@ -36,7 +36,7 @@ import { } from '../metricsHelper'; import { OTLPMetricExporterOptions } from '../../src'; import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; describe('OTLPMetricExporter - web', () => { let collectorExporter: OTLPMetricExporter; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts index a7ff5413327..4eaa53bceb7 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts @@ -22,7 +22,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { collect, mockCounter, mockObservableGauge, setUp, shutdown } from '../metricsHelper'; import { OTLPExporterBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; type CollectorExporterConfig = OTLPExporterConfigBase; class OTLPMetricExporter extends OTLPExporterBase< diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts index 9b801c51a4f..f5e617fd0db 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts @@ -30,11 +30,10 @@ import { MetricReader } from '@opentelemetry/sdk-metrics-base'; import { - IExportMetricsServiceRequest, IKeyValue, - IMetric, IResource } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest, IMetric } from '@opentelemetry/otlp-transformer-metrics'; if (typeof Buffer === 'undefined') { (window as any).Buffer = { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index a9076abafb7..d60cf7a9fd8 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -41,7 +41,7 @@ import { MockedResponse } from './nodeHelpers'; import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; import { Stream, PassThrough } from 'stream'; import { OTLPExporterError, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; let fakeRequest: PassThrough; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json index 69019ed4090..43f052a48e5 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json @@ -25,7 +25,7 @@ "path": "../otlp-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-metrics" } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json index dafcc23c943..67fc09e98f9 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json @@ -72,7 +72,7 @@ "@opentelemetry/exporter-metrics-otlp-http": "0.28.0", "@opentelemetry/otlp-proto-exporter-base": "0.28.0", "@opentelemetry/otlp-exporter-base": "0.28.0", - "@opentelemetry/otlp-transformer": "0.28.0", + "@opentelemetry/otlp-transformer-metrics": "0.28.0", "@opentelemetry/resources": "1.2.0", "@opentelemetry/sdk-metrics-base": "0.28.0", "protobufjs": "^6.9.0" diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index ffcbede0418..a1476a309a5 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -22,7 +22,7 @@ import { getEnv, baggageUtils} from '@opentelemetry/core'; import { ResourceMetrics} from '@opentelemetry/sdk-metrics-base'; import { OTLPMetricExporterBase } from '@opentelemetry/exporter-metrics-otlp-http'; import { appendResourcePathToUrlIfNotPresent, OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 086c829ae1d..bf591320a04 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -36,7 +36,7 @@ import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metr import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-http'; import { Stream, PassThrough } from 'stream'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; -import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer-metrics'; let fakeRequest: PassThrough; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts index 80d38bd1641..b86d09bf36a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts @@ -28,8 +28,9 @@ import { MeterProvider, MetricReader } from '@opentelemetry/sdk-metrics-base'; -import { IExportMetricsServiceRequest, IKeyValue, IMetric } from '@opentelemetry/otlp-transformer'; +import { IKeyValue } from '@opentelemetry/otlp-transformer'; import { Stream } from 'stream'; +import { IExportMetricsServiceRequest, IMetric } from '@opentelemetry/otlp-transformer-metrics'; export class TestMetricReader extends MetricReader { selectAggregationTemporality() { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json index 1023f08037d..2a9179bdcb0 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json @@ -31,7 +31,7 @@ "path": "../otlp-proto-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-metrics" } ] } diff --git a/experimental/packages/otlp-grpc-exporter-base/package.json b/experimental/packages/otlp-grpc-exporter-base/package.json index 26486d265c3..3228b529146 100644 --- a/experimental/packages/otlp-grpc-exporter-base/package.json +++ b/experimental/packages/otlp-grpc-exporter-base/package.json @@ -64,7 +64,7 @@ "ts-mocha": "9.0.2", "typescript": "4.4.4", "@opentelemetry/sdk-trace-base": "1.2.0", - "@opentelemetry/otlp-transformer": "0.28.0", + "@opentelemetry/otlp-transformer-trace": "0.28.0", "@opentelemetry/resources": "1.2.0" }, "peerDependencies": { diff --git a/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts b/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts index e8b0204d616..1c0cfd73f09 100644 --- a/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts +++ b/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts @@ -20,7 +20,8 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; import { VERSION } from '@opentelemetry/core'; -import { IEvent, IKeyValue, ILink, IResource, ISpan } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IEvent, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; const traceIdArr = [ 31, diff --git a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json index 087c804079c..7b945943321 100644 --- a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json +++ b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json @@ -22,7 +22,7 @@ "path": "../otlp-exporter-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-trace" } ] } diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer/package.json index 540c5af84f0..369a183cf00 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer/package.json @@ -68,12 +68,5 @@ "ts-mocha": "9.0.2", "typescript": "4.4.4", "webpack": "4.46.0" - }, - "dependencies": { - "@opentelemetry/api-metrics": "0.28.0", - "@opentelemetry/core": "1.2.0", - "@opentelemetry/resources": "1.2.0", - "@opentelemetry/sdk-metrics-base": "0.28.0", - "@opentelemetry/sdk-trace-base": "1.2.0" } } diff --git a/experimental/packages/otlp-transformer/src/index.ts b/experimental/packages/otlp-transformer/src/index.ts index bff2629664f..118e63520a3 100644 --- a/experimental/packages/otlp-transformer/src/index.ts +++ b/experimental/packages/otlp-transformer/src/index.ts @@ -15,10 +15,6 @@ */ export * from './common/types'; -export * from './metrics/types'; export * from './resource/types'; -export * from './trace/types'; export { toAttributes } from './common'; -export { createExportTraceServiceRequest } from './trace'; -export { createExportMetricsServiceRequest } from './metrics'; diff --git a/experimental/packages/otlp-transformer/src/metrics/index.ts b/experimental/packages/otlp-transformer/src/metrics/index.ts deleted file mode 100644 index 28337c3cd41..00000000000 --- a/experimental/packages/otlp-transformer/src/metrics/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 type { ResourceMetrics } from '@opentelemetry/sdk-metrics-base'; -import type { IExportMetricsServiceRequest } from './types'; -import { toResourceMetrics } from './internal'; - -export function createExportMetricsServiceRequest(resourceMetrics: ResourceMetrics[]): IExportMetricsServiceRequest { - return { - resourceMetrics: resourceMetrics.map(metrics => toResourceMetrics(metrics)) - }; -} diff --git a/experimental/packages/otlp-transformer/src/metrics/internal.ts b/experimental/packages/otlp-transformer/src/metrics/internal.ts deleted file mode 100644 index 08a9b0f1ef4..00000000000 --- a/experimental/packages/otlp-transformer/src/metrics/internal.ts +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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 { ValueType } from '@opentelemetry/api-metrics'; -import { hrTimeToNanoseconds } from '@opentelemetry/core'; -import { - AggregationTemporality, - DataPoint, - DataPointType, - Histogram, - ScopeMetrics, - InstrumentType, - MetricData, - ResourceMetrics -} from '@opentelemetry/sdk-metrics-base'; -import { toAttributes } from '../common'; -import { - EAggregationTemporality, - IHistogramDataPoint, - IMetric, - INumberDataPoint, - IResourceMetrics, - IScopeMetrics -} from './types'; - -export function toResourceMetrics(resourceMetrics: ResourceMetrics): IResourceMetrics { - return { - resource: { - attributes: toAttributes(resourceMetrics.resource.attributes), - droppedAttributesCount: 0 - }, - schemaUrl: undefined, // TODO: Schema Url does not exist yet in the SDK. - scopeMetrics: toScopeMetrics(resourceMetrics.scopeMetrics) - }; -} - -export function toScopeMetrics(scopeMetrics: ScopeMetrics[]): IScopeMetrics[]{ - return Array.from(scopeMetrics.map(metrics => { - const scopeMetrics : IScopeMetrics = { - scope: { - name: metrics.scope.name, - version: metrics.scope.version, - }, - metrics: metrics.metrics.map(metricData => toMetric(metricData)), - schemaUrl: metrics.scope.schemaUrl - }; - return scopeMetrics; - })); -} - -export function toMetric(metricData: MetricData): IMetric { - const out: IMetric = { - name: metricData.descriptor.name, - description: metricData.descriptor.description, - unit: metricData.descriptor.unit, - }; - - const aggregationTemporality = toAggregationTemporality(metricData.aggregationTemporality); - - if (metricData.dataPointType === DataPointType.SINGULAR) { - const dataPoints = toSingularDataPoints(metricData); - const isMonotonic = metricData.descriptor.type === InstrumentType.COUNTER || - metricData.descriptor.type === InstrumentType.OBSERVABLE_COUNTER; - if (isSum(metricData)) { - out.sum = { - aggregationTemporality, - isMonotonic, - dataPoints - }; - - } else { - // Instrument is a gauge. - out.gauge = { - dataPoints - }; - } - } else if (isHistogram(metricData)) { - out.histogram = { - aggregationTemporality, - dataPoints: toHistogramDataPoints(metricData) - }; - } - - return out; -} - -function toSingularDataPoint(dataPoint: DataPoint | DataPoint, valueType: ValueType) { - const out: INumberDataPoint = { - attributes: toAttributes(dataPoint.attributes), - startTimeUnixNano: hrTimeToNanoseconds( - dataPoint.startTime - ), - timeUnixNano: hrTimeToNanoseconds( - dataPoint.endTime - ), - }; - - if (valueType === ValueType.INT) { - out.asInt = dataPoint.value as number; - } else if (valueType === ValueType.DOUBLE) { - out.asDouble = dataPoint.value as number; - } - - return out; -} - -function toSingularDataPoints( - metricData: MetricData -): INumberDataPoint[] { - return metricData.dataPoints.map(dataPoint => { - return toSingularDataPoint(dataPoint, metricData.descriptor.valueType); - }); -} - -function toHistogramDataPoints( - metricData: MetricData -): IHistogramDataPoint[] { - return metricData.dataPoints.map(dataPoint => { - const histogram = dataPoint.value as Histogram; - return { - attributes: toAttributes(dataPoint.attributes), - bucketCounts: histogram.buckets.counts, - explicitBounds: histogram.buckets.boundaries, - count: histogram.count, - sum: histogram.sum, - startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime), - timeUnixNano: hrTimeToNanoseconds( - dataPoint.endTime - ), - }; - }); -} - -function isSum(metric: MetricData) { - return (metric.descriptor.type === InstrumentType.COUNTER || - metric.descriptor.type === InstrumentType.UP_DOWN_COUNTER || - metric.descriptor.type === InstrumentType.OBSERVABLE_COUNTER || - metric.descriptor.type === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER); -} - -function isHistogram(metric: MetricData) { - return metric.dataPointType === DataPointType.HISTOGRAM; -} - -function toAggregationTemporality( - temporality: AggregationTemporality, -): EAggregationTemporality { - if (temporality === AggregationTemporality.DELTA) { - return EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA; - } - - if (temporality === AggregationTemporality.CUMULATIVE) { - return EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE; - } - - return EAggregationTemporality.AGGREGATION_TEMPORALITY_UNSPECIFIED; -} diff --git a/experimental/packages/otlp-transformer/src/metrics/types.ts b/experimental/packages/otlp-transformer/src/metrics/types.ts deleted file mode 100644 index 0e98ff2a25c..00000000000 --- a/experimental/packages/otlp-transformer/src/metrics/types.ts +++ /dev/null @@ -1,351 +0,0 @@ -/* - * 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 { IInstrumentationScope, IKeyValue } from '../common/types'; -import { IResource } from '../resource/types'; - -/** Properties of an ExportMetricsServiceRequest. */ -export interface IExportMetricsServiceRequest { - - /** ExportMetricsServiceRequest resourceMetrics */ - resourceMetrics: IResourceMetrics[] -} - -/** Properties of a ResourceMetrics. */ -export interface IResourceMetrics { - - /** ResourceMetrics resource */ - resource?: IResource; - - /** ResourceMetrics scopeMetrics */ - scopeMetrics: IScopeMetrics[] - - /** ResourceMetrics schemaUrl */ - schemaUrl?: string; -} - -/** Properties of an IScopeMetrics. */ -export interface IScopeMetrics { - - /** ScopeMetrics scope */ - scope?: IInstrumentationScope; - - /** ScopeMetrics metrics */ - metrics: IMetric[]; - - /** ScopeMetrics schemaUrl */ - schemaUrl?: string; -} - -/** Properties of a Metric. */ -export interface IMetric { - - /** Metric name */ - name: string; - - /** Metric description */ - description?: string; - - /** Metric unit */ - unit?: string; - - /** Metric gauge */ - gauge?: IGauge; - - /** Metric sum */ - sum?: ISum; - - /** Metric histogram */ - histogram?: IHistogram; - - /** Metric exponentialHistogram */ - exponentialHistogram?: IExponentialHistogram; - - /** Metric summary */ - summary?: ISummary; -} - -/** Properties of a Gauge. */ -export interface IGauge { - /** Gauge dataPoints */ - dataPoints: INumberDataPoint[] -} - -/** Properties of a Sum. */ -export interface ISum { - - /** Sum dataPoints */ - dataPoints: INumberDataPoint[]; - - /** Sum aggregationTemporality */ - aggregationTemporality: EAggregationTemporality - - /** Sum isMonotonic */ - isMonotonic?: (boolean | null); -} - -/** Properties of a Histogram. */ -export interface IHistogram { - /** Histogram dataPoints */ - dataPoints: IHistogramDataPoint[] - - /** Histogram aggregationTemporality */ - aggregationTemporality?: EAggregationTemporality -} - -/** Properties of an ExponentialHistogram. */ -export interface IExponentialHistogram { - /** ExponentialHistogram dataPoints */ - dataPoints: IExponentialHistogramDataPoint[]; - - /** ExponentialHistogram aggregationTemporality */ - aggregationTemporality?: EAggregationTemporality; -} - -/** Properties of a Summary. */ -export interface ISummary { - /** Summary dataPoints */ - dataPoints: ISummaryDataPoint[]; -} - -/** Properties of a NumberDataPoint. */ -export interface INumberDataPoint { - - /** NumberDataPoint attributes */ - attributes: IKeyValue[] - - /** NumberDataPoint startTimeUnixNano */ - startTimeUnixNano?: number; - - /** NumberDataPoint timeUnixNano */ - timeUnixNano?: number; - - /** NumberDataPoint asDouble */ - asDouble?: (number | null); - - /** NumberDataPoint asInt */ - asInt?: number; - - /** NumberDataPoint exemplars */ - exemplars?: IExemplar[]; - - /** NumberDataPoint flags */ - flags?: number; -} - - -/** Properties of a HistogramDataPoint. */ -export interface IHistogramDataPoint { - /** HistogramDataPoint attributes */ - attributes?: IKeyValue[]; - - /** HistogramDataPoint startTimeUnixNano */ - startTimeUnixNano?: number; - - /** HistogramDataPoint timeUnixNano */ - timeUnixNano?: number; - - /** HistogramDataPoint count */ - count?: number; - - /** HistogramDataPoint sum */ - sum?: number; - - /** HistogramDataPoint bucketCounts */ - bucketCounts?: number[] - - /** HistogramDataPoint explicitBounds */ - explicitBounds?: number[] - - /** HistogramDataPoint exemplars */ - exemplars?: IExemplar[]; - - /** HistogramDataPoint flags */ - flags?: number; -} - -/** Properties of an ExponentialHistogramDataPoint. */ -export interface IExponentialHistogramDataPoint { - - /** ExponentialHistogramDataPoint attributes */ - attributes?: IKeyValue[]; - - /** ExponentialHistogramDataPoint startTimeUnixNano */ - startTimeUnixNano?: number; - - /** ExponentialHistogramDataPoint timeUnixNano */ - timeUnixNano?: string; - - /** ExponentialHistogramDataPoint count */ - count?: number; - - /** ExponentialHistogramDataPoint sum */ - sum?: number; - - /** ExponentialHistogramDataPoint scale */ - scale?: number; - - /** ExponentialHistogramDataPoint zeroCount */ - zeroCount?: number; - - /** ExponentialHistogramDataPoint positive */ - positive?: IBuckets; - - /** ExponentialHistogramDataPoint negative */ - negative?: IBuckets; - - /** ExponentialHistogramDataPoint flags */ - flags?: number; - - /** ExponentialHistogramDataPoint exemplars */ - exemplars?: IExemplar[] -} - - -/** Properties of a SummaryDataPoint. */ -export interface ISummaryDataPoint { - /** SummaryDataPoint attributes */ - attributes?: IKeyValue[]; - - /** SummaryDataPoint startTimeUnixNano */ - startTimeUnixNano?: number; - - /** SummaryDataPoint timeUnixNano */ - timeUnixNano?: string; - - /** SummaryDataPoint count */ - count?: number; - - /** SummaryDataPoint sum */ - sum?: number; - - /** SummaryDataPoint quantileValues */ - quantileValues?: IValueAtQuantile[]; - - /** SummaryDataPoint flags */ - flags?: number; -} - -/** Properties of a ValueAtQuantile. */ -export interface IValueAtQuantile { - /** ValueAtQuantile quantile */ - quantile?: number; - - /** ValueAtQuantile value */ - value?: number; -} - -/** Properties of a Buckets. */ -export interface IBuckets { - /** Buckets offset */ - offset?: number; - - /** Buckets bucketCounts */ - bucketCounts?: number[]; -} - -/** Properties of an Exemplar. */ -export interface IExemplar { - /** Exemplar filteredAttributes */ - filteredAttributes?: IKeyValue[]; - - /** Exemplar timeUnixNano */ - timeUnixNano?: string; - - /** Exemplar asDouble */ - asDouble?: number; - - /** Exemplar asInt */ - asInt?: number; - - /** Exemplar spanId */ - spanId?: string; - - /** Exemplar traceId */ - traceId?: string; -} - -/** - * AggregationTemporality defines how a metric aggregator reports aggregated - * values. It describes how those values relate to the time interval over - * which they are aggregated. - */ -export const enum EAggregationTemporality { - /* UNSPECIFIED is the default AggregationTemporality, it MUST not be used. */ - AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, - - /** DELTA is an AggregationTemporality for a metric aggregator which reports - changes since last report time. Successive metrics contain aggregation of - values from continuous and non-overlapping intervals. - - The values for a DELTA metric are based only on the time interval - associated with one measurement cycle. There is no dependency on - previous measurements like is the case for CUMULATIVE metrics. - - For example, consider a system measuring the number of requests that - it receives and reports the sum of these requests every second as a - DELTA metric: - - 1. The system starts receiving at time=t_0. - 2. A request is received, the system measures 1 request. - 3. A request is received, the system measures 1 request. - 4. A request is received, the system measures 1 request. - 5. The 1 second collection cycle ends. A metric is exported for the - number of requests received over the interval of time t_0 to - t_0+1 with a value of 3. - 6. A request is received, the system measures 1 request. - 7. A request is received, the system measures 1 request. - 8. The 1 second collection cycle ends. A metric is exported for the - number of requests received over the interval of time t_0+1 to - t_0+2 with a value of 2. */ - AGGREGATION_TEMPORALITY_DELTA = 1, - - /** CUMULATIVE is an AggregationTemporality for a metric aggregator which - reports changes since a fixed start time. This means that current values - of a CUMULATIVE metric depend on all previous measurements since the - start time. Because of this, the sender is required to retain this state - in some form. If this state is lost or invalidated, the CUMULATIVE metric - values MUST be reset and a new fixed start time following the last - reported measurement time sent MUST be used. - - For example, consider a system measuring the number of requests that - it receives and reports the sum of these requests every second as a - CUMULATIVE metric: - - 1. The system starts receiving at time=t_0. - 2. A request is received, the system measures 1 request. - 3. A request is received, the system measures 1 request. - 4. A request is received, the system measures 1 request. - 5. The 1 second collection cycle ends. A metric is exported for the - number of requests received over the interval of time t_0 to - t_0+1 with a value of 3. - 6. A request is received, the system measures 1 request. - 7. A request is received, the system measures 1 request. - 8. The 1 second collection cycle ends. A metric is exported for the - number of requests received over the interval of time t_0 to - t_0+2 with a value of 5. - 9. The system experiences a fault and loses state. - 10. The system recovers and resumes receiving at time=t_1. - 11. A request is received, the system measures 1 request. - 12. The 1 second collection cycle ends. A metric is exported for the - number of requests received over the interval of time t_1 to - t_0+1 with a value of 1. - - Note: Even though, when reporting changes since last report time, using - CUMULATIVE is valid, it is not recommended. This may cause problems for - systems that do not use start_time to determine when the aggregation - value was reset (e.g. Prometheus). */ - AGGREGATION_TEMPORALITY_CUMULATIVE = 2 -} diff --git a/experimental/packages/otlp-transformer/src/trace/index.ts b/experimental/packages/otlp-transformer/src/trace/index.ts deleted file mode 100644 index 52c24b80929..00000000000 --- a/experimental/packages/otlp-transformer/src/trace/index.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 type { Resource } from '@opentelemetry/resources'; -import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; -import { sdkSpanToOtlpSpan } from './internal'; -import { IExportTraceServiceRequest, IResourceSpans, IScopeSpans } from './types'; -import { toAttributes } from '../common'; - -export function createExportTraceServiceRequest(spans: ReadableSpan[], useHex?: boolean): IExportTraceServiceRequest { - return { - resourceSpans: spanRecordsToResourceSpans(spans, useHex) - }; -} - -function createResourceMap(readableSpans: ReadableSpan[]) { - const resourceMap: Map> = new Map(); - for (const record of readableSpans) { - let ilmMap = resourceMap.get(record.resource); - - if (!ilmMap) { - ilmMap = new Map(); - resourceMap.set(record.resource, ilmMap); - } - - // TODO this is duplicated in basic tracer. Consolidate on a common helper in core - const instrumentationLibraryKey = `${record.instrumentationLibrary.name}@${record.instrumentationLibrary.version || ''}:${record.instrumentationLibrary.schemaUrl || ''}`; - let records = ilmMap.get(instrumentationLibraryKey); - - if (!records) { - records = []; - ilmMap.set(instrumentationLibraryKey, records); - } - - records.push(record); - } - - return resourceMap; -} - -function spanRecordsToResourceSpans(readableSpans: ReadableSpan[], useHex?: boolean): IResourceSpans[] { - const resourceMap = createResourceMap(readableSpans); - const out: IResourceSpans[] = []; - - const entryIterator = resourceMap.entries(); - let entry = entryIterator.next(); - while (!entry.done) { - const [resource, ilmMap] = entry.value; - const scopeResourceSpans: IScopeSpans[] = []; - const ilmIterator = ilmMap.values(); - let ilmEntry = ilmIterator.next(); - while (!ilmEntry.done) { - const scopeSpans = ilmEntry.value; - if (scopeSpans.length > 0) { - const { name, version, schemaUrl } = scopeSpans[0].instrumentationLibrary; - const spans = scopeSpans.map(readableSpan => sdkSpanToOtlpSpan(readableSpan, useHex)); - - scopeResourceSpans.push({ - scope: { name, version }, - spans: spans, - schemaUrl: schemaUrl - }); - } - ilmEntry = ilmIterator.next(); - } - // TODO SDK types don't provide resource schema URL at this time - const transformedSpans: IResourceSpans = { - resource: { - attributes: toAttributes(resource.attributes), - droppedAttributesCount: 0, - }, - scopeSpans: scopeResourceSpans, - schemaUrl: undefined - }; - - out.push(transformedSpans); - entry = entryIterator.next(); - } - - return out; -} diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts deleted file mode 100644 index ecda330df6d..00000000000 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 type { Link } from '@opentelemetry/api'; -import { hrTimeToNanoseconds } from '@opentelemetry/core'; -import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; -import { EStatusCode, IEvent, ILink, ISpan } from './types'; -import * as core from '@opentelemetry/core'; -import { toAttributes } from '../common'; - -export function sdkSpanToOtlpSpan( - span: ReadableSpan, - useHex?: boolean -): ISpan { - const ctx = span.spanContext(); - const status = span.status; - const parentSpanId = useHex? span.parentSpanId : span.parentSpanId != null? core.hexToBase64(span.parentSpanId): undefined; - return { - traceId: useHex? ctx.traceId : core.hexToBase64(ctx.traceId), - spanId: useHex? ctx.spanId : core.hexToBase64(ctx.spanId), - parentSpanId: parentSpanId, - name: span.name, - // Span kind is offset by 1 because the API does not define a value for unset - kind: span.kind == null ? 0 : span.kind + 1, - startTimeUnixNano: hrTimeToNanoseconds(span.startTime), - endTimeUnixNano: hrTimeToNanoseconds(span.endTime), - attributes: toAttributes(span.attributes), - droppedAttributesCount: 0, - events: span.events.map(toOtlpSpanEvent), - droppedEventsCount: 0, - status: { - // API and proto enums share the same values - code: status.code as unknown as EStatusCode, - message: status.message, - }, - links: span.links.map(link => toOtlpLink(link, useHex)), - droppedLinksCount: 0, - }; -} - -export function toOtlpLink(link: Link, useHex?: boolean): ILink { - return { - attributes: link.attributes ? toAttributes(link.attributes) : [], - spanId: useHex? link.context.spanId : core.hexToBase64(link.context.spanId), - traceId: useHex? link.context.traceId : core.hexToBase64(link.context.traceId), - droppedAttributesCount: 0, - }; -} - -export function toOtlpSpanEvent( - timedEvent: TimedEvent -): IEvent { - return { - attributes: timedEvent.attributes ? toAttributes(timedEvent.attributes) : [], - name: timedEvent.name, - timeUnixNano: hrTimeToNanoseconds(timedEvent.time), - droppedAttributesCount: 0, - }; -} diff --git a/experimental/packages/otlp-transformer/src/trace/types.ts b/experimental/packages/otlp-transformer/src/trace/types.ts deleted file mode 100644 index a12260c7e43..00000000000 --- a/experimental/packages/otlp-transformer/src/trace/types.ts +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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 { IInstrumentationScope, IKeyValue } from '../common/types'; -import { IResource } from '../resource/types'; - -/** Properties of an ExportTraceServiceRequest. */ -export interface IExportTraceServiceRequest { - - /** ExportTraceServiceRequest resourceSpans */ - resourceSpans?: IResourceSpans[]; -} - -/** Properties of a ResourceSpans. */ -export interface IResourceSpans { - - /** ResourceSpans resource */ - resource?: IResource; - - /** ResourceSpans scopeSpans */ - scopeSpans: IScopeSpans[]; - - /** ResourceSpans schemaUrl */ - schemaUrl?: string; -} - -/** Properties of an ScopeSpans. */ -export interface IScopeSpans { - - /** IScopeSpans scope */ - scope?: IInstrumentationScope; - - /** IScopeSpans spans */ - spans?: ISpan[] - - /** IScopeSpans schemaUrl */ - schemaUrl?: (string | null); -} - -/** Properties of a Span. */ -export interface ISpan { - /** Span traceId */ - traceId: string; - - /** Span spanId */ - spanId: string; - - /** Span traceState */ - traceState?: (string | null); - - /** Span parentSpanId */ - parentSpanId?: string; - - /** Span name */ - name: string; - - /** Span kind */ - kind: ESpanKind; - - /** Span startTimeUnixNano */ - startTimeUnixNano: number; - - /** Span endTimeUnixNano */ - endTimeUnixNano: number; - - /** Span attributes */ - attributes: IKeyValue[]; - - /** Span droppedAttributesCount */ - droppedAttributesCount: number - - /** Span events */ - events: IEvent[]; - - /** Span droppedEventsCount */ - droppedEventsCount: number - - /** Span links */ - links: ILink[]; - - /** Span droppedLinksCount */ - droppedLinksCount: number - - /** Span status */ - status: IStatus; -} - -/** - * SpanKind is the type of span. Can be used to specify additional relationships between spans - * in addition to a parent/child relationship. - */ -export enum ESpanKind { - /** Unspecified. Do NOT use as default. Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. */ - SPAN_KIND_UNSPECIFIED = 0, - - /** Indicates that the span represents an internal operation within an application, - * as opposed to an operation happening at the boundaries. Default value. - */ - SPAN_KIND_INTERNAL = 1, - - /** Indicates that the span covers server-side handling of an RPC or other - * remote network request. - */ - SPAN_KIND_SERVER = 2, - - /** Indicates that the span describes a request to some remote service. - */ - SPAN_KIND_CLIENT = 3, - - /** Indicates that the span describes a producer sending a message to a broker. - * Unlike CLIENT and SERVER, there is often no direct critical path latency relationship - * between producer and consumer spans. A PRODUCER span ends when the message was accepted - * by the broker while the logical processing of the message might span a much longer time. - */ - SPAN_KIND_PRODUCER = 4, - - /** Indicates that the span describes consumer receiving a message from a broker. - * Like the PRODUCER kind, there is often no direct critical path latency relationship - * between producer and consumer spans. - */ - SPAN_KIND_CONSUMER = 5, -} - -/** Properties of a Status. */ -export interface IStatus { - /** Status message */ - message?: string; - - /** Status code */ - code: EStatusCode; -} - -/** StatusCode enum. */ -export const enum EStatusCode { - /** The default status. */ - STATUS_CODE_UNSET = 0, - /** The Span has been evaluated by an Application developers or Operator to have completed successfully. */ - STATUS_CODE_OK = 1, - /** The Span contains an error. */ - STATUS_CODE_ERROR = 2, -} - -/** Properties of an Event. */ -export interface IEvent { - /** Event timeUnixNano */ - timeUnixNano: number; - - /** Event name */ - name: string; - - /** Event attributes */ - attributes: IKeyValue[]; - - /** Event droppedAttributesCount */ - droppedAttributesCount: number; -} - -/** Properties of a Link. */ -export interface ILink { - /** Link traceId */ - traceId: string; - - /** Link spanId */ - spanId: string; - - /** Link traceState */ - traceState?: string; - - /** Link attributes */ - attributes: IKeyValue[]; - - /** Link droppedAttributesCount */ - droppedAttributesCount: number; -} diff --git a/experimental/packages/otlp-transformer/test/metrics.test.ts b/experimental/packages/otlp-transformer/test/metrics.test.ts deleted file mode 100644 index 77a54ab1e55..00000000000 --- a/experimental/packages/otlp-transformer/test/metrics.test.ts +++ /dev/null @@ -1,393 +0,0 @@ -/* - * 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 { ValueType } from '@opentelemetry/api-metrics'; -import { Resource } from '@opentelemetry/resources'; -import { - AggregationTemporality, - DataPointType, - InstrumentType, - MetricData, - ResourceMetrics -} from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import { createExportMetricsServiceRequest } from '../src/metrics'; -import { EAggregationTemporality } from '../src/metrics/types'; -import { hrTime, hrTimeToNanoseconds } from '@opentelemetry/core'; - -const START_TIME = hrTime(); -const END_TIME = hrTime(); - -describe('Metrics', () => { - describe('createExportMetricsServiceRequest', () => { - function createCounterData(value: number, aggregationTemporality: AggregationTemporality): MetricData { - return { - descriptor: { - description: 'this is a description', - type: InstrumentType.COUNTER, - name: 'counter', - unit: '1', - valueType: ValueType.INT, - }, - aggregationTemporality, - dataPointType: DataPointType.SINGULAR, - dataPoints: [ - { - value: value, - startTime: START_TIME, - endTime: END_TIME, - attributes: { 'string-attribute': 'some attribute value' } - } - ] - }; - } - - function createObservableCounterData(value: number, aggregationTemporality: AggregationTemporality): MetricData { - return { - descriptor: { - description: 'this is a description', - type: InstrumentType.OBSERVABLE_COUNTER, - name: 'observable-counter', - unit: '1', - valueType: ValueType.INT, - }, - aggregationTemporality, - dataPointType: DataPointType.SINGULAR, - dataPoints: [ - { - value: value, - startTime: START_TIME, - endTime: END_TIME, - attributes: { 'string-attribute': 'some attribute value' } - } - ] - }; - } - - function createObservableGaugeData(value: number): MetricData { - return { - descriptor: { - description: 'this is a description', - type: InstrumentType.OBSERVABLE_GAUGE, - name: 'gauge', - unit: '1', - valueType: ValueType.DOUBLE, - }, - aggregationTemporality: AggregationTemporality.CUMULATIVE, - dataPointType: DataPointType.SINGULAR, - dataPoints: [ - { - value: value, - startTime: START_TIME, - endTime: END_TIME, - attributes: { 'string-attribute': 'some attribute value' } - } - ] - }; - } - - function createHistogramMetrics(count: number, sum: number, boundaries: number[], counts: number[], aggregationTemporality: AggregationTemporality): MetricData { - return { - descriptor: { - description: 'this is a description', - type: InstrumentType.HISTOGRAM, - name: 'hist', - unit: '1', - valueType: ValueType.INT, - }, - aggregationTemporality, - dataPointType: DataPointType.HISTOGRAM, - dataPoints: [ - { - value: { - sum: sum, - count: count, - buckets: { - boundaries: boundaries, - counts: counts - } - }, - startTime: START_TIME, - endTime: END_TIME, - attributes: { 'string-attribute': 'some attribute value' }, - } - ] - }; - } - - function createResourceMetrics(metricData: MetricData[]): ResourceMetrics { - const resource = new Resource({ - 'resource-attribute': 'resource attribute value', - }); - return { - resource: resource, - scopeMetrics: - [ - { - scope: { - name: 'mylib', - version: '0.1.0', - schemaUrl: 'http://url.to.schema' - }, - metrics: metricData, - } - ] - }; - } - - it('serializes a sum metric record', () => { - const metrics = createResourceMetrics([createCounterData(10, AggregationTemporality.DELTA)]); - const exportRequest = createExportMetricsServiceRequest([metrics]); - assert.ok(exportRequest); - - assert.deepStrictEqual(exportRequest, { - resourceMetrics: [ - { - resource: { - attributes: [ - { - key: 'resource-attribute', - value: { - stringValue: 'resource attribute value', - }, - }, - ], - droppedAttributesCount: 0, - }, - schemaUrl: undefined, - scopeMetrics: [ - { - scope: { - name: 'mylib', - version: '0.1.0', - }, - schemaUrl: 'http://url.to.schema', - metrics: [ - { - name: 'counter', - description: 'this is a description', - unit: '1', - sum: { - dataPoints: [ - { - attributes: [ - { - key: 'string-attribute', - value: { - stringValue: 'some attribute value', - }, - }, - ], - startTimeUnixNano: hrTimeToNanoseconds(START_TIME), - timeUnixNano: hrTimeToNanoseconds(END_TIME), - asInt: 10, - }, - ], - aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA, - isMonotonic: true, - }, - }, - ], - }, - ], - }, - ], - }); - }); - - it('serializes an observable sum metric record', () => { - const exportRequest = createExportMetricsServiceRequest( - [createResourceMetrics([createObservableCounterData(10, AggregationTemporality.DELTA)])] - ); - assert.ok(exportRequest); - - assert.deepStrictEqual(exportRequest, { - resourceMetrics: [ - { - resource: { - attributes: [ - { - key: 'resource-attribute', - value: { - stringValue: 'resource attribute value', - }, - }, - ], - droppedAttributesCount: 0, - }, - schemaUrl: undefined, - scopeMetrics: [ - { - scope: { - name: 'mylib', - version: '0.1.0', - }, - schemaUrl: 'http://url.to.schema', - metrics: [ - { - name: 'observable-counter', - description: 'this is a description', - unit: '1', - sum: { - dataPoints: [ - { - attributes: [ - { - key: 'string-attribute', - value: { - stringValue: 'some attribute value', - }, - }, - ], - startTimeUnixNano: hrTimeToNanoseconds(START_TIME), - timeUnixNano: hrTimeToNanoseconds(END_TIME), - asInt: 10, - }, - ], - aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA, - isMonotonic: true, - }, - }, - ], - }, - ], - }, - ], - }); - }); - - it('serializes a gauge metric record', () => { - const exportRequest = createExportMetricsServiceRequest( - [createResourceMetrics([createObservableGaugeData(10.5)])] - ); - assert.ok(exportRequest); - - assert.deepStrictEqual(exportRequest, { - resourceMetrics: [ - { - resource: { - attributes: [ - { - key: 'resource-attribute', - value: { - stringValue: 'resource attribute value', - }, - }, - ], - droppedAttributesCount: 0, - }, - schemaUrl: undefined, - scopeMetrics: [ - { - scope: { - name: 'mylib', - version: '0.1.0', - }, - schemaUrl: 'http://url.to.schema', - metrics: [ - { - name: 'gauge', - description: 'this is a description', - unit: '1', - gauge: { - dataPoints: [ - { - attributes: [ - { - key: 'string-attribute', - value: { - stringValue: 'some attribute value', - }, - }, - ], - startTimeUnixNano: hrTimeToNanoseconds(START_TIME), - timeUnixNano: hrTimeToNanoseconds(END_TIME), - asDouble: 10.5, - }, - ], - }, - }, - ], - }, - ], - }, - ], - }); - }); - - it('serializes a histogram metric record', () => { - const exportRequest = createExportMetricsServiceRequest( - [createResourceMetrics([createHistogramMetrics(2, 9, [5], [1,1], AggregationTemporality.CUMULATIVE)])] - ); - assert.ok(exportRequest); - - assert.deepStrictEqual(exportRequest, { - resourceMetrics: [ - { - resource: { - attributes: [ - { - key: 'resource-attribute', - value: { - stringValue: 'resource attribute value', - }, - }, - ], - droppedAttributesCount: 0, - }, - schemaUrl: undefined, - scopeMetrics: [ - { - scope: { - name: 'mylib', - version: '0.1.0', - }, - schemaUrl: 'http://url.to.schema', - metrics: [ - { - name: 'hist', - description: 'this is a description', - unit: '1', - histogram: { - aggregationTemporality: EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE, - dataPoints: [ - { - attributes: [ - { - key: 'string-attribute', - value: { - stringValue: 'some attribute value', - }, - }, - ], - bucketCounts: [1, 1], - count: 2, - explicitBounds: [5], - sum: 9, - startTimeUnixNano: hrTimeToNanoseconds(START_TIME), - timeUnixNano: hrTimeToNanoseconds(END_TIME), - }, - ], - }, - }, - ], - }, - ], - }, - ], - }); - }); - }); -}); diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts deleted file mode 100644 index b47dcaf1e9c..00000000000 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* - * 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 { SpanKind, SpanStatusCode } from '@opentelemetry/api'; -import { TraceState, hexToBase64 } from '@opentelemetry/core'; -import { Resource } from '@opentelemetry/resources'; -import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; -import * as assert from 'assert'; -import { createExportTraceServiceRequest, ESpanKind, EStatusCode } from '../src'; - -function createExpectedSpanJson(useHex: boolean){ - const traceId = useHex? '00000000000000000000000000000001' : hexToBase64('00000000000000000000000000000001'); - const spanId = useHex? '0000000000000002' : hexToBase64('0000000000000002'); - const parentSpanId = useHex? '0000000000000001' : hexToBase64('0000000000000001'); - const linkSpanId = useHex? '0000000000000003' : hexToBase64('0000000000000003'); - const linkTraceId = useHex? '00000000000000000000000000000002' : hexToBase64('00000000000000000000000000000002'); - - return { - resourceSpans: [ - { - resource: { - attributes: [ - { - key: 'resource-attribute', - value: { stringValue: 'resource attribute value' }, - }, - ], - droppedAttributesCount: 0, - }, - schemaUrl: undefined, - scopeSpans: [ - { - scope: { name: 'myLib', version: '0.1.0' }, - spans: [ - { - traceId: traceId, - spanId: spanId, - parentSpanId: parentSpanId, - name: 'span-name', - kind: ESpanKind.SPAN_KIND_CLIENT, - links: [ - { - droppedAttributesCount: 0, - spanId: linkSpanId, - traceId: linkTraceId, - attributes: [ - { - key: 'link-attribute', - value: { - stringValue: 'string value' - } - } - ] - } - ], - // eslint-disable-next-line @typescript-eslint/no-loss-of-precision - startTimeUnixNano: 1640715557342725388, - // eslint-disable-next-line @typescript-eslint/no-loss-of-precision - endTimeUnixNano: 1640715558642725388, - events: [ - { - droppedAttributesCount: 0, - attributes: [ - { - key: 'event-attribute', - value: { - stringValue: 'some string value' - } - } - ], - name: 'some event', - timeUnixNano: 1640715558542725400 - } - ], - attributes: [ - { - key: 'string-attribute', - value: { stringValue: 'some attribute value' }, - }, - ], - droppedAttributesCount: 0, - droppedEventsCount: 0, - droppedLinksCount: 0, - status: { - code: EStatusCode.STATUS_CODE_OK, - message: undefined, - }, - }, - ], - schemaUrl: 'http://url.to.schema', - }, - ], - }, - ], - }; -} - -describe('Trace', () => { - describe('createExportTraceServiceRequest', () => { - let resource: Resource; - let span: ReadableSpan; - - beforeEach(() => { - resource = new Resource({ - 'resource-attribute': 'resource attribute value', - }); - span = { - spanContext: () => ({ - spanId: '0000000000000002', - traceFlags: 1, - traceId: '00000000000000000000000000000001', - isRemote: false, - traceState: new TraceState(''), - }), - parentSpanId: '0000000000000001', - attributes: { 'string-attribute': 'some attribute value' }, - duration: [1, 300000000], - endTime: [1640715558, 642725388], - ended: true, - events: [ - { - name: 'some event', - time: [1640715558, 542725388], - attributes: { - 'event-attribute': 'some string value' - } - } - ], - instrumentationLibrary: { - name: 'myLib', - version: '0.1.0', - schemaUrl: 'http://url.to.schema', - }, - kind: SpanKind.CLIENT, - links: [ - { - context: { - spanId: '0000000000000003', - traceId: '00000000000000000000000000000002', - traceFlags: 1, - isRemote: false, - traceState: new TraceState('') - }, - attributes: { - 'link-attribute': 'string value' - } - } - ], - name: 'span-name', - resource, - startTime: [1640715557, 342725388], - status: { - code: SpanStatusCode.OK, - }, - }; - }); - - it('returns null on an empty list', () => { - assert.deepStrictEqual(createExportTraceServiceRequest([], true), { resourceSpans: [] }); - }); - - it('serializes a span with useHex = true', () => { - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.deepStrictEqual(exportRequest, createExpectedSpanJson(true)); - }); - - it('serializes a span with useHex = false', () => { - const exportRequest = createExportTraceServiceRequest([span], false); - assert.ok(exportRequest); - assert.deepStrictEqual(exportRequest, createExpectedSpanJson(false)); - }); - - it('serializes a span without a parent with useHex = true', () => { - (span as any).parentSpanId = undefined; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId, undefined); - }); - - it('serializes a span without a parent with useHex = false', () => { - (span as any).parentSpanId = undefined; - const exportRequest = createExportTraceServiceRequest([span], false); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].parentSpanId, undefined); - }); - - describe('status code', () => { - it('error', () => { - span.status.code = SpanStatusCode.ERROR; - span.status.message = 'error message'; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - const spanStatus = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].status; - assert.strictEqual(spanStatus?.code, EStatusCode.STATUS_CODE_ERROR); - assert.strictEqual(spanStatus?.message, 'error message'); - }); - - it('unset', () => { - span.status.code = SpanStatusCode.UNSET; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].status.code, EStatusCode.STATUS_CODE_UNSET); - }); - }); - - describe('span kind', () => { - it('consumer', () => { - (span as any).kind = SpanKind.CONSUMER; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_CONSUMER); - }); - it('internal', () => { - (span as any).kind = SpanKind.INTERNAL; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_INTERNAL); - }); - it('producer', () => { - (span as any).kind = SpanKind.PRODUCER; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_PRODUCER); - }); - it('server', () => { - (span as any).kind = SpanKind.SERVER; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_SERVER); - }); - it('unspecified', () => { - (span as any).kind = undefined; - const exportRequest = createExportTraceServiceRequest([span], true); - assert.ok(exportRequest); - assert.strictEqual(exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].kind, ESpanKind.SPAN_KIND_UNSPECIFIED); - }); - }); - }); -}); diff --git a/experimental/packages/otlp-transformer/tsconfig.json b/experimental/packages/otlp-transformer/tsconfig.json index 89cb53e4dea..ed9d0830bdd 100644 --- a/experimental/packages/otlp-transformer/tsconfig.json +++ b/experimental/packages/otlp-transformer/tsconfig.json @@ -7,22 +7,5 @@ "include": [ "src/**/*.ts", "test/**/*.ts" - ], - "references": [ - { - "path": "../../../packages/opentelemetry-core" - }, - { - "path": "../../../packages/opentelemetry-resources" - }, - { - "path": "../../../packages/opentelemetry-sdk-trace-base" - }, - { - "path": "../opentelemetry-api-metrics" - }, - { - "path": "../opentelemetry-sdk-metrics-base" - } ] } From 913ec762cf904af991590f235fb88f3a3ea47656 Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Fri, 13 May 2022 11:21:24 +0200 Subject: [PATCH 5/8] feat(otlp-transformer): rename otlp-transformer -> otlp-transformer-base. --- .../exporter-trace-otlp-grpc/package.json | 3 +- .../test/traceHelper.ts | 2 +- .../exporter-trace-otlp-grpc/tsconfig.json | 3 ++ .../exporter-trace-otlp-http/package.json | 3 +- .../test/traceHelper.ts | 2 +- .../exporter-trace-otlp-http/tsconfig.json | 3 ++ .../exporter-trace-otlp-proto/package.json | 3 +- .../test/traceHelper.ts | 2 +- .../exporter-trace-otlp-proto/tsconfig.json | 3 ++ .../package.json | 3 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 ++ .../package.json | 3 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 ++ .../package.json | 3 +- .../test/metricsHelper.ts | 2 +- .../tsconfig.json | 3 ++ .../otlp-grpc-exporter-base/package.json | 1 + .../test/traceHelper.ts | 2 +- .../otlp-grpc-exporter-base/tsconfig.json | 3 ++ .../.eslintignore | 0 .../.eslintrc.js | 0 .../.gitignore | 0 .../README.md | 0 .../karma.conf.js | 0 .../package.json | 8 ++++- .../src/common/index.ts | 0 .../src/common/internal.ts | 0 .../src/common/types.ts | 0 .../src/index.ts | 0 .../src/resource/types.ts | 0 .../test/common.test.ts | 0 .../test/index-webpack.ts | 0 .../tsconfig.all.json | 0 .../tsconfig.esm.json | 0 .../tsconfig.esnext.json | 0 .../tsconfig.json | 0 .../otlp-transformer-metrics/package.json | 8 ++++- .../src/metrics/internal.ts | 6 ++-- .../src/metrics/types.ts | 3 +- .../otlp-transformer-metrics/tsconfig.json | 2 +- .../otlp-transformer-trace/package.json | 8 ++++- .../otlp-transformer-trace/src/trace/index.ts | 2 +- .../src/trace/internal.ts | 2 +- .../otlp-transformer-trace/src/trace/types.ts | 31 ++++++++++--------- .../otlp-transformer-trace/tsconfig.json | 2 +- tsconfig.json | 6 ++-- 48 files changed, 90 insertions(+), 42 deletions(-) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/.eslintignore (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/.eslintrc.js (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/.gitignore (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/README.md (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/karma.conf.js (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/package.json (90%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/src/common/index.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/src/common/internal.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/src/common/types.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/src/index.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/src/resource/types.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/test/common.test.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/test/index-webpack.ts (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/tsconfig.all.json (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/tsconfig.esm.json (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/tsconfig.esnext.json (100%) rename experimental/packages/{otlp-transformer => otlp-transformer-base}/tsconfig.json (100%) diff --git a/experimental/packages/exporter-trace-otlp-grpc/package.json b/experimental/packages/exporter-trace-otlp-grpc/package.json index 28663ec53ac..9f9d634c985 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/package.json +++ b/experimental/packages/exporter-trace-otlp-grpc/package.json @@ -61,7 +61,8 @@ "sinon": "12.0.1", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts index f2efd6df2d3..a5dcde46545 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts @@ -20,7 +20,7 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; import { VERSION } from '@opentelemetry/core'; -import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer-base'; import { IEvent, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; diff --git a/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json b/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json index 3b489c13149..e6c274f99b8 100644 --- a/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-grpc/tsconfig.json @@ -24,6 +24,9 @@ { "path": "../otlp-grpc-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-trace" } diff --git a/experimental/packages/exporter-trace-otlp-http/package.json b/experimental/packages/exporter-trace-otlp-http/package.json index 5882cdd2325..f09e909c7b2 100644 --- a/experimental/packages/exporter-trace-otlp-http/package.json +++ b/experimental/packages/exporter-trace-otlp-http/package.json @@ -88,7 +88,8 @@ "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.9.1", - "webpack-merge": "5.8.0" + "webpack-merge": "5.8.0", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts index 092423333ab..9d4e2408bc5 100644 --- a/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts @@ -22,7 +22,7 @@ import * as assert from 'assert'; import { IKeyValue, IResource -} from '@opentelemetry/otlp-transformer'; +} from '@opentelemetry/otlp-transformer-base'; import { ESpanKind, IEvent, IExportTraceServiceRequest, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; if (typeof Buffer === 'undefined') { diff --git a/experimental/packages/exporter-trace-otlp-http/tsconfig.json b/experimental/packages/exporter-trace-otlp-http/tsconfig.json index 7b945943321..2a34485beab 100644 --- a/experimental/packages/exporter-trace-otlp-http/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-http/tsconfig.json @@ -21,6 +21,9 @@ { "path": "../otlp-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-trace" } diff --git a/experimental/packages/exporter-trace-otlp-proto/package.json b/experimental/packages/exporter-trace-otlp-proto/package.json index c52d3b8c536..9d0febd110c 100644 --- a/experimental/packages/exporter-trace-otlp-proto/package.json +++ b/experimental/packages/exporter-trace-otlp-proto/package.json @@ -60,7 +60,8 @@ "sinon": "12.0.1", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts index 0a474843454..63a51d0f368 100644 --- a/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts +++ b/experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts @@ -20,7 +20,7 @@ import { Resource } from '@opentelemetry/resources'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import { Stream } from 'stream'; -import { IKeyValue } from '@opentelemetry/otlp-transformer'; +import { IKeyValue } from '@opentelemetry/otlp-transformer-base'; import { IEvent, IExportTraceServiceRequest, diff --git a/experimental/packages/exporter-trace-otlp-proto/tsconfig.json b/experimental/packages/exporter-trace-otlp-proto/tsconfig.json index c7e4514d3fb..b29e78fe157 100644 --- a/experimental/packages/exporter-trace-otlp-proto/tsconfig.json +++ b/experimental/packages/exporter-trace-otlp-proto/tsconfig.json @@ -24,6 +24,9 @@ { "path": "../otlp-proto-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-trace" } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json index 973662ed8f0..499107bb56d 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json @@ -61,7 +61,8 @@ "sinon": "12.0.1", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts index 919cabff82a..dfe2e88f6e4 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/metricsHelper.ts @@ -25,7 +25,7 @@ import { MeterProvider, MetricReader, } from '@opentelemetry/sdk-metrics-base'; -import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer-base'; import { IMetric } from '@opentelemetry/otlp-transformer-metrics'; class TestMetricReader extends MetricReader { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json index 2301c17e292..15b218133fd 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json @@ -27,6 +27,9 @@ { "path": "../otlp-grpc-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-metrics" } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index 280661785f3..8170aa6a68c 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -88,7 +88,8 @@ "typescript": "4.4.4", "webpack": "4.46.0", "webpack-cli": "4.9.1", - "webpack-merge": "5.8.0" + "webpack-merge": "5.8.0", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts index f5e617fd0db..92ff7a0f95e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts @@ -32,7 +32,7 @@ import { import { IKeyValue, IResource -} from '@opentelemetry/otlp-transformer'; +} from '@opentelemetry/otlp-transformer-base'; import { IExportMetricsServiceRequest, IMetric } from '@opentelemetry/otlp-transformer-metrics'; if (typeof Buffer === 'undefined') { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json index 43f052a48e5..41060ece178 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json @@ -24,6 +24,9 @@ { "path": "../otlp-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-metrics" } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json index 67fc09e98f9..b125b5c4ad9 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json @@ -61,7 +61,8 @@ "sinon": "12.0.1", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@opentelemetry/otlp-transformer-base": "0.28.0" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts index b86d09bf36a..19e96017882 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts @@ -28,7 +28,7 @@ import { MeterProvider, MetricReader } from '@opentelemetry/sdk-metrics-base'; -import { IKeyValue } from '@opentelemetry/otlp-transformer'; +import { IKeyValue } from '@opentelemetry/otlp-transformer-base'; import { Stream } from 'stream'; import { IExportMetricsServiceRequest, IMetric } from '@opentelemetry/otlp-transformer-metrics'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json index 2a9179bdcb0..8564aea34a6 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json @@ -30,6 +30,9 @@ { "path": "../otlp-proto-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-metrics" } diff --git a/experimental/packages/otlp-grpc-exporter-base/package.json b/experimental/packages/otlp-grpc-exporter-base/package.json index 3228b529146..f0137735b5e 100644 --- a/experimental/packages/otlp-grpc-exporter-base/package.json +++ b/experimental/packages/otlp-grpc-exporter-base/package.json @@ -65,6 +65,7 @@ "typescript": "4.4.4", "@opentelemetry/sdk-trace-base": "1.2.0", "@opentelemetry/otlp-transformer-trace": "0.28.0", + "@opentelemetry/otlp-transformer-base": "0.28.0", "@opentelemetry/resources": "1.2.0" }, "peerDependencies": { diff --git a/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts b/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts index 1c0cfd73f09..56c9ec22e6d 100644 --- a/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts +++ b/experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts @@ -20,7 +20,7 @@ import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; import { VERSION } from '@opentelemetry/core'; -import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { IKeyValue, IResource } from '@opentelemetry/otlp-transformer-base'; import { IEvent, ILink, ISpan } from '@opentelemetry/otlp-transformer-trace'; const traceIdArr = [ diff --git a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json index 7b945943321..2a34485beab 100644 --- a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json +++ b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json @@ -21,6 +21,9 @@ { "path": "../otlp-exporter-base" }, + { + "path": "../otlp-transformer-base" + }, { "path": "../otlp-transformer-trace" } diff --git a/experimental/packages/otlp-transformer/.eslintignore b/experimental/packages/otlp-transformer-base/.eslintignore similarity index 100% rename from experimental/packages/otlp-transformer/.eslintignore rename to experimental/packages/otlp-transformer-base/.eslintignore diff --git a/experimental/packages/otlp-transformer/.eslintrc.js b/experimental/packages/otlp-transformer-base/.eslintrc.js similarity index 100% rename from experimental/packages/otlp-transformer/.eslintrc.js rename to experimental/packages/otlp-transformer-base/.eslintrc.js diff --git a/experimental/packages/otlp-transformer/.gitignore b/experimental/packages/otlp-transformer-base/.gitignore similarity index 100% rename from experimental/packages/otlp-transformer/.gitignore rename to experimental/packages/otlp-transformer-base/.gitignore diff --git a/experimental/packages/otlp-transformer/README.md b/experimental/packages/otlp-transformer-base/README.md similarity index 100% rename from experimental/packages/otlp-transformer/README.md rename to experimental/packages/otlp-transformer-base/README.md diff --git a/experimental/packages/otlp-transformer/karma.conf.js b/experimental/packages/otlp-transformer-base/karma.conf.js similarity index 100% rename from experimental/packages/otlp-transformer/karma.conf.js rename to experimental/packages/otlp-transformer-base/karma.conf.js diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer-base/package.json similarity index 90% rename from experimental/packages/otlp-transformer/package.json rename to experimental/packages/otlp-transformer-base/package.json index 369a183cf00..ee17bdbbe33 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer-base/package.json @@ -1,5 +1,5 @@ { - "name": "@opentelemetry/otlp-transformer", + "name": "@opentelemetry/otlp-transformer-base", "private": false, "publishConfig": { "access": "public" @@ -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", diff --git a/experimental/packages/otlp-transformer/src/common/index.ts b/experimental/packages/otlp-transformer-base/src/common/index.ts similarity index 100% rename from experimental/packages/otlp-transformer/src/common/index.ts rename to experimental/packages/otlp-transformer-base/src/common/index.ts diff --git a/experimental/packages/otlp-transformer/src/common/internal.ts b/experimental/packages/otlp-transformer-base/src/common/internal.ts similarity index 100% rename from experimental/packages/otlp-transformer/src/common/internal.ts rename to experimental/packages/otlp-transformer-base/src/common/internal.ts diff --git a/experimental/packages/otlp-transformer/src/common/types.ts b/experimental/packages/otlp-transformer-base/src/common/types.ts similarity index 100% rename from experimental/packages/otlp-transformer/src/common/types.ts rename to experimental/packages/otlp-transformer-base/src/common/types.ts diff --git a/experimental/packages/otlp-transformer/src/index.ts b/experimental/packages/otlp-transformer-base/src/index.ts similarity index 100% rename from experimental/packages/otlp-transformer/src/index.ts rename to experimental/packages/otlp-transformer-base/src/index.ts diff --git a/experimental/packages/otlp-transformer/src/resource/types.ts b/experimental/packages/otlp-transformer-base/src/resource/types.ts similarity index 100% rename from experimental/packages/otlp-transformer/src/resource/types.ts rename to experimental/packages/otlp-transformer-base/src/resource/types.ts diff --git a/experimental/packages/otlp-transformer/test/common.test.ts b/experimental/packages/otlp-transformer-base/test/common.test.ts similarity index 100% rename from experimental/packages/otlp-transformer/test/common.test.ts rename to experimental/packages/otlp-transformer-base/test/common.test.ts diff --git a/experimental/packages/otlp-transformer/test/index-webpack.ts b/experimental/packages/otlp-transformer-base/test/index-webpack.ts similarity index 100% rename from experimental/packages/otlp-transformer/test/index-webpack.ts rename to experimental/packages/otlp-transformer-base/test/index-webpack.ts diff --git a/experimental/packages/otlp-transformer/tsconfig.all.json b/experimental/packages/otlp-transformer-base/tsconfig.all.json similarity index 100% rename from experimental/packages/otlp-transformer/tsconfig.all.json rename to experimental/packages/otlp-transformer-base/tsconfig.all.json diff --git a/experimental/packages/otlp-transformer/tsconfig.esm.json b/experimental/packages/otlp-transformer-base/tsconfig.esm.json similarity index 100% rename from experimental/packages/otlp-transformer/tsconfig.esm.json rename to experimental/packages/otlp-transformer-base/tsconfig.esm.json diff --git a/experimental/packages/otlp-transformer/tsconfig.esnext.json b/experimental/packages/otlp-transformer-base/tsconfig.esnext.json similarity index 100% rename from experimental/packages/otlp-transformer/tsconfig.esnext.json rename to experimental/packages/otlp-transformer-base/tsconfig.esnext.json diff --git a/experimental/packages/otlp-transformer/tsconfig.json b/experimental/packages/otlp-transformer-base/tsconfig.json similarity index 100% rename from experimental/packages/otlp-transformer/tsconfig.json rename to experimental/packages/otlp-transformer-base/tsconfig.json diff --git a/experimental/packages/otlp-transformer-metrics/package.json b/experimental/packages/otlp-transformer-metrics/package.json index 353cb4119ec..6d4483bb461 100644 --- a/experimental/packages/otlp-transformer-metrics/package.json +++ b/experimental/packages/otlp-transformer-metrics/package.json @@ -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", @@ -73,6 +79,6 @@ "@opentelemetry/api-metrics": "0.28.0", "@opentelemetry/core": "1.2.0", "@opentelemetry/sdk-metrics-base": "0.28.0", - "@opentelemetry/otlp-transformer": "0.28.0" + "@opentelemetry/otlp-transformer-base": "0.28.0" } } diff --git a/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts b/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts index e03ade73915..44e3d0e71b5 100644 --- a/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts +++ b/experimental/packages/otlp-transformer-metrics/src/metrics/internal.ts @@ -33,7 +33,7 @@ import { IResourceMetrics, IScopeMetrics } from './types'; -import { toAttributes } from '@opentelemetry/otlp-transformer'; +import { toAttributes } from '@opentelemetry/otlp-transformer-base'; export function toResourceMetrics(resourceMetrics: ResourceMetrics): IResourceMetrics { return { @@ -46,9 +46,9 @@ export function toResourceMetrics(resourceMetrics: ResourceMetrics): IResourceMe }; } -export function toScopeMetrics(scopeMetrics: ScopeMetrics[]): IScopeMetrics[]{ +export function toScopeMetrics(scopeMetrics: ScopeMetrics[]): IScopeMetrics[] { return Array.from(scopeMetrics.map(metrics => { - const scopeMetrics : IScopeMetrics = { + const scopeMetrics: IScopeMetrics = { scope: { name: metrics.scope.name, version: metrics.scope.version, diff --git a/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts b/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts index 3aff9c7dc79..4992e5786dc 100644 --- a/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts +++ b/experimental/packages/otlp-transformer-metrics/src/metrics/types.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { IResource, IInstrumentationScope } from '@opentelemetry/otlp-transformer'; -import { IKeyValue } from '@opentelemetry/otlp-transformer'; +import { IInstrumentationScope, IKeyValue, IResource } from '@opentelemetry/otlp-transformer-base'; /** Properties of an ExportMetricsServiceRequest. */ export interface IExportMetricsServiceRequest { diff --git a/experimental/packages/otlp-transformer-metrics/tsconfig.json b/experimental/packages/otlp-transformer-metrics/tsconfig.json index 7e4a374d57e..63266350407 100644 --- a/experimental/packages/otlp-transformer-metrics/tsconfig.json +++ b/experimental/packages/otlp-transformer-metrics/tsconfig.json @@ -19,7 +19,7 @@ "path": "../opentelemetry-sdk-metrics-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-base" } ] } diff --git a/experimental/packages/otlp-transformer-trace/package.json b/experimental/packages/otlp-transformer-trace/package.json index 7facea56c55..a4be4c11b2d 100644 --- a/experimental/packages/otlp-transformer-trace/package.json +++ b/experimental/packages/otlp-transformer-trace/package.json @@ -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", @@ -73,6 +79,6 @@ "@opentelemetry/core": "1.2.0", "@opentelemetry/sdk-trace-base": "1.2.0", "@opentelemetry/resources": "1.2.0", - "@opentelemetry/otlp-transformer": "0.28.0" + "@opentelemetry/otlp-transformer-base": "0.28.0" } } diff --git a/experimental/packages/otlp-transformer-trace/src/trace/index.ts b/experimental/packages/otlp-transformer-trace/src/trace/index.ts index 577d120e7f9..23f4255a420 100644 --- a/experimental/packages/otlp-transformer-trace/src/trace/index.ts +++ b/experimental/packages/otlp-transformer-trace/src/trace/index.ts @@ -17,7 +17,7 @@ import type { Resource } from '@opentelemetry/resources'; import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { sdkSpanToOtlpSpan } from './internal'; import { IExportTraceServiceRequest, IResourceSpans, IScopeSpans } from './types'; -import { toAttributes } from '@opentelemetry/otlp-transformer'; +import { toAttributes } from '@opentelemetry/otlp-transformer-base'; export function createExportTraceServiceRequest(spans: ReadableSpan[], useHex?: boolean): IExportTraceServiceRequest { return { diff --git a/experimental/packages/otlp-transformer-trace/src/trace/internal.ts b/experimental/packages/otlp-transformer-trace/src/trace/internal.ts index 38a8d782bd7..81ead70210c 100644 --- a/experimental/packages/otlp-transformer-trace/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer-trace/src/trace/internal.ts @@ -18,7 +18,7 @@ import { hrTimeToNanoseconds } from '@opentelemetry/core'; import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; import { EStatusCode, IEvent, ILink, ISpan } from './types'; import * as core from '@opentelemetry/core'; -import { toAttributes } from '@opentelemetry/otlp-transformer'; +import { toAttributes } from '@opentelemetry/otlp-transformer-base'; export function sdkSpanToOtlpSpan( span: ReadableSpan, diff --git a/experimental/packages/otlp-transformer-trace/src/trace/types.ts b/experimental/packages/otlp-transformer-trace/src/trace/types.ts index e3acfad3a26..edfd830ab5c 100644 --- a/experimental/packages/otlp-transformer-trace/src/trace/types.ts +++ b/experimental/packages/otlp-transformer-trace/src/trace/types.ts @@ -14,8 +14,11 @@ * limitations under the License. */ - -import { IInstrumentationScope, IKeyValue, IResource } from '@opentelemetry/otlp-transformer'; +import { + IInstrumentationScope, + IKeyValue, + IResource +} from '@opentelemetry/otlp-transformer-base'; /** Properties of an ExportTraceServiceRequest. */ export interface IExportTraceServiceRequest { @@ -107,30 +110,30 @@ export enum ESpanKind { SPAN_KIND_UNSPECIFIED = 0, /** Indicates that the span represents an internal operation within an application, - * as opposed to an operation happening at the boundaries. Default value. - */ + * as opposed to an operation happening at the boundaries. Default value. + */ SPAN_KIND_INTERNAL = 1, /** Indicates that the span covers server-side handling of an RPC or other - * remote network request. - */ + * remote network request. + */ SPAN_KIND_SERVER = 2, /** Indicates that the span describes a request to some remote service. - */ + */ SPAN_KIND_CLIENT = 3, /** Indicates that the span describes a producer sending a message to a broker. - * Unlike CLIENT and SERVER, there is often no direct critical path latency relationship - * between producer and consumer spans. A PRODUCER span ends when the message was accepted - * by the broker while the logical processing of the message might span a much longer time. - */ + * Unlike CLIENT and SERVER, there is often no direct critical path latency relationship + * between producer and consumer spans. A PRODUCER span ends when the message was accepted + * by the broker while the logical processing of the message might span a much longer time. + */ SPAN_KIND_PRODUCER = 4, /** Indicates that the span describes consumer receiving a message from a broker. - * Like the PRODUCER kind, there is often no direct critical path latency relationship - * between producer and consumer spans. - */ + * Like the PRODUCER kind, there is often no direct critical path latency relationship + * between producer and consumer spans. + */ SPAN_KIND_CONSUMER = 5, } diff --git a/experimental/packages/otlp-transformer-trace/tsconfig.json b/experimental/packages/otlp-transformer-trace/tsconfig.json index f2e2b65c7bc..f8209962904 100644 --- a/experimental/packages/otlp-transformer-trace/tsconfig.json +++ b/experimental/packages/otlp-transformer-trace/tsconfig.json @@ -19,7 +19,7 @@ "path": "../../../packages/opentelemetry-sdk-trace-base" }, { - "path": "../otlp-transformer" + "path": "../otlp-transformer-base" } ] } diff --git a/tsconfig.json b/tsconfig.json index a92c1e57601..d5e2711e6c2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -143,13 +143,13 @@ "path": "experimental/packages/otlp-proto-exporter-base" }, { - "path": "experimental/packages/otlp-transformer-metrics" + "path": "experimental/packages/otlp-transformer-base" }, { - "path": "experimental/packages/otlp-transformer-trace" + "path": "experimental/packages/otlp-transformer-metrics" }, { - "path": "experimental/packages/otlp-transformer" + "path": "experimental/packages/otlp-transformer-trace" }, { "path": "experimental/backwards-compatability/node10" From a49233859950d32b4259e0bcbed6bc56afb0375d Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Fri, 13 May 2022 11:47:13 +0200 Subject: [PATCH 6/8] refactor(otlp-transformer-metrics): formatting. --- .../packages/otlp-transformer-metrics/test/metrics.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts b/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts index ff8bc4100a2..77a54ab1e55 100644 --- a/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts +++ b/experimental/packages/otlp-transformer-metrics/test/metrics.test.ts @@ -141,7 +141,7 @@ describe('Metrics', () => { version: '0.1.0', schemaUrl: 'http://url.to.schema' }, - metrics: metricData + metrics: metricData, } ] }; From 8ae3f546df54715be507a1a1f85d84caea09a3dc Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Fri, 13 May 2022 13:09:41 +0200 Subject: [PATCH 7/8] feat(otlp-transformer): cleanup readme and deps. --- .../packages/otlp-transformer-base/README.md | 83 ++---------------- .../otlp-transformer-base/package.json | 1 - .../otlp-transformer-metrics/README.md | 87 ++----------------- .../otlp-transformer-metrics/package.json | 1 - .../packages/otlp-transformer-trace/README.md | 87 ++----------------- .../otlp-transformer-trace/package.json | 1 - 6 files changed, 18 insertions(+), 242 deletions(-) diff --git a/experimental/packages/otlp-transformer-base/README.md b/experimental/packages/otlp-transformer-base/README.md index 2c53ce82cac..c8eb39a70ee 100644 --- a/experimental/packages/otlp-transformer-base/README.md +++ b/experimental/packages/otlp-transformer-base/README.md @@ -3,9 +3,10 @@ [![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] structures that are shared between signals +to [OpenTelemetry Protocol][otlp] format using [protocol buffers][protobuf] or JSON. ## Quick Start @@ -14,80 +15,8 @@ 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 -``` - -### Serialize Traces and Metrics - -This module exports functions to serialize traces and metrics from the OpenTelemetry SDK into protocol buffers which can be sent over HTTP to the OpenTelemetry collector or a compatible receiver. - -```typescript -import { createExportTraceServiceRequest, createExportMetricsServiceRequest } from "@opentelemetry/otlp-transformer"; - -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); -``` +npm install @opentelemetry/api + ``` ## Useful links diff --git a/experimental/packages/otlp-transformer-base/package.json b/experimental/packages/otlp-transformer-base/package.json index ee17bdbbe33..f0ca2dce9ce 100644 --- a/experimental/packages/otlp-transformer-base/package.json +++ b/experimental/packages/otlp-transformer-base/package.json @@ -68,7 +68,6 @@ "mkdirp": "1.0.4", "mocha": "7.2.0", "nyc": "15.1.0", - "protobufjs": "6.11.2", "rimraf": "3.0.2", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", diff --git a/experimental/packages/otlp-transformer-metrics/README.md b/experimental/packages/otlp-transformer-metrics/README.md index 2c53ce82cac..27ea6d33fe3 100644 --- a/experimental/packages/otlp-transformer-metrics/README.md +++ b/experimental/packages/otlp-transformer-metrics/README.md @@ -3,9 +3,10 @@ [![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] metrics to [OpenTelemetry Protocol][otlp] +format using [protocol buffers][protobuf] or JSON. ## Quick Start @@ -14,80 +15,8 @@ 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 -``` - -### Serialize Traces and Metrics - -This module exports functions to serialize traces and metrics from the OpenTelemetry SDK into protocol buffers which can be sent over HTTP to the OpenTelemetry collector or a compatible receiver. - -```typescript -import { createExportTraceServiceRequest, createExportMetricsServiceRequest } from "@opentelemetry/otlp-transformer"; - -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); -``` +npm install @opentelemetry/api + ``` ## Useful links @@ -109,7 +38,3 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [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 diff --git a/experimental/packages/otlp-transformer-metrics/package.json b/experimental/packages/otlp-transformer-metrics/package.json index 6d4483bb461..4da97781cf7 100644 --- a/experimental/packages/otlp-transformer-metrics/package.json +++ b/experimental/packages/otlp-transformer-metrics/package.json @@ -68,7 +68,6 @@ "mkdirp": "1.0.4", "mocha": "7.2.0", "nyc": "15.1.0", - "protobufjs": "6.11.2", "rimraf": "3.0.2", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", diff --git a/experimental/packages/otlp-transformer-trace/README.md b/experimental/packages/otlp-transformer-trace/README.md index 2c53ce82cac..27ea6d33fe3 100644 --- a/experimental/packages/otlp-transformer-trace/README.md +++ b/experimental/packages/otlp-transformer-trace/README.md @@ -3,9 +3,10 @@ [![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] metrics to [OpenTelemetry Protocol][otlp] +format using [protocol buffers][protobuf] or JSON. ## Quick Start @@ -14,80 +15,8 @@ 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 -``` - -### Serialize Traces and Metrics - -This module exports functions to serialize traces and metrics from the OpenTelemetry SDK into protocol buffers which can be sent over HTTP to the OpenTelemetry collector or a compatible receiver. - -```typescript -import { createExportTraceServiceRequest, createExportMetricsServiceRequest } from "@opentelemetry/otlp-transformer"; - -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); -``` +npm install @opentelemetry/api + ``` ## Useful links @@ -109,7 +38,3 @@ Apache 2.0 - See [LICENSE][license-url] for more information. [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 diff --git a/experimental/packages/otlp-transformer-trace/package.json b/experimental/packages/otlp-transformer-trace/package.json index a4be4c11b2d..d79a9d58118 100644 --- a/experimental/packages/otlp-transformer-trace/package.json +++ b/experimental/packages/otlp-transformer-trace/package.json @@ -68,7 +68,6 @@ "mkdirp": "1.0.4", "mocha": "7.2.0", "nyc": "15.1.0", - "protobufjs": "6.11.2", "rimraf": "3.0.2", "ts-loader": "8.3.0", "ts-mocha": "9.0.2", From 284a24429190bda1de40619b21a684381882d872 Mon Sep 17 00:00:00 2001 From: "marc.pichler" Date: Fri, 13 May 2022 13:27:52 +0200 Subject: [PATCH 8/8] fix(changelog): add changelog entry. --- experimental/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index a703efc970b..f4be95baa3e 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to experimental packages in this project will be documented * feat(exporters): update proto version and use otlp-transformer #2929 @pichlermarc * fix(sdk-metrics-base): misbehaving aggregation temporality selector tolerance #2958 @legendecas * feat(sdk-metrics-base): async instruments callback timeout #2742 @legendecas +* feat(otlp-transformer): split otlp-transformer into multiple packages #2968 @pichlermarc ### :bug: (Bug Fix)