From a96116db88c7c0a0d1185601942b379c6118bd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B2=92=E7=B2=92=E6=A9=99?= Date: Fri, 28 Apr 2023 16:25:32 +0800 Subject: [PATCH 1/3] deps: remove `rimraf` (#3769) --- experimental/packages/exporter-logs-otlp-grpc/package.json | 1 - .../packages/opentelemetry-shim-opencensus/package.json | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/experimental/packages/exporter-logs-otlp-grpc/package.json b/experimental/packages/exporter-logs-otlp-grpc/package.json index b484723791..661e8c7221 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/package.json +++ b/experimental/packages/exporter-logs-otlp-grpc/package.json @@ -61,7 +61,6 @@ "cpx": "1.5.0", "mocha": "10.0.0", "nyc": "15.1.0", - "rimraf": "4.1.2", "sinon": "15.0.0", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", diff --git a/experimental/packages/opentelemetry-shim-opencensus/package.json b/experimental/packages/opentelemetry-shim-opencensus/package.json index d9191233b4..8779173e9f 100644 --- a/experimental/packages/opentelemetry-shim-opencensus/package.json +++ b/experimental/packages/opentelemetry-shim-opencensus/package.json @@ -53,7 +53,6 @@ "codecov": "3.8.3", "mocha": "10.0.0", "nyc": "15.1.0", - "rimraf": "4.1.2", "ts-mocha": "10.0.0", "typescript": "4.4.4" }, @@ -69,4 +68,4 @@ }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-shim-opencensus", "sideEffects": false -} +} \ No newline at end of file From abfb1bb68e1ec8a183c01644ab9673cd6ac74841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B2=92=E7=B2=92=E6=A9=99?= Date: Fri, 28 Apr 2023 18:28:52 +0800 Subject: [PATCH 2/3] refactor(otlp-transformer): refine metrics transformer (#3770) --- experimental/CHANGELOG.md | 1 + .../otlp-transformer/src/metrics/internal.ts | 91 ++++++++++--------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 70a5620184..bf12e19402 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to experimental packages in this project will be documented * feat(otlp-transformer): support log records. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 * feat(otlp-grpc-exporter-base): support log records. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 * feat(exporter-logs-otlp-grpc): otlp-grpc exporter for logs. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 +* refactor(otlp-transformer): refine metric transformers. [#3770](https://github.com/open-telemetry/opentelemetry-js/pull/3770/) @llc1123 ### :bug: (Bug Fix) diff --git a/experimental/packages/otlp-transformer/src/metrics/internal.ts b/experimental/packages/otlp-transformer/src/metrics/internal.ts index 7ba7722b6a..b73696b0ab 100644 --- a/experimental/packages/otlp-transformer/src/metrics/internal.ts +++ b/experimental/packages/otlp-transformer/src/metrics/internal.ts @@ -44,24 +44,21 @@ export function toResourceMetrics( attributes: toAttributes(resourceMetrics.resource.attributes), droppedAttributesCount: 0, }, - schemaUrl: undefined, // TODO: Schema Url does not exist yet in the SDK. + schemaUrl: undefined, scopeMetrics: toScopeMetrics(resourceMetrics.scopeMetrics), }; } export function toScopeMetrics(scopeMetrics: ScopeMetrics[]): IScopeMetrics[] { return Array.from( - scopeMetrics.map(metrics => { - const scopeMetrics: IScopeMetrics = { - scope: { - name: metrics.scope.name, - version: metrics.scope.version, - }, - metrics: metrics.metrics.map(metricData => toMetric(metricData)), - schemaUrl: metrics.scope.schemaUrl, - }; - return scopeMetrics; - }) + scopeMetrics.map(metrics => ({ + scope: { + name: metrics.scope.name, + version: metrics.scope.version, + }, + metrics: metrics.metrics.map(metricData => toMetric(metricData)), + schemaUrl: metrics.scope.schemaUrl, + })) ); } @@ -76,27 +73,31 @@ export function toMetric(metricData: MetricData): IMetric { metricData.aggregationTemporality ); - if (metricData.dataPointType === DataPointType.SUM) { - out.sum = { - aggregationTemporality, - isMonotonic: metricData.isMonotonic, - dataPoints: toSingularDataPoints(metricData), - }; - } else if (metricData.dataPointType === DataPointType.GAUGE) { - // Instrument is a gauge. - out.gauge = { - dataPoints: toSingularDataPoints(metricData), - }; - } else if (metricData.dataPointType === DataPointType.HISTOGRAM) { - out.histogram = { - aggregationTemporality, - dataPoints: toHistogramDataPoints(metricData), - }; - } else if (metricData.dataPointType === DataPointType.EXPONENTIAL_HISTOGRAM) { - out.exponentialHistogram = { - aggregationTemporality, - dataPoints: toExponentialHistogramDataPoints(metricData), - }; + switch (metricData.dataPointType) { + case DataPointType.SUM: + out.sum = { + aggregationTemporality, + isMonotonic: metricData.isMonotonic, + dataPoints: toSingularDataPoints(metricData), + }; + break; + case DataPointType.GAUGE: + out.gauge = { + dataPoints: toSingularDataPoints(metricData), + }; + break; + case DataPointType.HISTOGRAM: + out.histogram = { + aggregationTemporality, + dataPoints: toHistogramDataPoints(metricData), + }; + break; + case DataPointType.EXPONENTIAL_HISTOGRAM: + out.exponentialHistogram = { + aggregationTemporality, + dataPoints: toExponentialHistogramDataPoints(metricData), + }; + break; } return out; @@ -115,10 +116,13 @@ function toSingularDataPoint( timeUnixNano: hrTimeToNanoseconds(dataPoint.endTime), }; - if (valueType === ValueType.INT) { - out.asInt = dataPoint.value as number; - } else if (valueType === ValueType.DOUBLE) { - out.asDouble = dataPoint.value as number; + switch (valueType) { + case ValueType.INT: + out.asInt = dataPoint.value as number; + break; + case ValueType.DOUBLE: + out.asDouble = dataPoint.value as number; + break; } return out; @@ -177,13 +181,10 @@ function toExponentialHistogramDataPoints( function toAggregationTemporality( temporality: AggregationTemporality ): EAggregationTemporality { - if (temporality === AggregationTemporality.DELTA) { - return EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA; + switch (temporality) { + case AggregationTemporality.DELTA: + return EAggregationTemporality.AGGREGATION_TEMPORALITY_DELTA; + case AggregationTemporality.CUMULATIVE: + return EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE; } - - if (temporality === AggregationTemporality.CUMULATIVE) { - return EAggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE; - } - - return EAggregationTemporality.AGGREGATION_TEMPORALITY_UNSPECIFIED; } From 2f1e31648402b310448d226ae9632b115e6ad5c4 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Fri, 28 Apr 2023 12:58:20 +0200 Subject: [PATCH 3/3] feat(otlp-grpc-exporter-base): use statically generated protobuf code (#3705) Co-authored-by: Daniel Dyla --- experimental/CHANGELOG.md | 1 + .../otlp-grpc-exporter-base/.gitignore | 2 + .../otlp-grpc-exporter-base/package.json | 16 ++-- .../src/LogsExportServiceClient.ts | 51 +++++++++++ .../src/MetricsExportServiceClient.ts | 54 +++++++++++ .../src/TraceExportServiceClient.ts | 54 +++++++++++ .../src/generated/.gitkeep | 0 .../src/internal-types.ts | 22 +++++ .../otlp-grpc-exporter-base/src/types.ts | 4 +- .../otlp-grpc-exporter-base/src/util.ts | 89 ++++++++----------- .../otlp-grpc-exporter-base/tsconfig.json | 4 +- .../otlp-proto-exporter-base/package.json | 3 +- package.json | 6 +- .../protos.js => scripts/generate-protos.js | 12 ++- 14 files changed, 246 insertions(+), 72 deletions(-) create mode 100644 experimental/packages/otlp-grpc-exporter-base/.gitignore create mode 100644 experimental/packages/otlp-grpc-exporter-base/src/LogsExportServiceClient.ts create mode 100644 experimental/packages/otlp-grpc-exporter-base/src/MetricsExportServiceClient.ts create mode 100644 experimental/packages/otlp-grpc-exporter-base/src/TraceExportServiceClient.ts create mode 100644 experimental/packages/otlp-grpc-exporter-base/src/generated/.gitkeep create mode 100644 experimental/packages/otlp-grpc-exporter-base/src/internal-types.ts rename experimental/packages/otlp-proto-exporter-base/scripts/protos.js => scripts/generate-protos.js (78%) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index bf12e19402..34d7727835 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to experimental packages in this project will be documented * feat(otlp-transformer): support log records. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 * feat(otlp-grpc-exporter-base): support log records. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 * feat(exporter-logs-otlp-grpc): otlp-grpc exporter for logs. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 +* feat(otlp-grpc-exporter-base): use statically generated protobuf code [#3705](https://github.com/open-telemetry/opentelemetry-js/pull/3705) @pichlermarc * refactor(otlp-transformer): refine metric transformers. [#3770](https://github.com/open-telemetry/opentelemetry-js/pull/3770/) @llc1123 ### :bug: (Bug Fix) diff --git a/experimental/packages/otlp-grpc-exporter-base/.gitignore b/experimental/packages/otlp-grpc-exporter-base/.gitignore new file mode 100644 index 0000000000..c82683cbd7 --- /dev/null +++ b/experimental/packages/otlp-grpc-exporter-base/.gitignore @@ -0,0 +1,2 @@ +src/generated/* +!src/generated/.gitkeep diff --git a/experimental/packages/otlp-grpc-exporter-base/package.json b/experimental/packages/otlp-grpc-exporter-base/package.json index cdb9986816..132c96b4c5 100644 --- a/experimental/packages/otlp-grpc-exporter-base/package.json +++ b/experimental/packages/otlp-grpc-exporter-base/package.json @@ -8,17 +8,17 @@ "scripts": { "prepublishOnly": "npm run compile", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", - "compile": "tsc --build", + "compile": "npm run protos && tsc --build", "clean": "tsc --build --clean", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", - "postcompile": "npm run submodule && npm run protos:copy", - "protos:copy": "cpx protos/opentelemetry/**/*.* build/protos/opentelemetry", + "protos": "npm run submodule && npm run protos:generate", + "protos:generate": "node ../../../scripts/generate-protos.js", "submodule": "git submodule sync --recursive && git submodule update --init --recursive", "tdd": "npm run test -- --watch-extensions ts --watch", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "version": "node ../../../scripts/version-update.js", - "watch": "npm run protos:copy && tsc -w", + "watch": "npm run protos && tsc -w", "precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies", "prewatch": "npm run precompile" }, @@ -40,7 +40,6 @@ "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", - "build/protos/**/*.proto", "doc", "LICENSE", "README.md" @@ -64,16 +63,17 @@ "sinon": "15.0.0", "ts-loader": "8.4.0", "ts-mocha": "10.0.0", - "typescript": "4.4.4" + "typescript": "4.4.4", + "protobufjs-cli": "1.0.2" }, "peerDependencies": { "@opentelemetry/api": "^1.0.0" }, "dependencies": { "@grpc/grpc-js": "^1.7.1", - "@grpc/proto-loader": "^0.7.3", "@opentelemetry/core": "1.12.0", - "@opentelemetry/otlp-exporter-base": "0.38.0" + "@opentelemetry/otlp-exporter-base": "0.38.0", + "protobufjs": "^7.2.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/otlp-grpc-exporter-base", "sideEffects": false diff --git a/experimental/packages/otlp-grpc-exporter-base/src/LogsExportServiceClient.ts b/experimental/packages/otlp-grpc-exporter-base/src/LogsExportServiceClient.ts new file mode 100644 index 0000000000..148fca31a1 --- /dev/null +++ b/experimental/packages/otlp-grpc-exporter-base/src/LogsExportServiceClient.ts @@ -0,0 +1,51 @@ +/* + * 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 root from './generated/root'; +import * as grpc from '@grpc/grpc-js'; +import { IExportLogsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { ExportType } from './internal-types'; +import IExportLogsServiceResponse = root.opentelemetry.proto.collector.logs.v1.IExportLogsServiceResponse; + +const responseType = root.opentelemetry.proto.collector.logs.v1 + .ExportLogsServiceResponse as ExportType; + +const requestType = root.opentelemetry.proto.collector.logs.v1 + .ExportLogsServiceRequest as ExportType; + +const logsServiceDefinition = { + export: { + path: '/opentelemetry.proto.collector.logs.v1.LogsService/Export', + requestStream: false, + responseStream: false, + requestSerialize: (arg: IExportLogsServiceRequest) => { + return Buffer.from(requestType.encode(arg).finish()); + }, + requestDeserialize: (arg: Buffer) => { + return requestType.decode(arg); + }, + responseSerialize: (arg: IExportLogsServiceResponse) => { + return Buffer.from(responseType.encode(arg).finish()); + }, + responseDeserialize: (arg: Buffer) => { + return responseType.decode(arg); + }, + }, +}; + +// Creates a new instance of a gRPC service client for OTLP logs +export const LogsExportServiceClient: grpc.ServiceClientConstructor = + grpc.makeGenericClientConstructor(logsServiceDefinition, 'LogsExportService'); diff --git a/experimental/packages/otlp-grpc-exporter-base/src/MetricsExportServiceClient.ts b/experimental/packages/otlp-grpc-exporter-base/src/MetricsExportServiceClient.ts new file mode 100644 index 0000000000..9a791ca2f3 --- /dev/null +++ b/experimental/packages/otlp-grpc-exporter-base/src/MetricsExportServiceClient.ts @@ -0,0 +1,54 @@ +/* + * 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 root from './generated/root'; +import * as grpc from '@grpc/grpc-js'; +import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { ExportType } from './internal-types'; +import IExportMetricsServiceResponse = root.opentelemetry.proto.collector.metrics.v1.IExportMetricsServiceResponse; + +const responseType = root.opentelemetry.proto.collector.metrics.v1 + .ExportMetricsServiceResponse as ExportType; + +const requestType = root.opentelemetry.proto.collector.metrics.v1 + .ExportMetricsServiceRequest as ExportType; + +const metricsServiceDefinition = { + export: { + path: '/opentelemetry.proto.collector.metrics.v1.MetricsService/Export', + requestStream: false, + responseStream: false, + requestSerialize: (arg: IExportMetricsServiceRequest) => { + return Buffer.from(requestType.encode(arg).finish()); + }, + requestDeserialize: (arg: Buffer) => { + return requestType.decode(arg); + }, + responseSerialize: (arg: IExportMetricsServiceResponse) => { + return Buffer.from(responseType.encode(arg).finish()); + }, + responseDeserialize: (arg: Buffer) => { + return responseType.decode(arg); + }, + }, +}; + +// Creates a new instance of a gRPC service client for OTLP metrics +export const MetricExportServiceClient: grpc.ServiceClientConstructor = + grpc.makeGenericClientConstructor( + metricsServiceDefinition, + 'MetricsExportService' + ); diff --git a/experimental/packages/otlp-grpc-exporter-base/src/TraceExportServiceClient.ts b/experimental/packages/otlp-grpc-exporter-base/src/TraceExportServiceClient.ts new file mode 100644 index 0000000000..6a150a24b1 --- /dev/null +++ b/experimental/packages/otlp-grpc-exporter-base/src/TraceExportServiceClient.ts @@ -0,0 +1,54 @@ +/* + * 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 root from './generated/root'; +import * as grpc from '@grpc/grpc-js'; +import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; +import { ExportType } from './internal-types'; +import IExportTraceServiceResponse = root.opentelemetry.proto.collector.trace.v1.IExportTraceServiceResponse; + +const responseType = root.opentelemetry.proto.collector.trace.v1 + .ExportTraceServiceResponse as ExportType; + +const requestType = root.opentelemetry.proto.collector.trace.v1 + .ExportTraceServiceRequest as ExportType; + +const traceServiceDefinition = { + export: { + path: '/opentelemetry.proto.collector.trace.v1.TraceService/Export', + requestStream: false, + responseStream: false, + requestSerialize: (arg: IExportTraceServiceRequest) => { + return Buffer.from(requestType.encode(arg).finish()); + }, + requestDeserialize: (arg: Buffer) => { + return requestType.decode(arg); + }, + responseSerialize: (arg: IExportTraceServiceResponse) => { + return Buffer.from(responseType.encode(arg).finish()); + }, + responseDeserialize: (arg: Buffer) => { + return responseType.decode(arg); + }, + }, +}; + +// Creates a new instance of a gRPC service client for exporting OTLP traces +export const TraceExportServiceClient: grpc.ServiceClientConstructor = + grpc.makeGenericClientConstructor( + traceServiceDefinition, + 'TraceExportService' + ); diff --git a/experimental/packages/otlp-grpc-exporter-base/src/generated/.gitkeep b/experimental/packages/otlp-grpc-exporter-base/src/generated/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/experimental/packages/otlp-grpc-exporter-base/src/internal-types.ts b/experimental/packages/otlp-grpc-exporter-base/src/internal-types.ts new file mode 100644 index 0000000000..8d108a0a22 --- /dev/null +++ b/experimental/packages/otlp-grpc-exporter-base/src/internal-types.ts @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type * as protobuf from 'protobufjs'; + +export interface ExportType unknown }> { + encode(message: T, writer?: protobuf.Writer): protobuf.Writer; + decode(reader: protobuf.Reader | Uint8Array, length?: number): R; +} diff --git a/experimental/packages/otlp-grpc-exporter-base/src/types.ts b/experimental/packages/otlp-grpc-exporter-base/src/types.ts index af67188846..7ecedff1ba 100644 --- a/experimental/packages/otlp-grpc-exporter-base/src/types.ts +++ b/experimental/packages/otlp-grpc-exporter-base/src/types.ts @@ -34,13 +34,15 @@ export interface GRPCQueueItem { /** * Service Client for sending spans/metrics/logs */ -export interface ServiceClient extends grpc.Client { +export interface ServiceClient { export: ( request: any, metadata: grpc.Metadata, options: grpc.CallOptions, callback: Function ) => {}; + + close(): void; } /** diff --git a/experimental/packages/otlp-grpc-exporter-base/src/util.ts b/experimental/packages/otlp-grpc-exporter-base/src/util.ts index f4dc8af8a9..7e1d58dff7 100644 --- a/experimental/packages/otlp-grpc-exporter-base/src/util.ts +++ b/experimental/packages/otlp-grpc-exporter-base/src/util.ts @@ -15,7 +15,6 @@ */ import * as grpc from '@grpc/grpc-js'; -import * as protoLoader from '@grpc/proto-loader'; import { diag } from '@opentelemetry/api'; import { getEnv, globalErrorHandler } from '@opentelemetry/core'; import * as path from 'path'; @@ -28,11 +27,15 @@ import { ServiceClientType, } from './types'; import { - CompressionAlgorithm, ExportServiceError, OTLPExporterError, + CompressionAlgorithm, } from '@opentelemetry/otlp-exporter-base'; +import { MetricExportServiceClient } from './MetricsExportServiceClient'; +import { TraceExportServiceClient } from './TraceExportServiceClient'; +import { LogsExportServiceClient } from './LogsExportServiceClient'; + export const DEFAULT_COLLECTOR_URL = 'http://localhost:4317'; export function onInit( @@ -46,61 +49,41 @@ export function onInit( collector.getUrlFromConfig(config) ); - const includeDirs = [path.resolve(__dirname, '..', 'protos')]; + try { + if (collector.getServiceClientType() === ServiceClientType.SPANS) { + const client = new TraceExportServiceClient(collector.url, credentials, { + 'grpc.default_compression_algorithm': collector.compression.valueOf(), + }); - protoLoader - .load(collector.getServiceProtoPath(), { - keepCase: false, - longs: String, - enums: String, - defaults: true, - oneofs: true, - includeDirs, - }) - .then(packageDefinition => { - const packageObject: any = grpc.loadPackageDefinition(packageDefinition); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + collector.serviceClient = client; + } else if (collector.getServiceClientType() === ServiceClientType.METRICS) { + const client = new MetricExportServiceClient(collector.url, credentials, { + 'grpc.default_compression_algorithm': collector.compression.valueOf(), + }); - const options = { - 'grpc.default_compression_algorithm': collector.compression, - }; - - switch (collector.getServiceClientType()) { - case ServiceClientType.SPANS: - collector.serviceClient = - new packageObject.opentelemetry.proto.collector.trace.v1.TraceService( - collector.url, - credentials, - options - ); - break; - case ServiceClientType.METRICS: - collector.serviceClient = - new packageObject.opentelemetry.proto.collector.metrics.v1.MetricsService( - collector.url, - credentials, - options - ); - break; - case ServiceClientType.LOGS: - collector.serviceClient = - new packageObject.opentelemetry.proto.collector.logs.v1.LogsService( - collector.url, - credentials, - options - ); - break; - } + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + collector.serviceClient = client; + } else if (collector.getServiceClientType() === ServiceClientType.LOGS) { + const client = new LogsExportServiceClient(collector.url, credentials, { + 'grpc.default_compression_algorithm': collector.compression.valueOf(), + }); - if (collector.grpcQueue.length > 0) { - const queue = collector.grpcQueue.splice(0); - queue.forEach((item: GRPCQueueItem) => { - collector.send(item.objects, item.onSuccess, item.onError); - }); - } - }) - .catch(err => { - globalErrorHandler(err); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + collector.serviceClient = client; + } + } catch (err) { + globalErrorHandler(err); + } + if (collector.grpcQueue.length > 0) { + const queue = collector.grpcQueue.splice(0); + queue.forEach((item: GRPCQueueItem) => { + collector.send(item.objects, item.onSuccess, item.onError); }); + } } export function send( diff --git a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json index bbfbbc57b0..ddc035cf3a 100644 --- a/experimental/packages/otlp-grpc-exporter-base/tsconfig.json +++ b/experimental/packages/otlp-grpc-exporter-base/tsconfig.json @@ -1,12 +1,14 @@ { "extends": "../../../tsconfig.base.json", "compilerOptions": { + "allowJs": true, "outDir": "build", "rootDir": "." }, "include": [ "src/**/*.ts", - "src/generated/*.js", + "src/generated/**/*.js", + "src/generated/**/*.ts", "test/**/*.ts" ], "references": [ diff --git a/experimental/packages/otlp-proto-exporter-base/package.json b/experimental/packages/otlp-proto-exporter-base/package.json index 6f39ea25e7..56fc97450f 100644 --- a/experimental/packages/otlp-proto-exporter-base/package.json +++ b/experimental/packages/otlp-proto-exporter-base/package.json @@ -19,7 +19,8 @@ "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", - "protos": "npm run submodule && node scripts/protos.js", + "protos": "npm run submodule && npm run protos:generate", + "protos:generate": "node ../../../scripts/generate-protos.js", "submodule": "git submodule sync --recursive && git submodule update --init --recursive", "version": "node ../../../scripts/version-update.js", "watch": "npm run protos && tsc -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json", diff --git a/package.json b/package.json index df63bd8fcd..d03e6ff438 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,13 @@ "version": "0.1.0", "description": "OpenTelemetry is a distributed tracing and stats collection framework.", "scripts": { - "precompile": "lerna run version", - "compile": "lerna run protos && tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", + "precompile": "lerna run version && npm run submodule", + "compile": "lerna run protos:generate && tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "prewatch": "npm run precompile", "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json", "postinstall": "npm run update-ts-configs && npm run bootstrap", - "postcompile": "npm run submodule && npm run protos:copy", "submodule": "git submodule sync --recursive && git submodule update --init --recursive", - "protos:copy": "lerna run protos:copy", "version:update": "lerna run version:update", "test": "lerna run test", "test:browser": "lerna run test:browser", diff --git a/experimental/packages/otlp-proto-exporter-base/scripts/protos.js b/scripts/generate-protos.js similarity index 78% rename from experimental/packages/otlp-proto-exporter-base/scripts/protos.js rename to scripts/generate-protos.js index 3f3fbd6c0c..972969f80d 100644 --- a/experimental/packages/otlp-proto-exporter-base/scripts/protos.js +++ b/scripts/generate-protos.js @@ -3,8 +3,10 @@ const cp = require('child_process'); const path = require('path'); -const generatedPath = path.resolve(__dirname, '../src/generated'); -const protosPath = path.resolve(__dirname, '../protos'); +const appRoot = process.cwd(); + +const generatedPath = path.resolve(appRoot, './src/generated'); +const protosPath = path.resolve(appRoot, './protos'); const protos = [ 'opentelemetry/proto/common/v1/common.proto', 'opentelemetry/proto/resource/v1/resource.proto', @@ -12,6 +14,8 @@ const protos = [ 'opentelemetry/proto/collector/trace/v1/trace_service.proto', 'opentelemetry/proto/metrics/v1/metrics.proto', 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto', + 'opentelemetry/proto/logs/v1/logs.proto', + 'opentelemetry/proto/collector/logs/v1/logs_service.proto', ].map(it => { return path.join(protosPath, it); }); @@ -33,7 +37,7 @@ function exec(command, argv) { } function pbts(pbjsOutFile) { - const pbtsPath = path.resolve(__dirname, '../node_modules/.bin/pbts'); + const pbtsPath = path.resolve(appRoot, './node_modules/.bin/pbts'); const pbtsOptions = [ '-o', path.join(generatedPath, 'root.d.ts'), ]; @@ -41,7 +45,7 @@ function pbts(pbjsOutFile) { } async function pbjs(files) { - const pbjsPath = path.resolve(__dirname, '../node_modules/.bin/pbjs'); + const pbjsPath = path.resolve(appRoot, './node_modules/.bin/pbjs'); const outFile = path.join(generatedPath, 'root.js'); const pbjsOptions = [ '-t', 'static-module',