From 0ee39deae40ce8894dde8a39ccc8477225cdcd8b Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 4 Nov 2021 15:25:09 -0400 Subject: [PATCH] chore: remove exporters depending on old metrics SDK --- .../package.json | 1 + .../src/OTLPMetricExporter.ts | 65 +-- .../test/OTLPMetricExporter.test.ts | 304 ------------ .../test/noop.test.ts | 0 .../tsconfig.json | 9 + .../package.json | 1 + .../platform/browser/OTLPMetricExporter.ts | 48 +- .../src/platform/node/OTLPMetricExporter.ts | 55 +-- .../src/transformMetrics.ts | 259 ---------- .../browser/CollectorMetricExporter.test.ts | 431 ----------------- .../test/browser/index-webpack.ts | 23 - .../common/CollectorMetricExporter.test.ts | 198 -------- .../test/common/transformMetrics.test.ts | 233 --------- .../test/metricsHelper.ts | 448 ------------------ .../test/node/CollectorMetricExporter.test.ts | 317 ------------- .../test/node/nodeHelpers.ts | 36 -- .../test/noop.test.ts | 0 .../tsconfig.esm.json | 8 + .../tsconfig.json | 8 + .../package.json | 1 + .../src/OTLPMetricExporter.ts | 57 +-- .../test/OTLPMetricExporter.test.ts | 259 ---------- .../test/metricsHelper.ts | 223 --------- .../test/noop.test.ts | 0 .../tsconfig.json | 8 +- .../package.json | 1 + .../src/PrometheusSerializer.ts | 2 +- .../test/PrometheusExporter.test.ts | 16 +- .../test/PrometheusSerializer.test.ts | 32 +- .../tsconfig.json | 3 - .../tsconfig.json | 6 - .../tsconfig.esm.json | 8 - .../tsconfig.json | 8 - .../tsconfig.json | 6 - .../opentelemetry-sdk-node/tsconfig.json | 3 - experimental/tsconfig.esm.json | 18 +- experimental/tsconfig.json | 23 +- 37 files changed, 122 insertions(+), 2996 deletions(-) delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts create mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/noop.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/transformMetrics.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/index-webpack.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/transformMetrics.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts create mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/noop.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts delete mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts create mode 100644 experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/noop.test.ts diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json index becd3e6ee1d..637ce37b785 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/package.json @@ -1,6 +1,7 @@ { "name": "@opentelemetry/exporter-metrics-otlp-grpc", "version": "0.26.0", + "private": true, "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector", "main": "build/src/index.js", "types": "build/src/index.d.ts", 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 18169928501..15d7c69c23d 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -14,66 +14,17 @@ * limitations under the License. */ -import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http' -import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { - OTLPExporterConfigNode, - OTLPExporterNodeBase, - ServiceClientType, - validateAndNormalizeUrl -} from '@opentelemetry/exporter-trace-otlp-grpc'; -import { baggageUtils, getEnv } from '@opentelemetry/core'; -import { Metadata } from '@grpc/grpc-js'; - -const DEFAULT_COLLECTOR_URL = 'localhost:4317'; +import { ExportResult } from '@opentelemetry/core'; +import { MetricExporter, MetricRecord } from '@opentelemetry/sdk-metrics-base'; /** * OTLP Metric Exporter for Node */ -export class OTLPMetricExporter - extends OTLPExporterNodeBase< - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest - > - implements MetricExporter { - // Converts time to nanoseconds - protected readonly _startTime = new Date().getTime() * 1000000; - - constructor(config: OTLPExporterConfigNode = {}) { - super(config); - const headers = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS); - this.metadata ||= new Metadata(); - for (const [k, v] of Object.entries(headers)) { - this.metadata.set(k, v) - } +export class OTLPMetricExporter implements MetricExporter { + export(metrics: MetricRecord[], resultCallback: (result: ExportResult) => void): void { + throw new Error('Method not implemented.'); } - - convert( - metrics: MetricRecord[] - ): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - return toOTLPExportMetricServiceRequest( - metrics, - this._startTime, - this - ); - } - - getDefaultUrl(config: OTLPExporterConfigNode): string { - return typeof config.url === 'string' - ? validateAndNormalizeUrl(config.url) - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT) - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT) - : DEFAULT_COLLECTOR_URL; - } - - getServiceClientType(): ServiceClientType { - return ServiceClientType.METRICS; - } - - getServiceProtoPath(): string { - return 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; + shutdown(): Promise { + throw new Error('Method not implemented.'); } -} +} \ No newline at end of file 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 deleted file mode 100644 index 569bd2e500d..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts +++ /dev/null @@ -1,304 +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 * as protoLoader from '@grpc/proto-loader'; -import { - Counter, - ObservableGauge, - Histogram, -} from '@opentelemetry/api-metrics'; -import { diag } from '@opentelemetry/api'; -import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import * as metrics from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import * as fs from 'fs'; -import * as grpc from '@grpc/grpc-js'; -import * as path from 'path'; -import * as sinon from 'sinon'; -import { OTLPMetricExporter } from '../src'; -import { - ensureExportedCounterIsCorrect, - ensureExportedObservableGaugeIsCorrect, - ensureExportedHistogramIsCorrect, - ensureMetadataIsCorrect, - ensureResourceIsCorrect, - mockCounter, - mockObservableGauge, - mockHistogram, -} from './metricsHelper'; - -const metricsServiceProtoPath = - 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; -const includeDirs = [path.resolve(__dirname, '../protos')]; - -const address = 'localhost:1501'; - -type TestParams = { - useTLS?: boolean; - metadata?: grpc.Metadata; -}; - -const metadata = new grpc.Metadata(); -metadata.set('k', 'v'); - -const testOTLPMetricExporter = (params: TestParams) => - describe(`OTLPMetricExporter - node ${ - params.useTLS ? 'with' : 'without' - } TLS, ${params.metadata ? 'with' : 'without'} metadata`, () => { - let collectorExporter: OTLPMetricExporter; - let server: grpc.Server; - let exportedData: - | otlpTypes.opentelemetryProto.metrics.v1.ResourceMetrics[] - | undefined; - let metrics: metrics.MetricRecord[]; - let reqMetadata: grpc.Metadata | undefined; - - before(done => { - server = new grpc.Server(); - protoLoader - .load(metricsServiceProtoPath, { - keepCase: false, - longs: String, - enums: String, - defaults: true, - oneofs: true, - includeDirs, - }) - .then((packageDefinition: protoLoader.PackageDefinition) => { - const packageObject: any = grpc.loadPackageDefinition( - packageDefinition - ); - server.addService( - packageObject.opentelemetry.proto.collector.metrics.v1 - .MetricsService.service, - { - Export: (data: { - request: otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest; - metadata: grpc.Metadata; - }) => { - try { - exportedData = data.request.resourceMetrics; - reqMetadata = data.metadata; - } catch (e) { - exportedData = undefined; - } - }, - } - ); - const credentials = params.useTLS - ? grpc.ServerCredentials.createSsl( - fs.readFileSync('./test/certs/ca.crt'), - [ - { - cert_chain: fs.readFileSync('./test/certs/server.crt'), - private_key: fs.readFileSync('./test/certs/server.key'), - }, - ] - ) - : grpc.ServerCredentials.createInsecure(); - server.bindAsync(address, credentials, () => { - server.start(); - done(); - }); - }); - }); - - after(() => { - server.forceShutdown(); - }); - - beforeEach(async () => { - const credentials = params.useTLS - ? grpc.credentials.createSsl( - fs.readFileSync('./test/certs/ca.crt'), - fs.readFileSync('./test/certs/client.key'), - fs.readFileSync('./test/certs/client.crt') - ) - : undefined; - collectorExporter = new OTLPMetricExporter({ - url: 'grpcs://' + address, - credentials, - metadata: params.metadata, - }); - // Overwrites the start time to make tests consistent - Object.defineProperty(collectorExporter, '_startTime', { - value: 1592602232694000000, - }); - metrics = []; - const counter: metrics.Metric & - Counter = mockCounter(); - const observableGauge: metrics.Metric & - ObservableGauge = mockObservableGauge(observableResult => { - observableResult.observe(3, {}); - observableResult.observe(6, {}); - }); - const histogram: metrics.Metric & - Histogram = mockHistogram(); - - counter.add(1); - histogram.record(7); - histogram.record(14); - - metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observableGauge.getMetricRecord())[0]); - metrics.push((await histogram.getMetricRecord())[0]); - }); - - afterEach(() => { - exportedData = undefined; - reqMetadata = undefined; - sinon.restore(); - }); - - describe('instance', () => { - it('should warn about headers', () => { - // Need to stub/spy on the underlying logger as the 'diag' instance is global - const spyLoggerWarn = sinon.stub(diag, 'warn'); - collectorExporter = new OTLPMetricExporter({ - url: `http://${address}`, - headers: { - foo: 'bar', - }, - }); - const args = spyLoggerWarn.args[0]; - assert.strictEqual(args[0], 'Headers cannot be set when using grpc'); - }); - it('should warn about path in url', () => { - const spyLoggerWarn = sinon.stub(diag, 'warn'); - collectorExporter = new OTLPMetricExporter({ - url: `http://${address}/v1/metrics` - }); - const args = spyLoggerWarn.args[0]; - assert.strictEqual( - args[0], - 'URL path should not be set when using grpc, the path part of the URL will be ignored.' - ); - }); - }); - - describe('export', () => { - it('should export metrics', done => { - const responseSpy = sinon.spy(); - collectorExporter.export(metrics, responseSpy); - setTimeout(() => { - assert.ok( - typeof exportedData !== 'undefined', - 'resource' + " doesn't exist" - ); - let resource; - if (exportedData) { - resource = exportedData[0].resource; - const counter = - exportedData[0].instrumentationLibraryMetrics[0].metrics[0]; - const observableGauge = - exportedData[0].instrumentationLibraryMetrics[0].metrics[1]; - const histogram = - exportedData[0].instrumentationLibraryMetrics[0].metrics[2]; - ensureExportedCounterIsCorrect( - counter, - counter.intSum?.dataPoints[0].timeUnixNano - ); - ensureExportedObservableGaugeIsCorrect( - observableGauge, - observableGauge.doubleGauge?.dataPoints[0].timeUnixNano - ); - ensureExportedHistogramIsCorrect( - histogram, - histogram.intHistogram?.dataPoints[0].timeUnixNano, - [0, 100], - ['0', '2', '0'] - ); - assert.ok( - typeof resource !== 'undefined', - "resource doesn't exist" - ); - if (resource) { - ensureResourceIsCorrect(resource); - } - } - if (params.metadata && reqMetadata) { - ensureMetadataIsCorrect(reqMetadata, params.metadata); - } - done(); - }, 500); - }); - }); - }); - -describe('OTLPMetricExporter - node (getDefaultUrl)', () => { - it('should default to localhost', done => { - const collectorExporter = new OTLPMetricExporter({}); - setTimeout(() => { - assert.strictEqual(collectorExporter['url'], 'localhost:4317'); - done(); - }); - }); - it('should keep the URL if included', done => { - const url = 'http://foo.bar.com'; - const collectorExporter = new OTLPMetricExporter({ url }); - setTimeout(() => { - assert.strictEqual(collectorExporter['url'], 'foo.bar.com'); - done(); - }); - }); -}); - -describe('when configuring via environment', () => { - const envSource = process.env; - it('should use url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - 'foo.bar' - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should override global exporter url with signal url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - 'foo.metrics' - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; - }); - it('should use headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['bar']); - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - it('should override global headers config with signal headers defined via env', () => { - const metadata = new grpc.Metadata(); - metadata.set('foo', 'bar'); - metadata.set('goo', 'lol'); - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=jar,bar=foo'; - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPMetricExporter({ metadata }); - assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['boo']); - assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['foo']); - assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['lol']); - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = ''; - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); -}); - -testOTLPMetricExporter({ useTLS: true }); -testOTLPMetricExporter({ useTLS: false }); -testOTLPMetricExporter({ metadata }); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/noop.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/noop.test.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json index 948abef3ceb..64ff561763b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json @@ -11,6 +11,15 @@ "references": [ { "path": "../opentelemetry-api-metrics" + }, + { + "path": "../opentelemetry-exporter-metrics-otlp-http" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-grpc" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-http" } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json index e1979a7a8fd..37e471a166b 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/package.json @@ -1,6 +1,7 @@ { "name": "@opentelemetry/exporter-metrics-otlp-http", "version": "0.26.0", + "private": true, "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector", "main": "build/src/index.js", "module": "build/esm/index.js", 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 b19eb0070bd..90edcc5aa2a 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 @@ -14,53 +14,21 @@ * limitations under the License. */ -import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { OTLPExporterBrowserBase, otlpTypes, appendResourcePathToUrlIfNotPresent } from '@opentelemetry/exporter-trace-otlp-http'; -import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; -import { getEnv, baggageUtils } from '@opentelemetry/core'; +import { ExportResult } from '@opentelemetry/core'; +import { MetricExporter, MetricRecord } from '@opentelemetry/sdk-metrics-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; +// @ts-ignore unused for now const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Metric Exporter for Web */ -export class OTLPMetricExporter - extends OTLPExporterBrowserBase< - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest - > - implements MetricExporter { - // Converts time to nanoseconds - private readonly _startTime = new Date().getTime() * 1000000; - - constructor(config: otlpTypes.OTLPExporterConfigBase = {}) { - super(config); - this._headers = Object.assign( - this._headers, - baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ) - ); - } - - convert( - metrics: MetricRecord[] - ): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - return toOTLPExportMetricServiceRequest( - metrics, - this._startTime, - this - ); +export class OTLPMetricExporter implements MetricExporter { + export(metrics: MetricRecord[], resultCallback: (result: ExportResult) => void): void { + throw new Error('Method not implemented.'); } - - getDefaultUrl(config: otlpTypes.OTLPExporterConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + shutdown(): Promise { + throw new Error('Method not implemented.'); } } 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 05bf6af767e..ccd1197a0ed 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 @@ -14,58 +14,21 @@ * limitations under the License. */ -import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { - OTLPExporterNodeBase, - OTLPExporterNodeConfigBase, - otlpTypes, - appendResourcePathToUrlIfNotPresent -} from '@opentelemetry/exporter-trace-otlp-http'; -import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; -import { getEnv, baggageUtils } from '@opentelemetry/core'; +import { ExportResult } from '@opentelemetry/core'; +import { MetricExporter, MetricRecord } from '@opentelemetry/sdk-metrics-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; +// @ts-ignore unused for now const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Metric Exporter for Node */ -export class OTLPMetricExporter - extends OTLPExporterNodeBase< - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest - > - implements MetricExporter { - // Converts time to nanoseconds - protected readonly _startTime = new Date().getTime() * 1000000; - - constructor(config: OTLPExporterNodeConfigBase = {}) { - super(config); - this.headers = Object.assign( - this.headers, - baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ) - ); - } - - convert( - metrics: MetricRecord[] - ): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - return toOTLPExportMetricServiceRequest( - metrics, - this._startTime, - this - ); +export class OTLPMetricExporter implements MetricExporter { + export(metrics: MetricRecord[], resultCallback: (result: ExportResult) => void): void { + throw new Error('Method not implemented.'); } - - getDefaultUrl(config: OTLPExporterNodeConfigBase): string { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; + shutdown(): Promise { + throw new Error('Method not implemented.'); } -} +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/transformMetrics.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/transformMetrics.ts deleted file mode 100644 index c7b9169563f..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/transformMetrics.ts +++ /dev/null @@ -1,259 +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 { SpanAttributes, HrTime } from '@opentelemetry/api'; -import { Labels, ValueType } from '@opentelemetry/api-metrics'; -import * as core from '@opentelemetry/core'; -import { - AggregatorKind, - Histogram, - MetricKind, - MetricRecord, -} from '@opentelemetry/sdk-metrics-base'; -import { Resource } from '@opentelemetry/resources'; -import { OTLPExporterBase, otlpTypes, toCollectorResource } from '@opentelemetry/exporter-trace-otlp-http'; - -/** - * Converts labels - * @param labels - */ -export function toCollectorLabels( - labels: Labels -): otlpTypes.opentelemetryProto.common.v1.StringKeyValue[] { - return Object.entries(labels).map(([key, value]) => { - return { key, value: String(value) }; - }); -} - -/** - * Given a MetricDescriptor, return its temporality in a compatible format with the collector - * @param descriptor - */ -export function toAggregationTemporality( - metric: MetricRecord -): otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality { - if (metric.descriptor.metricKind === MetricKind.OBSERVABLE_GAUGE) { - return otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_UNSPECIFIED; - } - - return metric.aggregationTemporality; -} - -/** - * Returns an DataPoint which can have integers or doublle values - * @param metric - * @param startTime - */ -export function toDataPoint( - metric: MetricRecord, - startTime: number -): otlpTypes.opentelemetryProto.metrics.v1.DataPoint { - return { - labels: toCollectorLabels(metric.labels), - value: metric.aggregator.toPoint().value as number, - startTimeUnixNano: startTime, - timeUnixNano: core.hrTimeToNanoseconds( - metric.aggregator.toPoint().timestamp - ), - }; -} - -/** - * Returns a HistogramPoint to the collector - * @param metric - * @param startTime - */ -export function toHistogramPoint( - metric: MetricRecord, - startTime: number -): otlpTypes.opentelemetryProto.metrics.v1.HistogramDataPoint { - const { value, timestamp } = metric.aggregator.toPoint() as { - value: Histogram; - timestamp: HrTime; - }; - return { - labels: toCollectorLabels(metric.labels), - sum: value.sum, - count: value.count, - startTimeUnixNano: startTime, - timeUnixNano: core.hrTimeToNanoseconds(timestamp), - bucketCounts: value.buckets.counts, - explicitBounds: value.buckets.boundaries, - }; -} - -/** - * Converts a metric to be compatible with the collector - * @param metric - * @param startTime start time in nanoseconds - */ -export function toCollectorMetric( - metric: MetricRecord, - startTime: number -): otlpTypes.opentelemetryProto.metrics.v1.Metric { - const metricCollector: otlpTypes.opentelemetryProto.metrics.v1.Metric = { - name: metric.descriptor.name, - description: metric.descriptor.description, - unit: metric.descriptor.unit, - }; - - if ( - metric.aggregator.kind === AggregatorKind.SUM || - metric.descriptor.metricKind === MetricKind.OBSERVABLE_COUNTER || - metric.descriptor.metricKind === MetricKind.OBSERVABLE_UP_DOWN_COUNTER - ) { - const result = { - dataPoints: [toDataPoint(metric, startTime)], - isMonotonic: - metric.descriptor.metricKind === MetricKind.COUNTER || - metric.descriptor.metricKind === MetricKind.OBSERVABLE_COUNTER, - aggregationTemporality: toAggregationTemporality(metric), - }; - if (metric.descriptor.valueType === ValueType.INT) { - metricCollector.intSum = result; - } else { - metricCollector.doubleSum = result; - } - } else if (metric.aggregator.kind === AggregatorKind.LAST_VALUE) { - const result = { - dataPoints: [toDataPoint(metric, startTime)], - }; - if (metric.descriptor.valueType === ValueType.INT) { - metricCollector.intGauge = result; - } else { - metricCollector.doubleGauge = result; - } - } else if (metric.aggregator.kind === AggregatorKind.HISTOGRAM) { - const result = { - dataPoints: [toHistogramPoint(metric, startTime)], - aggregationTemporality: toAggregationTemporality(metric), - }; - if (metric.descriptor.valueType === ValueType.INT) { - metricCollector.intHistogram = result; - } else { - metricCollector.doubleHistogram = result; - } - } - - return metricCollector; -} - -/** - * Prepares metric service request to be sent to collector - * @param metrics metrics - * @param startTime start time of the metric in nanoseconds - * @param collectorMetricExporterBase - */ -export function toOTLPExportMetricServiceRequest< - T extends otlpTypes.OTLPExporterConfigBase ->( - metrics: MetricRecord[], - startTime: number, - collectorExporterBase: OTLPExporterBase< - T, - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest - > -): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - const groupedMetrics: Map< - Resource, - Map - > = groupMetricsByResourceAndLibrary(metrics); - const additionalAttributes = Object.assign( - {}, - collectorExporterBase.attributes - ); - return { - resourceMetrics: toCollectorResourceMetrics( - groupedMetrics, - additionalAttributes, - startTime - ), - }; -} - -/** - * Takes an array of metrics and groups them by resource and instrumentation - * library - * @param metrics metrics - */ -export function groupMetricsByResourceAndLibrary( - metrics: MetricRecord[] -): Map> { - return metrics.reduce((metricMap, metric) => { - //group by resource - let resourceMetrics = metricMap.get(metric.resource); - if (!resourceMetrics) { - resourceMetrics = new Map(); - metricMap.set(metric.resource, resourceMetrics); - } - //group by instrumentation library - let libMetrics = resourceMetrics.get(metric.instrumentationLibrary); - if (!libMetrics) { - libMetrics = new Array(); - resourceMetrics.set(metric.instrumentationLibrary, libMetrics); - } - libMetrics.push(metric); - return metricMap; - }, new Map>()); -} - -/** - * Convert to InstrumentationLibraryMetrics - * @param instrumentationLibrary - * @param metrics - * @param startTime - */ -function toCollectorInstrumentationLibraryMetrics( - instrumentationLibrary: core.InstrumentationLibrary, - metrics: MetricRecord[], - startTime: number -): otlpTypes.opentelemetryProto.metrics.v1.InstrumentationLibraryMetrics { - return { - metrics: metrics.map(metric => toCollectorMetric(metric, startTime)), - instrumentationLibrary, - }; -} - -/** - * Returns a list of resource metrics which will be exported to the collector - * @param groupedSpans - * @param baseAttributes - */ -function toCollectorResourceMetrics( - groupedMetrics: Map< - Resource, - Map - >, - baseAttributes: SpanAttributes, - startTime: number -): otlpTypes.opentelemetryProto.metrics.v1.ResourceMetrics[] { - return Array.from(groupedMetrics, ([resource, libMetrics]) => { - return { - resource: toCollectorResource(resource, baseAttributes), - instrumentationLibraryMetrics: Array.from( - libMetrics, - ([instrumentationLibrary, metrics]) => - toCollectorInstrumentationLibraryMetrics( - instrumentationLibrary, - metrics, - startTime - ) - ), - }; - }); -} 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 deleted file mode 100644 index ed311496919..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/CollectorMetricExporter.test.ts +++ /dev/null @@ -1,431 +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 { diag } from '@opentelemetry/api'; -import { - Counter, - ObservableGauge, - Histogram, -} from '@opentelemetry/api-metrics'; -import { ExportResultCode, hrTimeToNanoseconds } from '@opentelemetry/core'; -import { - BoundCounter, - BoundObservable, - BoundHistogram, - Metric, - MetricRecord, -} from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import { OTLPMetricExporter } from '../../src/platform/browser/index'; -import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import { - ensureCounterIsCorrect, - ensureExportMetricsServiceRequestIsSet, - ensureHeadersContain, - ensureObservableGaugeIsCorrect, - ensureHistogramIsCorrect, - ensureWebResourceIsCorrect, - mockCounter, - mockObservableGauge, - mockHistogram, -} from '../metricsHelper'; - -describe('OTLPMetricExporter - web', () => { - let collectorExporter: OTLPMetricExporter; - let stubOpen: sinon.SinonStub; - let stubBeacon: sinon.SinonStub; - let metrics: MetricRecord[]; - - beforeEach(async () => { - stubOpen = sinon.stub(XMLHttpRequest.prototype, 'open'); - sinon.stub(XMLHttpRequest.prototype, 'send'); - stubBeacon = sinon.stub(navigator, 'sendBeacon'); - metrics = []; - const counter: Metric & Counter = mockCounter(); - const observableGauge: Metric & ObservableGauge = mockObservableGauge( - observableResult => { - observableResult.observe(3, {}); - observableResult.observe(6, {}); - }, - 'double-observable-gauge2' - ); - const histogram: Metric & - Histogram = mockHistogram(); - counter.add(1); - histogram.record(7); - histogram.record(14); - - metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observableGauge.getMetricRecord())[0]); - metrics.push((await histogram.getMetricRecord())[0]); - }); - - afterEach(() => { - sinon.restore(); - }); - - describe('export', () => { - describe('when "sendBeacon" is available', () => { - beforeEach(() => { - collectorExporter = new OTLPMetricExporter({ - url: 'http://foo.bar.com', - }); - // Overwrites the start time to make tests consistent - Object.defineProperty(collectorExporter, '_startTime', { - value: 1592602232694000000, - }); - }); - it('should successfully send metrics using sendBeacon', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(async () => { - const args = stubBeacon.args[0]; - const url = args[0]; - const blob: Blob = args[1]; - const body = await blob.text(); - const json = JSON.parse( - body - ) as otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest; - const metric1 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[0]; - const metric2 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[1]; - const metric3 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[2]; - - assert.ok(typeof metric1 !== 'undefined', "metric doesn't exist"); - if (metric1) { - ensureCounterIsCorrect( - metric1, - hrTimeToNanoseconds(metrics[0].aggregator.toPoint().timestamp) - ); - } - - assert.ok( - typeof metric2 !== 'undefined', - "second metric doesn't exist" - ); - if (metric2) { - ensureObservableGaugeIsCorrect( - metric2, - hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), - 6, - 'double-observable-gauge2' - ); - } - - assert.ok( - typeof metric3 !== 'undefined', - "third metric doesn't exist" - ); - if (metric3) { - ensureHistogramIsCorrect( - metric3, - hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), - [0, 100], - [0, 2, 0] - ); - } - - const resource = json.resourceMetrics[0].resource; - assert.ok(typeof resource !== 'undefined', "resource doesn't exist"); - if (resource) { - ensureWebResourceIsCorrect(resource); - } - - assert.strictEqual(url, 'http://foo.bar.com'); - assert.strictEqual(stubBeacon.callCount, 1); - - assert.strictEqual(stubOpen.callCount, 0); - - ensureExportMetricsServiceRequestIsSet(json); - - done(); - }); - }); - - it('should log the successful message', done => { - // Need to stub/spy on the underlying logger as the "diag" instance is global - const spyLoggerDebug = sinon.stub(diag, 'debug'); - const spyLoggerError = sinon.stub(diag, 'error'); - stubBeacon.returns(true); - - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const response: any = spyLoggerDebug.args[1][0]; - assert.strictEqual(response, 'sendBeacon - can send'); - assert.strictEqual(spyLoggerError.args.length, 0); - - done(); - }); - }); - - it('should log the error message', done => { - stubBeacon.returns(false); - - collectorExporter.export(metrics, result => { - assert.deepStrictEqual(result.code, ExportResultCode.FAILED); - assert.ok(result.error?.message.includes('cannot send')); - done(); - }); - }); - }); - - describe('when "sendBeacon" is NOT available', () => { - let server: any; - beforeEach(() => { - (window.navigator as any).sendBeacon = false; - collectorExporter = new OTLPMetricExporter({ - url: 'http://foo.bar.com', - }); - // Overwrites the start time to make tests consistent - Object.defineProperty(collectorExporter, '_startTime', { - value: 1592602232694000000, - }); - server = sinon.fakeServer.create(); - }); - afterEach(() => { - server.restore(); - }); - - it('should successfully send the metrics using XMLHttpRequest', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const request = server.requests[0]; - assert.strictEqual(request.method, 'POST'); - assert.strictEqual(request.url, 'http://foo.bar.com'); - - const body = request.requestBody; - const json = JSON.parse( - body - ) as otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest; - const metric1 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[0]; - const metric2 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[1]; - const metric3 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[2]; - assert.ok(typeof metric1 !== 'undefined', "metric doesn't exist"); - if (metric1) { - ensureCounterIsCorrect( - metric1, - hrTimeToNanoseconds(metrics[0].aggregator.toPoint().timestamp) - ); - } - assert.ok( - typeof metric2 !== 'undefined', - "second metric doesn't exist" - ); - if (metric2) { - ensureObservableGaugeIsCorrect( - metric2, - hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), - 6, - 'double-observable-gauge2' - ); - } - - assert.ok( - typeof metric3 !== 'undefined', - "third metric doesn't exist" - ); - if (metric3) { - ensureHistogramIsCorrect( - metric3, - hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), - [0, 100], - [0, 2, 0] - ); - } - - const resource = json.resourceMetrics[0].resource; - assert.ok(typeof resource !== 'undefined', "resource doesn't exist"); - if (resource) { - ensureWebResourceIsCorrect(resource); - } - - assert.strictEqual(stubBeacon.callCount, 0); - ensureExportMetricsServiceRequestIsSet(json); - - done(); - }); - }); - - it('should log the successful message', done => { - // Need to stub/spy on the underlying logger as the "diag" instance is global - const spyLoggerDebug = sinon.stub(diag, 'debug'); - const spyLoggerError = sinon.stub(diag, 'error'); - - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const request = server.requests[0]; - request.respond(200); - - const response: any = spyLoggerDebug.args[1][0]; - assert.strictEqual(response, 'xhr success'); - assert.strictEqual(spyLoggerError.args.length, 0); - - assert.strictEqual(stubBeacon.callCount, 0); - done(); - }); - }); - - it('should log the error message', done => { - collectorExporter.export(metrics, result => { - assert.deepStrictEqual(result.code, ExportResultCode.FAILED); - assert.ok(result.error?.message.includes('Failed to export')); - assert.strictEqual(stubBeacon.callCount, 0); - done(); - }); - - setTimeout(() => { - const request = server.requests[0]; - request.respond(400); - }); - }); - it('should send custom headers', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const request = server.requests[0]; - request.respond(200); - - assert.strictEqual(stubBeacon.callCount, 0); - done(); - }); - }); - }); - }); - - describe('export with custom headers', () => { - let server: any; - const customHeaders = { - foo: 'bar', - bar: 'baz', - }; - let collectorExporterConfig: otlpTypes.OTLPExporterConfigBase; - - beforeEach(() => { - collectorExporterConfig = { - headers: customHeaders, - }; - server = sinon.fakeServer.create(); - }); - - afterEach(() => { - server.restore(); - }); - - describe('when "sendBeacon" is available', () => { - beforeEach(() => { - collectorExporter = new OTLPMetricExporter( - collectorExporterConfig - ); - }); - it('should successfully send custom headers using XMLHTTPRequest', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const [{ requestHeaders }] = server.requests; - - ensureHeadersContain(requestHeaders, customHeaders); - assert.strictEqual(stubBeacon.callCount, 0); - assert.strictEqual(stubOpen.callCount, 0); - - done(); - }); - }); - }); - - describe('when "sendBeacon" is NOT available', () => { - beforeEach(() => { - (window.navigator as any).sendBeacon = false; - collectorExporter = new OTLPMetricExporter( - collectorExporterConfig - ); - }); - - it('should successfully send metrics using XMLHttpRequest', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const [{ requestHeaders }] = server.requests; - - ensureHeadersContain(requestHeaders, customHeaders); - assert.strictEqual(stubBeacon.callCount, 0); - assert.strictEqual(stubOpen.callCount, 0); - - done(); - }); - }); - }); - }); -}); - -describe('when configuring via environment', () => { - const envSource = window as any; - it('should use url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should use url defined in env and append version and signal when not present', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should override global exporter url with signal url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; - }); - it('should use headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPMetricExporter({ headers: {} }); - // @ts-expect-error access internal property for testing - assert.strictEqual(collectorExporter._headers.foo, 'bar'); - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - it('should override global headers config with signal headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPMetricExporter({ headers: {} }); - // @ts-expect-error access internal property for testing - assert.strictEqual(collectorExporter._headers.foo, 'boo'); - // @ts-expect-error access internal property for testing - assert.strictEqual(collectorExporter._headers.bar, 'foo'); - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = ''; - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); -}); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/index-webpack.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/index-webpack.ts deleted file mode 100644 index 99100a0f6ee..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/browser/index-webpack.ts +++ /dev/null @@ -1,23 +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. - */ -const testsContext = require.context('../browser', true, /test$/); -testsContext.keys().forEach(testsContext); - -const testsContextCommon = require.context('../common', true, /test$/); -testsContextCommon.keys().forEach(testsContextCommon); - -const srcContext = require.context('.', true, /src$/); -srcContext.keys().forEach(srcContext); 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 deleted file mode 100644 index 91b678d2a21..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/CollectorMetricExporter.test.ts +++ /dev/null @@ -1,198 +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 { Counter, ObservableGauge } from '@opentelemetry/api-metrics'; -import { ExportResultCode } from '@opentelemetry/core'; -import { - BoundCounter, - BoundObservable, - Metric, - MetricRecord, -} from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import { OTLPExporterBase, otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import { mockCounter, mockObservableGauge } from '../metricsHelper'; - -type CollectorExporterConfig = otlpTypes.OTLPExporterConfigBase; -class OTLPMetricExporter extends OTLPExporterBase< - CollectorExporterConfig, - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest -> { - onInit() {} - onShutdown() {} - send() {} - getDefaultUrl(config: CollectorExporterConfig) { - return config.url || ''; - } - convert( - metrics: MetricRecord[] - ): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - return { resourceMetrics: [] }; - } -} - -describe('OTLPMetricExporter - common', () => { - let collectorExporter: OTLPMetricExporter; - let collectorExporterConfig: CollectorExporterConfig; - let metrics: MetricRecord[]; - - afterEach(() => { - sinon.restore(); - }); - - describe('constructor', () => { - let onInitSpy: any; - - beforeEach(async () => { - onInitSpy = sinon.stub(OTLPMetricExporter.prototype, 'onInit'); - collectorExporterConfig = { - hostname: 'foo', - attributes: {}, - url: 'http://foo.bar.com', - }; - collectorExporter = new OTLPMetricExporter(collectorExporterConfig); - metrics = []; - const counter: Metric & Counter = mockCounter(); - const observableGauge: Metric & ObservableGauge = mockObservableGauge( - observableResult => { - observableResult.observe(3, {}); - observableResult.observe(6, {}); - }, - 'double-observable-gauge3' - ); - counter.add(1); - - metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observableGauge.getMetricRecord())[0]); - }); - - it('should create an instance', () => { - assert.ok(typeof collectorExporter !== 'undefined'); - }); - - it('should call onInit', () => { - assert.strictEqual(onInitSpy.callCount, 1); - }); - - describe('when config contains certain params', () => { - it('should set hostname', () => { - assert.strictEqual(collectorExporter.hostname, 'foo'); - }); - - it('should set url', () => { - assert.strictEqual(collectorExporter.url, 'http://foo.bar.com'); - }); - }); - - describe('when config is missing certain params', () => { - beforeEach(() => { - collectorExporter = new OTLPMetricExporter(); - }); - }); - }); - - describe('export', () => { - let spySend: any; - beforeEach(() => { - spySend = sinon.stub(OTLPMetricExporter.prototype, 'send'); - collectorExporter = new OTLPMetricExporter(collectorExporterConfig); - }); - - it('should export metrics as otlpTypes.Metrics', done => { - collectorExporter.export(metrics, () => {}); - setTimeout(() => { - const metric1 = spySend.args[0][0][0] as MetricRecord; - assert.deepStrictEqual(metrics[0], metric1); - const metric2 = spySend.args[0][0][1] as MetricRecord; - assert.deepStrictEqual(metrics[1], metric2); - done(); - }); - assert.strictEqual(spySend.callCount, 1); - }); - - describe('when exporter is shutdown', () => { - it( - 'should not export anything but return callback with code' + - ' "FailedNotRetryable"', - async () => { - await collectorExporter.shutdown(); - spySend.resetHistory(); - - const callbackSpy = sinon.spy(); - collectorExporter.export(metrics, callbackSpy); - const returnCode = callbackSpy.args[0][0]; - assert.strictEqual( - returnCode.code, - ExportResultCode.FAILED, - 'return value is wrong' - ); - assert.strictEqual(spySend.callCount, 0, 'should not call send'); - } - ); - }); - describe('when an error occurs', () => { - it('should return failed export result', done => { - spySend.throws({ - code: 600, - details: 'Test error', - metadata: {}, - message: 'Non-Retryable', - stack: 'Stack', - }); - const callbackSpy = sinon.spy(); - collectorExporter.export(metrics, callbackSpy); - setTimeout(() => { - const returnCode = callbackSpy.args[0][0]; - assert.strictEqual( - returnCode.code, - ExportResultCode.FAILED, - 'return value is wrong' - ); - assert.strictEqual( - returnCode.error.message, - 'Non-Retryable', - 'return error message is wrong' - ); - assert.strictEqual(spySend.callCount, 1, 'should call send'); - done(); - }); - }); - }); - }); - - describe('shutdown', () => { - let onShutdownSpy: any; - beforeEach(() => { - onShutdownSpy = sinon.stub( - OTLPMetricExporter.prototype, - 'onShutdown' - ); - collectorExporterConfig = { - hostname: 'foo', - attributes: {}, - url: 'http://foo.bar.com', - }; - collectorExporter = new OTLPMetricExporter(collectorExporterConfig); - }); - - it('should call onShutdown', async () => { - await collectorExporter.shutdown(); - assert.strictEqual(onShutdownSpy.callCount, 1); - }); - }); -}); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/transformMetrics.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/transformMetrics.test.ts deleted file mode 100644 index b14e1b96d5c..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/common/transformMetrics.test.ts +++ /dev/null @@ -1,233 +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 { - Counter, - ObservableCounter, - ObservableUpDownCounter, - ObservableGauge, - Histogram, -} from '@opentelemetry/api-metrics'; -import { hrTimeToNanoseconds } from '@opentelemetry/core'; -import { - BoundCounter, - BoundObservable, - BoundHistogram, - Metric, - SumAggregator, -} from '@opentelemetry/sdk-metrics-base'; -import { Resource } from '@opentelemetry/resources'; -import * as assert from 'assert'; -import * as transform from '../../src/transformMetrics'; -import { - ensureCounterIsCorrect, - ensureDoubleCounterIsCorrect, - ensureObservableGaugeIsCorrect, - ensureObservableCounterIsCorrect, - ensureObservableUpDownCounterIsCorrect, - ensureHistogramIsCorrect, - mockCounter, - mockDoubleCounter, - mockedInstrumentationLibraries, - mockedResources, - mockObservableGauge, - mockObservableCounter, - mockObservableUpDownCounter, - mockHistogram, - multiInstrumentationLibraryMetricsGet, - multiResourceMetricsGet, -} from '../metricsHelper'; - -describe('transformMetrics', () => { - describe('toCollectorMetric', async () => { - let counter: Metric & Counter; - let doubleCounter: Metric & Counter; - let observableGauge: Metric & ObservableGauge; - let observableCounter: Metric & ObservableCounter; - let observableUpDownCounter: Metric & ObservableUpDownCounter; - let histogram: Metric & Histogram; - beforeEach(() => { - counter = mockCounter(); - doubleCounter = mockDoubleCounter(); - let count1 = 0; - let count2 = 0; - let count3 = 0; - - function getValue(count: number) { - if (count % 2 === 0) { - return 3; - } - return -1; - } - - observableGauge = mockObservableGauge(observableResult => { - count1++; - observableResult.observe(getValue(count1), {}); - }); - - observableCounter = mockObservableCounter(observableResult => { - count2++; - observableResult.observe(getValue(count2), {}); - }); - - observableUpDownCounter = mockObservableUpDownCounter(observableResult => { - count3++; - observableResult.observe(getValue(count3), {}); - }); - - histogram = mockHistogram(); - - // Counter - counter.add(1); - - // Double Counter - doubleCounter.add(8); - - // Histogram - histogram.record(7); - histogram.record(14); - }); - - it('should convert metric', async () => { - const counterMetric = (await counter.getMetricRecord())[0]; - ensureCounterIsCorrect( - transform.toCollectorMetric(counterMetric, 1592602232694000000), - hrTimeToNanoseconds(await counterMetric.aggregator.toPoint().timestamp) - ); - - const doubleCounterMetric = (await doubleCounter.getMetricRecord())[0]; - ensureDoubleCounterIsCorrect( - transform.toCollectorMetric(doubleCounterMetric, 1592602232694000000), - hrTimeToNanoseconds(doubleCounterMetric.aggregator.toPoint().timestamp) - ); - - await observableGauge.getMetricRecord(); - await observableGauge.getMetricRecord(); - const observableGaugeMetric = (await observableGauge.getMetricRecord())[0]; - ensureObservableGaugeIsCorrect( - transform.toCollectorMetric(observableGaugeMetric, 1592602232694000000), - hrTimeToNanoseconds(observableGaugeMetric.aggregator.toPoint().timestamp), - -1 - ); - - // collect 3 times - await observableCounter.getMetricRecord(); - await observableCounter.getMetricRecord(); - const observableCounterMetric = (await observableCounter.getMetricRecord())[0]; - ensureObservableCounterIsCorrect( - transform.toCollectorMetric(observableCounterMetric, 1592602232694000000), - hrTimeToNanoseconds(observableCounterMetric.aggregator.toPoint().timestamp), - 3 - ); - - // collect 3 times - await observableUpDownCounter.getMetricRecord(); - await observableUpDownCounter.getMetricRecord(); - const observableUpDownCounterMetric = ( - await observableUpDownCounter.getMetricRecord() - )[0]; - ensureObservableUpDownCounterIsCorrect( - transform.toCollectorMetric( - observableUpDownCounterMetric, - 1592602232694000000 - ), - hrTimeToNanoseconds( - observableUpDownCounterMetric.aggregator.toPoint().timestamp - ), - -1 - ); - - const histogramMetric = (await histogram.getMetricRecord())[0]; - ensureHistogramIsCorrect( - transform.toCollectorMetric(histogramMetric, 1592602232694000000), - hrTimeToNanoseconds(histogramMetric.aggregator.toPoint().timestamp), - [0, 100], - [0, 2, 0] - ); - }); - - it('should convert metric labels value to string', () => { - const metric = transform.toCollectorMetric( - { - descriptor: { - name: 'name', - description: 'description', - unit: 'unit', - metricKind: 0, - valueType: 0, - }, - labels: { foo: (1 as unknown) as string }, - aggregator: new SumAggregator(), - resource: new Resource({}), - aggregationTemporality: 0, - instrumentationLibrary: { name: 'x', version: 'y' }, - }, - 1592602232694000000 - ); - const collectorMetric = metric.intSum?.dataPoints[0]; - assert.strictEqual(collectorMetric?.labels[0].value, '1'); - }); - }); - - describe('groupMetricsByResourceAndLibrary', () => { - it('should group by resource', async () => { - const [resource1, resource2] = mockedResources; - const [library] = mockedInstrumentationLibraries; - const [metric1, metric2, metric3] = multiResourceMetricsGet( - observableResult => { - observableResult.observe(1, {}); - } - ); - - const expected = new Map([ - [resource1, new Map([[library, [metric1, metric3]]])], - [resource2, new Map([[library, [metric2]]])], - ]); - - const result = transform.groupMetricsByResourceAndLibrary( - multiResourceMetricsGet(observableResult => { - observableResult.observe(1, {}); - }) - ); - - assert.deepStrictEqual(result, expected); - }); - - it('should group by instrumentation library', async () => { - const [resource] = mockedResources; - const [lib1, lib2] = mockedInstrumentationLibraries; - const [ - metric1, - metric2, - metric3, - ] = multiInstrumentationLibraryMetricsGet(observableResult => {}); - const expected = new Map([ - [ - resource, - new Map([ - [lib1, [metric1, metric3]], - [lib2, [metric2]], - ]), - ], - ]); - - const result = transform.groupMetricsByResourceAndLibrary( - multiInstrumentationLibraryMetricsGet(observableResult => {}) - ); - - assert.deepStrictEqual(result, expected); - }); - }); -}); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts deleted file mode 100644 index 830be337f08..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/metricsHelper.ts +++ /dev/null @@ -1,448 +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 { - Counter, - ObservableResult, - ObservableCounter, - ObservableUpDownCounter, - ObservableGauge, - Histogram, - ValueType, -} from '@opentelemetry/api-metrics'; -import { InstrumentationLibrary, VERSION } from '@opentelemetry/core'; -import * as metrics from '@opentelemetry/sdk-metrics-base'; -import { Resource } from '@opentelemetry/resources'; -import * as assert from 'assert'; -import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; - -const meterProvider = new metrics.MeterProvider({ - interval: 30000, - resource: new Resource({ - service: 'ui', - version: 1, - cost: 112.12, - }), -}); - -const meter = meterProvider.getMeter('default', '0.0.1'); - -if (typeof Buffer === 'undefined') { - (window as any).Buffer = { - from: function (arr: []) { - return new Uint8Array(arr); - }, - }; -} - -export function mockCounter(): metrics.Metric & Counter { - const name = 'int-counter'; - const metric = - meter['_metrics'].get(name) || - meter.createCounter(name, { - description: 'sample counter description', - valueType: ValueType.INT, - }); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockDoubleCounter(): metrics.Metric & - Counter { - const name = 'double-counter'; - const metric = - meter['_metrics'].get(name) || - meter.createCounter(name, { - description: 'sample counter description', - valueType: ValueType.DOUBLE, - }); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockObservableGauge( - callback: (observableResult: ObservableResult) => unknown, - name = 'double-observable-gauge' -): metrics.Metric & ObservableGauge { - const metric = - meter['_metrics'].get(name) || - meter.createObservableGauge( - name, - { - description: 'sample observable gauge description', - valueType: ValueType.DOUBLE, - }, - callback - ); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockObservableCounter( - callback: (observableResult: ObservableResult) => unknown, - name = 'double-observable-counter' -): metrics.Metric & ObservableCounter { - const metric = - meter['_metrics'].get(name) || - meter.createObservableCounter( - name, - { - description: 'sample observable counter description', - valueType: ValueType.DOUBLE, - }, - callback - ); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockObservableUpDownCounter( - callback: (observableResult: ObservableResult) => unknown, - name = 'double-up-down-observable-counter' -): metrics.Metric & ObservableUpDownCounter { - const metric = - meter['_metrics'].get(name) || - meter.createObservableUpDownCounter( - name, - { - description: 'sample observable up down counter description', - valueType: ValueType.DOUBLE, - }, - callback - ); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockHistogram(): metrics.Metric & - Histogram { - const name = 'int-histogram'; - const metric = - meter['_metrics'].get(name) || - meter.createHistogram(name, { - description: 'sample histogram description', - valueType: ValueType.INT, - boundaries: [0, 100], - }); - metric.clear(); - metric.bind({}); - return metric; -} - -export const mockedResources: Resource[] = [ - new Resource({ name: 'resource 1' }), - new Resource({ name: 'resource 2' }), -]; - -export const mockedInstrumentationLibraries: InstrumentationLibrary[] = [ - { - name: 'lib1', - version: '0.0.1', - }, - { - name: 'lib2', - version: '0.0.2', - }, -]; - -export const multiResourceMetricsGet = function ( - callback: (observableResult: ObservableResult) => unknown -): any[] { - return [ - { - ...mockCounter(), - resource: mockedResources[0], - instrumentationLibrary: mockedInstrumentationLibraries[0], - }, - { - ...mockObservableGauge(callback), - resource: mockedResources[1], - instrumentationLibrary: mockedInstrumentationLibraries[0], - }, - { - ...mockCounter(), - resource: mockedResources[0], - instrumentationLibrary: mockedInstrumentationLibraries[0], - }, - ]; -}; - -export const multiInstrumentationLibraryMetricsGet = function ( - callback: (observableResult: ObservableResult) => unknown -): any[] { - return [ - { - ...mockCounter(), - resource: mockedResources[0], - instrumentationLibrary: mockedInstrumentationLibraries[0], - }, - { - ...mockObservableGauge(callback), - resource: mockedResources[0], - instrumentationLibrary: mockedInstrumentationLibraries[1], - }, - { - ...mockCounter(), - resource: mockedResources[0], - instrumentationLibrary: mockedInstrumentationLibraries[0], - }, - ]; -}; - -export function ensureAttributesAreCorrect( - attributes: otlpTypes.opentelemetryProto.common.v1.KeyValue[] -) { - assert.deepStrictEqual( - attributes, - [ - { - key: 'component', - value: { - stringValue: 'document-load', - }, - }, - ], - 'attributes are incorrect' - ); -} - -export function ensureWebResourceIsCorrect( - resource: otlpTypes.opentelemetryProto.resource.v1.Resource -) { - assert.strictEqual(resource.attributes.length, 7); - assert.strictEqual(resource.attributes[0].key, 'service.name'); - assert.strictEqual(resource.attributes[0].value.stringValue, 'unknown_service'); - assert.strictEqual(resource.attributes[1].key, 'telemetry.sdk.language'); - assert.strictEqual(resource.attributes[1].value.stringValue, 'webjs'); - assert.strictEqual(resource.attributes[2].key, 'telemetry.sdk.name'); - assert.strictEqual(resource.attributes[2].value.stringValue, 'opentelemetry'); - assert.strictEqual(resource.attributes[3].key, 'telemetry.sdk.version'); - assert.strictEqual(resource.attributes[3].value.stringValue, VERSION); - assert.strictEqual(resource.attributes[4].key, 'service'); - assert.strictEqual(resource.attributes[4].value.stringValue, 'ui'); - assert.strictEqual(resource.attributes[5].key, 'version'); - assert.strictEqual(resource.attributes[5].value.intValue, 1); - assert.strictEqual(resource.attributes[6].key, 'cost'); - assert.strictEqual(resource.attributes[6].value.doubleValue, 112.12); - assert.strictEqual(resource.droppedAttributesCount, 0); -} - -export function ensureCounterIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number -) { - assert.deepStrictEqual(metric, { - name: 'int-counter', - description: 'sample counter description', - unit: '1', - intSum: { - dataPoints: [ - { - labels: [], - value: 1, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - }, - ], - isMonotonic: true, - aggregationTemporality: - otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_CUMULATIVE, - }, - }); -} - -export function ensureDoubleCounterIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number -) { - assert.deepStrictEqual(metric, { - name: 'double-counter', - description: 'sample counter description', - unit: '1', - doubleSum: { - dataPoints: [ - { - labels: [], - value: 8, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - }, - ], - isMonotonic: true, - aggregationTemporality: - otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_CUMULATIVE, - }, - }); -} - -export function ensureObservableGaugeIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number, - value: number, - name = 'double-observable-gauge' -) { - assert.deepStrictEqual(metric, { - name, - description: 'sample observable gauge description', - unit: '1', - doubleGauge: { - dataPoints: [ - { - labels: [], - value, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - }, - ], - }, - }); -} - -export function ensureObservableCounterIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number, - value: number, - name = 'double-observable-counter' -) { - assert.deepStrictEqual(metric, { - name, - description: 'sample observable counter description', - unit: '1', - doubleSum: { - isMonotonic: true, - dataPoints: [ - { - labels: [], - value, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - }, - ], - aggregationTemporality: - otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_CUMULATIVE, - }, - }); -} - -export function ensureObservableUpDownCounterIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number, - value: number, - name = 'double-up-down-observable-counter' -) { - assert.deepStrictEqual(metric, { - name, - description: 'sample observable up down counter description', - unit: '1', - doubleSum: { - isMonotonic: false, - dataPoints: [ - { - labels: [], - value, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - }, - ], - aggregationTemporality: - otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_CUMULATIVE, - }, - }); -} - -export function ensureHistogramIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time: number, - explicitBounds: (number | null)[] = [Infinity], - bucketCounts: number[] = [2, 0] -) { - assert.deepStrictEqual(metric, { - name: 'int-histogram', - description: 'sample histogram description', - unit: '1', - intHistogram: { - dataPoints: [ - { - labels: [], - sum: 21, - count: 2, - startTimeUnixNano: 1592602232694000000, - timeUnixNano: time, - bucketCounts, - explicitBounds, - }, - ], - aggregationTemporality: - otlpTypes.opentelemetryProto.metrics.v1.AggregationTemporality - .AGGREGATION_TEMPORALITY_CUMULATIVE, - }, - }); -} - -export function ensureExportMetricsServiceRequestIsSet( - json: otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest -) { - const resourceMetrics = json.resourceMetrics; - assert.strictEqual( - resourceMetrics.length, - 1, - 'resourceMetrics has incorrect length' - ); - - const resource = resourceMetrics[0].resource; - assert.strictEqual(!!resource, true, 'resource is missing'); - - const instrumentationLibraryMetrics = - resourceMetrics[0].instrumentationLibraryMetrics; - assert.strictEqual( - instrumentationLibraryMetrics && instrumentationLibraryMetrics.length, - 1, - 'instrumentationLibraryMetrics is missing' - ); - - const instrumentationLibrary = - instrumentationLibraryMetrics[0].instrumentationLibrary; - assert.strictEqual( - !!instrumentationLibrary, - true, - 'instrumentationLibrary is missing' - ); - - const metrics = resourceMetrics[0].instrumentationLibraryMetrics[0].metrics; - assert.strictEqual(metrics.length, 3, 'Metrics are missing'); -} - -export function ensureHeadersContain( - actual: { [key: string]: string }, - expected: { [key: string]: string } -) { - Object.entries(expected).forEach(([k, v]) => { - assert.strictEqual( - v, - actual[k], - `Expected ${actual} to contain ${k}: ${v}` - ); - }); -} 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 deleted file mode 100644 index f0beecd7955..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ /dev/null @@ -1,317 +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 { diag } from '@opentelemetry/api'; -import { - Counter, - ObservableGauge, - Histogram, -} from '@opentelemetry/api-metrics'; -import * as core from '@opentelemetry/core'; -import { - BoundCounter, - BoundObservable, - BoundHistogram, - Metric, - MetricRecord, -} from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import * as http from 'http'; -import * as sinon from 'sinon'; -import { - OTLPMetricExporter, -} from '../../src/platform/node'; -import { OTLPExporterNodeConfigBase, otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import { - ensureCounterIsCorrect, - ensureExportMetricsServiceRequestIsSet, - ensureObservableGaugeIsCorrect, - ensureHistogramIsCorrect, - mockCounter, - mockObservableGauge, - mockHistogram, -} from '../metricsHelper'; -import { MockedResponse } from './nodeHelpers'; - -const fakeRequest = { - end: function () {}, - on: function () {}, - write: function () {}, -}; - -const address = 'localhost:1501'; - -describe('OTLPMetricExporter - node with json over http', () => { - let collectorExporter: OTLPMetricExporter; - let collectorExporterConfig: OTLPExporterNodeConfigBase; - let stubRequest: sinon.SinonStub; - let stubWrite: sinon.SinonStub; - let metrics: MetricRecord[]; - - afterEach(() => { - sinon.restore(); - }); - - describe('instance', () => { - it('should warn about metadata when using json', () => { - const metadata = 'foo'; - // Need to stub/spy on the underlying logger as the "diag" instance is global - const spyLoggerWarn = sinon.stub(diag, 'warn'); - collectorExporter = new OTLPMetricExporter({ - url: address, - metadata, - } as any); - const args = spyLoggerWarn.args[0]; - assert.strictEqual(args[0], 'Metadata cannot be set when using http'); - }); - }); - - describe('when configuring via environment', () => { - const envSource = process.env; - it('should use url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should use url defined in env and append version and signal when not present', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should override global exporter url with signal url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; - }); - it('should use headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual(collectorExporter.headers.foo, 'bar'); - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - it('should override global headers config with signal headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual(collectorExporter.headers.foo, 'boo'); - assert.strictEqual(collectorExporter.headers.bar, 'foo'); - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = ''; - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - }); - - describe('export', () => { - beforeEach(async () => { - stubRequest = sinon.stub(http, 'request').returns(fakeRequest as any); - stubWrite = sinon.stub(fakeRequest, 'write'); - collectorExporterConfig = { - headers: { - foo: 'bar', - }, - hostname: 'foo', - attributes: {}, - url: 'http://foo.bar.com', - keepAlive: true, - httpAgentOptions: { keepAliveMsecs: 2000 }, - }; - collectorExporter = new OTLPMetricExporter(collectorExporterConfig); - // Overwrites the start time to make tests consistent - Object.defineProperty(collectorExporter, '_startTime', { - value: 1592602232694000000, - }); - metrics = []; - const counter: Metric & Counter = mockCounter(); - const observableGauge: Metric & ObservableGauge = mockObservableGauge( - observableResult => { - observableResult.observe(6, {}); - }, - 'double-observable-gauge2' - ); - const histogram: Metric & - Histogram = mockHistogram(); - counter.add(1); - histogram.record(7); - histogram.record(14); - - metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observableGauge.getMetricRecord())[0]); - metrics.push((await histogram.getMetricRecord())[0]); - }); - - it('should open the connection', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const args = stubRequest.args[0]; - const options = args[0]; - - assert.strictEqual(options.hostname, 'foo.bar.com'); - assert.strictEqual(options.method, 'POST'); - assert.strictEqual(options.path, '/'); - done(); - }); - }); - - it('should set custom headers', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const args = stubRequest.args[0]; - const options = args[0]; - assert.strictEqual(options.headers['foo'], 'bar'); - done(); - }); - }); - - it('should have keep alive and keepAliveMsecs option set', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const args = stubRequest.args[0]; - const options = args[0]; - const agent = options.agent; - assert.strictEqual(agent.keepAlive, true); - assert.strictEqual(agent.options.keepAliveMsecs, 2000); - done(); - }); - }); - - it('should successfully send metrics', done => { - collectorExporter.export(metrics, () => {}); - - setTimeout(() => { - const writeArgs = stubWrite.args[0]; - const json = JSON.parse( - writeArgs[0] - ) as otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest; - const metric1 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[0]; - const metric2 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[1]; - const metric3 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[2]; - - assert.ok(typeof metric1 !== 'undefined', "counter doesn't exist"); - ensureCounterIsCorrect( - metric1, - core.hrTimeToNanoseconds(metrics[0].aggregator.toPoint().timestamp) - ); - assert.ok(typeof metric2 !== 'undefined', "observable gauge doesn't exist"); - ensureObservableGaugeIsCorrect( - metric2, - core.hrTimeToNanoseconds(metrics[1].aggregator.toPoint().timestamp), - 6, - 'double-observable-gauge2' - ); - assert.ok(typeof metric3 !== 'undefined', "histogram doesn't exist"); - ensureHistogramIsCorrect( - metric3, - core.hrTimeToNanoseconds(metrics[2].aggregator.toPoint().timestamp), - [0, 100], - [0, 2, 0] - ); - - ensureExportMetricsServiceRequestIsSet(json); - - done(); - }); - }); - - it('should log the successful message', done => { - // Need to stub/spy on the underlying logger as the "diag" instance is global - const stubLoggerError = sinon.stub(diag, 'error'); - - const responseSpy = sinon.spy(); - collectorExporter.export(metrics, responseSpy); - - setTimeout(() => { - const mockRes = new MockedResponse(200); - const args = stubRequest.args[0]; - const callback = args[1]; - callback(mockRes); - mockRes.send('success'); - setTimeout(() => { - assert.strictEqual(stubLoggerError.args.length, 0); - assert.strictEqual( - responseSpy.args[0][0].code, - core.ExportResultCode.SUCCESS - ); - done(); - }); - }); - }); - - it('should log the error message', done => { - const handler = core.loggingErrorHandler(); - core.setGlobalErrorHandler(handler); - - const responseSpy = sinon.spy(); - collectorExporter.export(metrics, responseSpy); - - setTimeout(() => { - const mockRes = new MockedResponse(400); - const args = stubRequest.args[0]; - const callback = args[1]; - callback(mockRes); - mockRes.send('failed'); - setTimeout(() => { - const result = responseSpy.args[0][0] as core.ExportResult; - assert.strictEqual(result.code, core.ExportResultCode.FAILED); - const error = result.error as otlpTypes.OTLPExporterError; - assert.ok(error !== undefined); - assert.strictEqual(error.code, 400); - assert.strictEqual(error.data, 'failed'); - done(); - }); - }); - }); - }); - describe('OTLPMetricExporter - node (getDefaultUrl)', () => { - it('should default to localhost', done => { - const collectorExporter = new OTLPMetricExporter(); - setTimeout(() => { - assert.strictEqual( - collectorExporter['url'], - 'http://localhost:55681/v1/metrics' - ); - done(); - }); - }); - - it('should keep the URL if included', done => { - const url = 'http://foo.bar.com'; - const collectorExporter = new OTLPMetricExporter({ url }); - setTimeout(() => { - assert.strictEqual(collectorExporter['url'], url); - done(); - }); - }); - }); -}); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts deleted file mode 100644 index 1219f2d976b..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/nodeHelpers.ts +++ /dev/null @@ -1,36 +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 { Stream } from 'stream'; - -export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { - super(); - } - - send(data: string) { - this.emit('data', data); - this.emit('end'); - } - - get statusCode() { - return this._code; - } - - get statusMessage() { - return this._msg; - } -} diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/noop.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/noop.test.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json index 379f547a469..063825713f5 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json @@ -7,5 +7,13 @@ }, "include": [ "src/**/*.ts" + ], + "references": [ + { + "path": "../opentelemetry-api-metrics/tsconfig.esm.json" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json" + } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json index ed9d0830bdd..d9595b8a987 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json @@ -7,5 +7,13 @@ "include": [ "src/**/*.ts", "test/**/*.ts" + ], + "references": [ + { + "path": "../opentelemetry-api-metrics" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-http" + } ] } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json index 80465ea0ec5..6b8103b7ce1 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json @@ -1,6 +1,7 @@ { "name": "@opentelemetry/exporter-metrics-otlp-proto", "version": "0.26.0", + "private": true, "description": "OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector using protobuf over HTTP", "main": "build/src/index.js", "types": "build/src/index.d.ts", 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 9bbbfa6c665..4443bb534f8 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -14,62 +14,21 @@ * limitations under the License. */ -import { - otlpTypes, - OTLPExporterNodeConfigBase, - appendResourcePathToUrlIfNotPresent, -} from '@opentelemetry/exporter-trace-otlp-http'; -import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'; -import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base'; -import { ServiceClientType, OTLPExporterNodeBase } from '@opentelemetry/exporter-trace-otlp-proto'; -import { getEnv, baggageUtils } from '@opentelemetry/core'; +import { ExportResult } from '@opentelemetry/core'; +import { MetricExporter, MetricRecord } from '@opentelemetry/sdk-metrics-base'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; +// @ts-ignore unused for now const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * OTLP Metric Exporter for Node with protobuf */ -export class OTLPMetricExporter - extends OTLPExporterNodeBase< - MetricRecord, - otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest - > - implements MetricExporter { - // Converts time to nanoseconds - protected readonly _startTime = new Date().getTime() * 1000000; - - constructor(config: OTLPExporterNodeConfigBase = {}) { - super(config); - this.headers = Object.assign( - this.headers, - baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ) - ); - } - - convert( - metrics: MetricRecord[] - ): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest { - return toOTLPExportMetricServiceRequest( - metrics, - this._startTime, - this - ); +export class OTLPMetricExporter implements MetricExporter { + export(metrics: MetricRecord[], resultCallback: (result: ExportResult) => void): void { + throw new Error('Method not implemented.'); } - - getDefaultUrl(config: OTLPExporterNodeConfigBase) { - return typeof config.url === 'string' - ? config.url - : getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0 - ? getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - : getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0 - ? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH) - : DEFAULT_COLLECTOR_URL; - } - - getServiceClientType() { - return ServiceClientType.METRICS; + shutdown(): Promise { + throw new Error('Method not implemented.'); } } 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 deleted file mode 100644 index 831b66780e3..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ /dev/null @@ -1,259 +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 { diag } from '@opentelemetry/api'; -import { - Counter, - ObservableGauge, - Histogram, -} from '@opentelemetry/api-metrics'; -import { ExportResultCode } from '@opentelemetry/core'; -import { - OTLPExporterNodeConfigBase, - otlpTypes, -} from '@opentelemetry/exporter-trace-otlp-http'; -import { getExportRequestProto } from '@opentelemetry/exporter-trace-otlp-proto'; -import * as metrics from '@opentelemetry/sdk-metrics-base'; -import * as assert from 'assert'; -import * as http from 'http'; -import * as sinon from 'sinon'; -import { OTLPMetricExporter } from '../src'; - -import { - ensureExportedCounterIsCorrect, - ensureExportedObservableGaugeIsCorrect, - ensureExportedHistogramIsCorrect, - ensureExportMetricsServiceRequestIsSet, - mockCounter, - MockedResponse, - mockObservableGauge, - mockHistogram, -} from './metricsHelper'; - -const fakeRequest = { - end: function () {}, - on: function () {}, - write: function () {}, -}; - -describe('OTLPMetricExporter - node with proto over http', () => { - let collectorExporter: OTLPMetricExporter; - let collectorExporterConfig: OTLPExporterNodeConfigBase; - let metrics: metrics.MetricRecord[]; - - describe('when configuring via environment', () => { - const envSource = process.env; - it('should use url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar/v1/metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should use url defined in env and append version and signal when not present', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - `${envSource.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics` - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - }); - it('should override global exporter url with signal url defined in env', () => { - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = 'http://foo.metrics'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual( - collectorExporter.url, - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - ); - envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; - envSource.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT = ''; - }); - it('should use headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual(collectorExporter.headers.foo, 'bar'); - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - it('should override global headers config with signal headers defined via env', () => { - envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPMetricExporter(); - assert.strictEqual(collectorExporter.headers.foo, 'boo'); - assert.strictEqual(collectorExporter.headers.bar, 'foo'); - envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = ''; - envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; - }); - }); - - describe('export', () => { - beforeEach(async () => { - collectorExporterConfig = { - headers: { - foo: 'bar', - }, - hostname: 'foo', - attributes: {}, - url: 'http://foo.bar.com', - keepAlive: true, - httpAgentOptions: { keepAliveMsecs: 2000 }, - }; - collectorExporter = new OTLPMetricExporter(collectorExporterConfig); - // Overwrites the start time to make tests consistent - Object.defineProperty(collectorExporter, '_startTime', { - value: 1592602232694000000, - }); - metrics = []; - const counter: metrics.Metric & - Counter = mockCounter(); - const observableGauge: metrics.Metric & - ObservableGauge = mockObservableGauge(observableResult => { - observableResult.observe(3, {}); - observableResult.observe(6, {}); - }); - const histogram: metrics.Metric & - Histogram = mockHistogram(); - - counter.add(1); - histogram.record(7); - histogram.record(14); - - metrics.push((await counter.getMetricRecord())[0]); - metrics.push((await observableGauge.getMetricRecord())[0]); - metrics.push((await histogram.getMetricRecord())[0]); - }); - afterEach(() => { - sinon.restore(); - }); - - it('should open the connection', done => { - collectorExporter.export(metrics, () => {}); - - sinon.stub(http, 'request').callsFake((options: any) => { - assert.strictEqual(options.hostname, 'foo.bar.com'); - assert.strictEqual(options.method, 'POST'); - assert.strictEqual(options.path, '/'); - done(); - return fakeRequest as any; - }); - }); - - it('should set custom headers', done => { - collectorExporter.export(metrics, () => {}); - - sinon.stub(http, 'request').callsFake((options: any) => { - assert.strictEqual(options.headers['foo'], 'bar'); - done(); - return fakeRequest as any; - }); - }); - - it('should have keep alive and keepAliveMsecs option set', done => { - collectorExporter.export(metrics, () => {}); - - sinon.stub(http, 'request').callsFake((options: any) => { - assert.strictEqual(options.agent.keepAlive, true); - assert.strictEqual(options.agent.options.keepAliveMsecs, 2000); - done(); - return fakeRequest as any; - }); - }); - - it('should successfully send metrics', done => { - collectorExporter.export(metrics, () => {}); - - sinon.stub(http, 'request').returns({ - end: () => {}, - on: () => {}, - write: (...writeArgs: any[]) => { - const ExportTraceServiceRequestProto = getExportRequestProto(); - const data = ExportTraceServiceRequestProto?.decode(writeArgs[0]); - const json = data?.toJSON() as otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest; - - const metric1 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[0]; - const metric2 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[1]; - const metric3 = - json.resourceMetrics[0].instrumentationLibraryMetrics[0].metrics[2]; - - assert.ok(typeof metric1 !== 'undefined', "counter doesn't exist"); - ensureExportedCounterIsCorrect( - metric1, - metric1.intSum?.dataPoints[0].timeUnixNano - ); - assert.ok(typeof metric2 !== 'undefined', "observable gauge doesn't exist"); - ensureExportedObservableGaugeIsCorrect( - metric2, - metric2.doubleGauge?.dataPoints[0].timeUnixNano - ); - assert.ok( - typeof metric3 !== 'undefined', - "value recorder doesn't exist" - ); - ensureExportedHistogramIsCorrect( - metric3, - metric3.intHistogram?.dataPoints[0].timeUnixNano, - [0, 100], - ['0', '2', '0'] - ); - - ensureExportMetricsServiceRequestIsSet(json); - - done(); - }, - } as any); - }); - - it('should log the successful message', done => { - // Need to stub/spy on the underlying logger as the "diag" instance is global - const spyLoggerError = sinon.stub(diag, 'error'); - - collectorExporter.export(metrics, result => { - assert.strictEqual(result.code, ExportResultCode.SUCCESS); - assert.strictEqual(spyLoggerError.args.length, 0); - done(); - }); - - sinon.stub(http, 'request').callsFake((options: any, cb: any) => { - const mockRes = new MockedResponse(200); - cb(mockRes); - mockRes.send('success'); - return fakeRequest as any; - }); - }); - - it('should log the error message', done => { - collectorExporter.export(metrics, result => { - assert.strictEqual(result.code, ExportResultCode.FAILED); - // @ts-expect-error verify error code - assert.strictEqual(result.error.code, 400); - done(); - }); - - sinon.stub(http, 'request').callsFake((options: any, cb: any) => { - const mockResError = new MockedResponse(400); - cb(mockResError); - mockResError.send('failed'); - - return fakeRequest as any; - }); - }); - }); -}); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts deleted file mode 100644 index b400f76a33e..00000000000 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/metricsHelper.ts +++ /dev/null @@ -1,223 +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 { - Counter, - ObservableResult, - ObservableGauge, - Histogram, - ValueType, -} from '@opentelemetry/api-metrics'; -import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http'; -import * as metrics from '@opentelemetry/sdk-metrics-base'; -import { Resource } from '@opentelemetry/resources'; -import * as assert from 'assert'; -import { Stream } from 'stream'; - -const meterProvider = new metrics.MeterProvider({ - interval: 30000, - resource: new Resource({ - service: 'ui', - version: 1, - cost: 112.12, - }), -}); - -const meter = meterProvider.getMeter('default', '0.0.1'); - -export function mockCounter(): metrics.Metric & Counter { - const name = 'int-counter'; - const metric = - meter['_metrics'].get(name) || - meter.createCounter(name, { - description: 'sample counter description', - valueType: ValueType.INT, - }); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockObservableGauge( - callback: (observableResult: ObservableResult) => void -): metrics.Metric & ObservableGauge { - const name = 'double-observable-gauge'; - const metric = - meter['_metrics'].get(name) || - meter.createObservableGauge( - name, - { - description: 'sample observable gauge description', - valueType: ValueType.DOUBLE, - }, - callback - ); - metric.clear(); - metric.bind({}); - return metric; -} - -export function mockHistogram(): metrics.Metric & - Histogram { - const name = 'int-histogram'; - const metric = - meter['_metrics'].get(name) || - meter.createHistogram(name, { - description: 'sample histogram description', - valueType: ValueType.INT, - boundaries: [0, 100], - }); - metric.clear(); - metric.bind({}); - return metric; -} - -export function ensureProtoAttributesAreCorrect( - attributes: otlpTypes.opentelemetryProto.common.v1.KeyValue[] -) { - assert.deepStrictEqual( - attributes, - [ - { - key: 'component', - value: { - stringValue: 'document-load', - }, - }, - ], - 'attributes are incorrect' - ); -} - -export function ensureExportedCounterIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time?: number -) { - assert.deepStrictEqual(metric, { - name: 'int-counter', - description: 'sample counter description', - unit: '1', - intSum: { - dataPoints: [ - { - value: '1', - startTimeUnixNano: '1592602232694000128', - timeUnixNano: String(time), - }, - ], - isMonotonic: true, - aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE', - }, - }); -} - -export function ensureExportedObservableGaugeIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time?: number -) { - assert.deepStrictEqual(metric, { - name: 'double-observable-gauge', - description: 'sample observable gauge description', - unit: '1', - doubleGauge: { - dataPoints: [ - { - value: 6, - startTimeUnixNano: '1592602232694000128', - timeUnixNano: String(time), - }, - ], - }, - }); -} - -export function ensureExportedHistogramIsCorrect( - metric: otlpTypes.opentelemetryProto.metrics.v1.Metric, - time?: number, - explicitBounds: number[] = [Infinity], - bucketCounts: string[] = ['2', '0'] -) { - assert.deepStrictEqual(metric, { - name: 'int-histogram', - description: 'sample histogram description', - unit: '1', - intHistogram: { - dataPoints: [ - { - sum: '21', - count: '2', - startTimeUnixNano: '1592602232694000128', - timeUnixNano: time, - bucketCounts, - explicitBounds, - }, - ], - aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE', - }, - }); -} - -export function ensureExportMetricsServiceRequestIsSet( - json: otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest -) { - const resourceMetrics = json.resourceMetrics; - assert.strictEqual( - resourceMetrics.length, - 1, - 'resourceMetrics has incorrect length' - ); - - const resource = resourceMetrics[0].resource; - assert.strictEqual(!!resource, true, 'resource is missing'); - - const instrumentationLibraryMetrics = - resourceMetrics[0].instrumentationLibraryMetrics; - assert.strictEqual( - instrumentationLibraryMetrics && instrumentationLibraryMetrics.length, - 1, - 'instrumentationLibraryMetrics is missing' - ); - - const instrumentationLibrary = - instrumentationLibraryMetrics[0].instrumentationLibrary; - assert.strictEqual( - !!instrumentationLibrary, - true, - 'instrumentationLibrary is missing' - ); - - const metrics = resourceMetrics[0].instrumentationLibraryMetrics[0].metrics; - assert.strictEqual(metrics.length, 3, 'Metrics are missing'); -} - -export class MockedResponse extends Stream { - constructor(private _code: number, private _msg?: string) { - super(); - } - - send(data: string) { - this.emit('data', data); - this.emit('end'); - } - - get statusCode() { - return this._code; - } - - get statusMessage() { - return this._msg; - } -} diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/noop.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/noop.test.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json index 03a463d6378..50c20b23e2e 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/tsconfig.json @@ -10,10 +10,16 @@ ], "references": [ { - "path": "../opentelemetry-sdk-metrics-base" + "path": "../opentelemetry-api-metrics" }, { "path": "../opentelemetry-exporter-metrics-otlp-http" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-http" + }, + { + "path": "../opentelemetry-exporter-trace-otlp-proto" } ] } diff --git a/experimental/packages/opentelemetry-exporter-prometheus/package.json b/experimental/packages/opentelemetry-exporter-prometheus/package.json index 777666c3db7..f103abbb0e1 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/package.json +++ b/experimental/packages/opentelemetry-exporter-prometheus/package.json @@ -1,6 +1,7 @@ { "name": "@opentelemetry/exporter-prometheus", "version": "0.26.0", + "private": true, "description": "OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index 35473b14a3d..0e0005b533a 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -106,7 +106,7 @@ function toPrometheusType( case AggregatorKind.SUM: if ( metricKind === MetricKind.COUNTER || - metricKind === MetricKind.OBSERVABLE_COUNTER + metricKind === MetricKind.SUM_OBSERVER ) { return 'counter'; } diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts index 3528df2c428..50837ecb025 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ObservableResult } from '@opentelemetry/api-metrics'; +import { ObserverResult } from '@opentelemetry/api-metrics'; import { CounterMetric, SumAggregator, @@ -284,12 +284,12 @@ describe('PrometheusExporter', () => { return 0.999; } - meter.createObservableGauge( + meter.createValueObserver( 'metric_observable_gauge', { description: 'a test description', }, - (observableResult: ObservableResult) => { + (observableResult: ObserverResult) => { observableResult.observe(getCpuUsage(), { pid: String(123), core: '1', @@ -475,12 +475,12 @@ describe('PrometheusExporter', () => { return 20; } - meter.createObservableCounter( + meter.createSumObserver( 'metric_observable_counter', { description: 'a test description', }, - (observableResult: ObservableResult) => { + (observableResult: ObserverResult) => { observableResult.observe(getValue(), { key1: 'labelValue1', }); @@ -515,12 +515,12 @@ describe('PrometheusExporter', () => { return 20; } - meter.createObservableUpDownCounter( + meter.createUpDownSumObserver( 'metric_observable_up_down_counter', { description: 'a test description', }, - (observableResult: ObservableResult) => { + (observableResult: ObserverResult) => { observableResult.observe(getValue(), { key1: 'labelValue1', }); @@ -551,7 +551,7 @@ describe('PrometheusExporter', () => { }); it('should export a Histogram as a summary', done => { - const histogram = meter.createHistogram('test_histogram', { + const histogram = meter.createValueRecorder('test_histogram', { description: 'a test description', }); diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 88a54223447..8c556124b67 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -19,9 +19,9 @@ import { LastValueAggregator, MeterProvider, CounterMetric, - HistogramMetric, + ValueRecorderMetric, UpDownCounterMetric, - ObservableGaugeMetric, + ValueObserverMetric, } from '@opentelemetry/sdk-metrics-base'; import { diag, DiagLogLevel } from '@opentelemetry/api'; import * as assert from 'assert'; @@ -99,13 +99,13 @@ describe('PrometheusSerializer', () => { const meter = new MeterProvider({ processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); - const observableGauge = meter.createObservableGauge( + const observableGauge = meter.createValueObserver( 'test', {}, observableResult => { observableResult.observe(1, labels); } - ) as ObservableGaugeMetric; + ) as ValueObserverMetric; await meter.collect(); const records = await observableGauge.getMetricRecord(); const record = records[0]; @@ -126,13 +126,13 @@ describe('PrometheusSerializer', () => { const meter = new MeterProvider({ processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); - const observableGauge = meter.createObservableGauge( + const observableGauge = meter.createValueObserver( 'test', {}, observableResult => { observableResult.observe(1, labels); } - ) as ObservableGaugeMetric; + ) as ValueObserverMetric; await meter.collect(); const records = await observableGauge.getMetricRecord(); const record = records[0]; @@ -153,9 +153,9 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const histogram = meter.createHistogram('test', { + const histogram = meter.createValueRecorder('test', { description: 'foobar', - }) as HistogramMetric; + }) as ValueRecorderMetric; histogram.record(5, labels); @@ -181,10 +181,10 @@ describe('PrometheusSerializer', () => { const serializer = new PrometheusSerializer(); const meter = new MeterProvider().getMeter('test'); - const histogram = meter.createHistogram('test', { + const histogram = meter.createValueRecorder('test', { description: 'foobar', boundaries: [1, 10, 100], - }) as HistogramMetric; + }) as ValueRecorderMetric; histogram.record(5, labels); const records = await histogram.getMetricRecord(); @@ -210,9 +210,9 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const histogram = meter.createHistogram('test', { + const histogram = meter.createValueRecorder('test', { description: 'foobar', - }) as HistogramMetric; + }) as ValueRecorderMetric; histogram.record(5, labels); const records = await histogram.getMetricRecord(); @@ -304,7 +304,7 @@ describe('PrometheusSerializer', () => { processor: new ExactProcessor(LastValueAggregator), }).getMeter('test'); const processor = new PrometheusLabelsBatcher(); - const observableGauge = meter.createObservableGauge( + const observableGauge = meter.createValueObserver( 'test', { description: 'foobar', @@ -312,7 +312,7 @@ describe('PrometheusSerializer', () => { observableResult => { observableResult.observe(1, labels); } - ) as ObservableGaugeMetric; + ) as ValueObserverMetric; await meter.collect(); const records = await observableGauge.getMetricRecord(); records.forEach(it => processor.process(it)); @@ -336,9 +336,9 @@ describe('PrometheusSerializer', () => { const processor = new ExactProcessor(HistogramAggregator, [1, 10, 100]); const meter = new MeterProvider({ processor }).getMeter('test'); - const histogram = meter.createHistogram('test', { + const histogram = meter.createValueRecorder('test', { description: 'foobar', - }) as HistogramMetric; + }) as ValueRecorderMetric; histogram.record(5, { val: '1' }); histogram.record(50, { val: '1' }); histogram.record(120, { val: '1' }); diff --git a/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json b/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json index 3c062d3feb2..948abef3ceb 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-prometheus/tsconfig.json @@ -11,9 +11,6 @@ "references": [ { "path": "../opentelemetry-api-metrics" - }, - { - "path": "../opentelemetry-sdk-metrics-base" } ] } diff --git a/experimental/packages/opentelemetry-exporter-trace-otlp-grpc/tsconfig.json b/experimental/packages/opentelemetry-exporter-trace-otlp-grpc/tsconfig.json index 13dc2e7744d..075a501621d 100644 --- a/experimental/packages/opentelemetry-exporter-trace-otlp-grpc/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-trace-otlp-grpc/tsconfig.json @@ -9,14 +9,8 @@ "test/**/*.ts" ], "references": [ - { - "path": "../opentelemetry-api-metrics" - }, { "path": "../opentelemetry-exporter-trace-otlp-http" - }, - { - "path": "../opentelemetry-sdk-metrics-base" } ] } diff --git a/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json b/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json index 7b09613481b..379f547a469 100644 --- a/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json @@ -7,13 +7,5 @@ }, "include": [ "src/**/*.ts" - ], - "references": [ - { - "path": "../opentelemetry-api-metrics/tsconfig.esm.json" - }, - { - "path": "../opentelemetry-sdk-metrics-base/tsconfig.esm.json" - } ] } diff --git a/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.json b/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.json index 3c062d3feb2..ed9d0830bdd 100644 --- a/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-trace-otlp-http/tsconfig.json @@ -7,13 +7,5 @@ "include": [ "src/**/*.ts", "test/**/*.ts" - ], - "references": [ - { - "path": "../opentelemetry-api-metrics" - }, - { - "path": "../opentelemetry-sdk-metrics-base" - } ] } diff --git a/experimental/packages/opentelemetry-exporter-trace-otlp-proto/tsconfig.json b/experimental/packages/opentelemetry-exporter-trace-otlp-proto/tsconfig.json index 13dc2e7744d..075a501621d 100644 --- a/experimental/packages/opentelemetry-exporter-trace-otlp-proto/tsconfig.json +++ b/experimental/packages/opentelemetry-exporter-trace-otlp-proto/tsconfig.json @@ -9,14 +9,8 @@ "test/**/*.ts" ], "references": [ - { - "path": "../opentelemetry-api-metrics" - }, { "path": "../opentelemetry-exporter-trace-otlp-http" - }, - { - "path": "../opentelemetry-sdk-metrics-base" } ] } diff --git a/experimental/packages/opentelemetry-sdk-node/tsconfig.json b/experimental/packages/opentelemetry-sdk-node/tsconfig.json index 36c71e90d8d..b0e33797f42 100644 --- a/experimental/packages/opentelemetry-sdk-node/tsconfig.json +++ b/experimental/packages/opentelemetry-sdk-node/tsconfig.json @@ -14,9 +14,6 @@ }, { "path": "../opentelemetry-instrumentation" - }, - { - "path": "../opentelemetry-sdk-metrics-base" } ] } diff --git a/experimental/tsconfig.esm.json b/experimental/tsconfig.esm.json index d2bedd4f38c..1325f4b2600 100644 --- a/experimental/tsconfig.esm.json +++ b/experimental/tsconfig.esm.json @@ -6,17 +6,26 @@ "path": "packages/opentelemetry-api-metrics/tsconfig.esm.json" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-grpc" + "path": "packages/opentelemetry-exporter-metrics-otlp-grpc" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json" + "path": "packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.esm.json" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-proto" + "path": "packages/opentelemetry-exporter-metrics-otlp-proto" }, { "path": "packages/opentelemetry-exporter-prometheus" }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-grpc" + }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-http/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-proto" + }, { "path": "packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json" }, @@ -32,6 +41,9 @@ { "path": "packages/opentelemetry-instrumentation/tsconfig.esm.json" }, + { + "path": "packages/opentelemetry-sdk-metrics-base-2/tsconfig.esm.json" + }, { "path": "packages/opentelemetry-sdk-metrics-base/tsconfig.esm.json" }, diff --git a/experimental/tsconfig.json b/experimental/tsconfig.json index 5a53c080f2b..ace9e1700b0 100644 --- a/experimental/tsconfig.json +++ b/experimental/tsconfig.json @@ -6,17 +6,26 @@ "path": "packages/opentelemetry-api-metrics" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-grpc" + "path": "packages/opentelemetry-exporter-metrics-otlp-grpc" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-http" + "path": "packages/opentelemetry-exporter-metrics-otlp-http" }, { - "path": "packages/opentelemetry-exporter-trace-otlp-proto" + "path": "packages/opentelemetry-exporter-metrics-otlp-proto" }, { "path": "packages/opentelemetry-exporter-prometheus" }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-grpc" + }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-http" + }, + { + "path": "packages/opentelemetry-exporter-trace-otlp-proto" + }, { "path": "packages/opentelemetry-instrumentation-fetch" }, @@ -33,13 +42,7 @@ "path": "packages/opentelemetry-instrumentation" }, { - "path": "packages/opentelemetry-exporter-metrics-otlp-http" - }, - { - "path": "packages/opentelemetry-exporter-metrics-otlp-grpc" - }, - { - "path": "packages/opentelemetry-exporter-metrics-otlp-proto" + "path": "packages/opentelemetry-sdk-metrics-base-2" }, { "path": "packages/opentelemetry-sdk-metrics-base"