From 4a54c84edae4505d60e60fac821c942abc90eb47 Mon Sep 17 00:00:00 2001 From: legendecas Date: Wed, 29 Apr 2020 12:58:53 +0800 Subject: [PATCH] refactor: merge opentelemetry-base to opentelemetry-core They act a very similar role in the SDK. --- .../opentelemetry-core/src/ExportResult.ts | 21 ++++++++++++++++ packages/opentelemetry-core/src/index.ts | 1 + .../src/platform/browser/constants.ts | 25 +++++++++++++++++++ .../src/platform/browser/index.ts | 1 + .../src/platform/node/constants.ts | 25 +++++++++++++++++++ .../src/platform/node/index.ts | 1 + .../package.json | 1 - .../src/CollectorExporter.ts | 3 +-- .../src/transform.ts | 5 ++-- .../package.json | 1 - .../src/jaeger.ts | 3 +-- .../package.json | 1 - .../src/prometheus.ts | 3 +-- .../package.json | 1 - .../src/zipkin.ts | 3 +-- packages/opentelemetry-metrics/package.json | 1 - .../src/export/ConsoleMetricExporter.ts | 2 +- .../src/export/Controller.ts | 3 +-- .../src/export/NoopExporter.ts | 2 +- .../opentelemetry-metrics/src/export/types.ts | 2 +- .../package.json | 1 - packages/opentelemetry-resources/package.json | 1 - .../opentelemetry-resources/src/Resource.ts | 2 +- packages/opentelemetry-tracing/package.json | 1 - .../src/export/ConsoleSpanExporter.ts | 3 +-- .../src/export/InMemorySpanExporter.ts | 2 +- .../src/export/SpanExporter.ts | 2 +- 27 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 packages/opentelemetry-core/src/ExportResult.ts create mode 100644 packages/opentelemetry-core/src/platform/browser/constants.ts create mode 100644 packages/opentelemetry-core/src/platform/node/constants.ts diff --git a/packages/opentelemetry-core/src/ExportResult.ts b/packages/opentelemetry-core/src/ExportResult.ts new file mode 100644 index 00000000000..3f94eddd57b --- /dev/null +++ b/packages/opentelemetry-core/src/ExportResult.ts @@ -0,0 +1,21 @@ +/*! + * Copyright 2019, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum ExportResult { + SUCCESS, + FAILED_NOT_RETRYABLE, + FAILED_RETRYABLE, +} diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 60b8b04f925..46f1baf8be1 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -18,6 +18,7 @@ export * from './common/ConsoleLogger'; export * from './common/NoopLogger'; export * from './common/time'; export * from './common/types'; +export * from './ExportResult'; export * from './version'; export * from './context/context'; export * from './context/propagation/B3Propagator'; diff --git a/packages/opentelemetry-core/src/platform/browser/constants.ts b/packages/opentelemetry-core/src/platform/browser/constants.ts new file mode 100644 index 00000000000..f37897b4683 --- /dev/null +++ b/packages/opentelemetry-core/src/platform/browser/constants.ts @@ -0,0 +1,25 @@ +/** + * Copyright 2020, 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 { VERSION } from '../../version'; + +/** Constants describing the SDK in use */ +export const SDK_INFO = { + NAME: 'opentelemetry', + RUNTIME: 'browser', + LANGUAGE: 'webjs', + VERSION: VERSION, +}; diff --git a/packages/opentelemetry-core/src/platform/browser/index.ts b/packages/opentelemetry-core/src/platform/browser/index.ts index 4668bb35aa2..59dc0fd827d 100644 --- a/packages/opentelemetry-core/src/platform/browser/index.ts +++ b/packages/opentelemetry-core/src/platform/browser/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +export * from './constants'; export * from './id'; export * from './performance'; export * from './timer-util'; diff --git a/packages/opentelemetry-core/src/platform/node/constants.ts b/packages/opentelemetry-core/src/platform/node/constants.ts new file mode 100644 index 00000000000..33c475d4289 --- /dev/null +++ b/packages/opentelemetry-core/src/platform/node/constants.ts @@ -0,0 +1,25 @@ +/** + * Copyright 2020, 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 { VERSION } from '../../version'; + +/** Constants describing the SDK in use */ +export const SDK_INFO = { + NAME: 'opentelemetry', + RUNTIME: 'node', + LANGUAGE: 'nodejs', + VERSION: VERSION, +}; diff --git a/packages/opentelemetry-core/src/platform/node/index.ts b/packages/opentelemetry-core/src/platform/node/index.ts index 4668bb35aa2..59dc0fd827d 100644 --- a/packages/opentelemetry-core/src/platform/node/index.ts +++ b/packages/opentelemetry-core/src/platform/node/index.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +export * from './constants'; export * from './id'; export * from './performance'; export * from './timer-util'; diff --git a/packages/opentelemetry-exporter-collector/package.json b/packages/opentelemetry-exporter-collector/package.json index ca89b50383c..27a209fa1a6 100644 --- a/packages/opentelemetry-exporter-collector/package.json +++ b/packages/opentelemetry-exporter-collector/package.json @@ -85,7 +85,6 @@ "dependencies": { "@grpc/proto-loader": "^0.5.3", "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/resources": "^0.7.0", "@opentelemetry/tracing": "^0.7.0", diff --git a/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts b/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts index 7199848da8e..070042b121b 100644 --- a/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/CollectorExporter.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { ExportResult } from '@opentelemetry/base'; -import { NoopLogger } from '@opentelemetry/core'; +import { ExportResult, NoopLogger } from '@opentelemetry/core'; import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing'; import { Attributes, Logger } from '@opentelemetry/api'; import { onInit, onShutdown, sendSpans } from './platform/index'; diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 580434c9908..3f67635ce67 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -21,7 +21,6 @@ import { TimedEvent, TraceState, } from '@opentelemetry/api'; -import { SDK_INFO } from '@opentelemetry/base'; import * as core from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { ReadableSpan } from '@opentelemetry/tracing'; @@ -218,8 +217,8 @@ export function toCollectorExportTraceServiceRequest( const instrumentationLibrarySpans: opentelemetryProto.trace.v1.InstrumentationLibrarySpans = { spans: spansToBeSent, instrumentationLibrary: { - name: name || `${SDK_INFO.NAME} - ${SDK_INFO.LANGUAGE}`, - version: SDK_INFO.VERSION, + name: name || `${core.SDK_INFO.NAME} - ${core.SDK_INFO.LANGUAGE}`, + version: core.SDK_INFO.VERSION, }, }; const resourceSpan: opentelemetryProto.trace.v1.ResourceSpans = { diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index 7cee3b85e07..99ccd8073d8 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -57,7 +57,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/tracing": "^0.7.0", "jaeger-client": "^3.15.0" diff --git a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts index 83f66584925..62d1320b4e9 100644 --- a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts +++ b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts @@ -15,8 +15,7 @@ */ import * as api from '@opentelemetry/api'; -import { ExportResult } from '@opentelemetry/base'; -import { NoopLogger } from '@opentelemetry/core'; +import { ExportResult, NoopLogger } from '@opentelemetry/core'; import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing'; import { Socket } from 'dgram'; import { spanToThrift } from './transform'; diff --git a/packages/opentelemetry-exporter-prometheus/package.json b/packages/opentelemetry-exporter-prometheus/package.json index d8985c4da75..d8c759f1be5 100644 --- a/packages/opentelemetry-exporter-prometheus/package.json +++ b/packages/opentelemetry-exporter-prometheus/package.json @@ -55,7 +55,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/metrics": "^0.7.0", "prom-client": "^11.5.3" diff --git a/packages/opentelemetry-exporter-prometheus/src/prometheus.ts b/packages/opentelemetry-exporter-prometheus/src/prometheus.ts index 9d266ecdc17..dc4df20c53c 100644 --- a/packages/opentelemetry-exporter-prometheus/src/prometheus.ts +++ b/packages/opentelemetry-exporter-prometheus/src/prometheus.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { ExportResult } from '@opentelemetry/base'; -import { NoopLogger, hrTimeToMilliseconds } from '@opentelemetry/core'; +import { ExportResult, NoopLogger, hrTimeToMilliseconds } from '@opentelemetry/core'; import { CounterSumAggregator, LastValue, diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index 394981afa34..5dea64a4fb6 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -55,7 +55,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/resources": "^0.7.0", "@opentelemetry/tracing": "^0.7.0" diff --git a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts index 56a06469f20..ca57625fdd2 100644 --- a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts +++ b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts @@ -18,9 +18,8 @@ import * as types from '@opentelemetry/api'; import * as http from 'http'; import * as https from 'https'; import * as url from 'url'; -import { NoopLogger } from '@opentelemetry/core'; +import { ExportResult, NoopLogger } from '@opentelemetry/core'; import { SpanExporter, ReadableSpan } from '@opentelemetry/tracing'; -import { ExportResult } from '@opentelemetry/base'; import * as zipkinTypes from './types'; import { toZipkinSpan, diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index 1e7a12497c1..9ea621828e7 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -58,7 +58,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/resources": "^0.7.0" } diff --git a/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts b/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts index 0440f895814..90f2f6be5d8 100644 --- a/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts +++ b/packages/opentelemetry-metrics/src/export/ConsoleMetricExporter.ts @@ -15,7 +15,7 @@ */ import { MetricExporter, MetricRecord, Distribution, Histogram } from './types'; -import { ExportResult } from '@opentelemetry/base'; +import { ExportResult } from '@opentelemetry/core'; /** * This is implementation of {@link MetricExporter} that prints metrics data to diff --git a/packages/opentelemetry-metrics/src/export/Controller.ts b/packages/opentelemetry-metrics/src/export/Controller.ts index ccef3213eb6..5ce3d0ee681 100644 --- a/packages/opentelemetry-metrics/src/export/Controller.ts +++ b/packages/opentelemetry-metrics/src/export/Controller.ts @@ -14,10 +14,9 @@ * limitations under the License. */ -import { unrefTimer } from '@opentelemetry/core'; +import { ExportResult, unrefTimer } from '@opentelemetry/core'; import { Meter } from '../Meter'; import { MetricExporter } from './types'; -import { ExportResult } from '@opentelemetry/base'; const DEFAULT_EXPORT_INTERVAL = 60_000; diff --git a/packages/opentelemetry-metrics/src/export/NoopExporter.ts b/packages/opentelemetry-metrics/src/export/NoopExporter.ts index 84eab150b8d..05b3694939a 100644 --- a/packages/opentelemetry-metrics/src/export/NoopExporter.ts +++ b/packages/opentelemetry-metrics/src/export/NoopExporter.ts @@ -15,7 +15,7 @@ */ import { MetricExporter, MetricRecord } from './types'; -import { ExportResult } from '@opentelemetry/base'; +import { ExportResult } from '@opentelemetry/core'; export class NoopExporter implements MetricExporter { // By default does nothing diff --git a/packages/opentelemetry-metrics/src/export/types.ts b/packages/opentelemetry-metrics/src/export/types.ts index 40b631e0269..cffe91bc47c 100644 --- a/packages/opentelemetry-metrics/src/export/types.ts +++ b/packages/opentelemetry-metrics/src/export/types.ts @@ -15,7 +15,7 @@ */ import { ValueType, HrTime, Labels } from '@opentelemetry/api'; -import { ExportResult } from '@opentelemetry/base'; +import { ExportResult } from '@opentelemetry/core'; /** The kind of metric. */ export enum MetricKind { diff --git a/packages/opentelemetry-plugin-xml-http-request/package.json b/packages/opentelemetry-plugin-xml-http-request/package.json index fa1a100e078..b12a130ed7f 100644 --- a/packages/opentelemetry-plugin-xml-http-request/package.json +++ b/packages/opentelemetry-plugin-xml-http-request/package.json @@ -77,7 +77,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/web": "^0.7.0", "shimmer": "^1.2.1" diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index 51925febfbb..327fd487b33 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -62,7 +62,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "gcp-metadata": "^3.5.0" } } diff --git a/packages/opentelemetry-resources/src/Resource.ts b/packages/opentelemetry-resources/src/Resource.ts index 0a76dad9684..bed19ee739f 100644 --- a/packages/opentelemetry-resources/src/Resource.ts +++ b/packages/opentelemetry-resources/src/Resource.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { SDK_INFO } from '@opentelemetry/base'; +import { SDK_INFO } from '@opentelemetry/core'; import { TELEMETRY_SDK_RESOURCE } from './constants'; import { ResourceLabels } from './types'; diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index 13c0d9e29a8..967241ecb8a 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -74,7 +74,6 @@ }, "dependencies": { "@opentelemetry/api": "^0.7.0", - "@opentelemetry/base": "^0.7.0", "@opentelemetry/context-base": "^0.7.0", "@opentelemetry/core": "^0.7.0", "@opentelemetry/resources": "^0.7.0" diff --git a/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts index 7f5fc968047..42c5875bd6c 100644 --- a/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-tracing/src/export/ConsoleSpanExporter.ts @@ -16,8 +16,7 @@ import { SpanExporter } from './SpanExporter'; import { ReadableSpan } from './ReadableSpan'; -import { ExportResult } from '@opentelemetry/base'; -import { hrTimeToMicroseconds } from '@opentelemetry/core'; +import { ExportResult, hrTimeToMicroseconds } from '@opentelemetry/core'; /** * This is implementation of {@link SpanExporter} that prints spans to the diff --git a/packages/opentelemetry-tracing/src/export/InMemorySpanExporter.ts b/packages/opentelemetry-tracing/src/export/InMemorySpanExporter.ts index 5415075ddb2..b3de120411f 100644 --- a/packages/opentelemetry-tracing/src/export/InMemorySpanExporter.ts +++ b/packages/opentelemetry-tracing/src/export/InMemorySpanExporter.ts @@ -16,7 +16,7 @@ import { SpanExporter } from './SpanExporter'; import { ReadableSpan } from './ReadableSpan'; -import { ExportResult } from '@opentelemetry/base'; +import { ExportResult } from '@opentelemetry/core'; /** * This class can be used for testing purposes. It stores the exported spans diff --git a/packages/opentelemetry-tracing/src/export/SpanExporter.ts b/packages/opentelemetry-tracing/src/export/SpanExporter.ts index 88e191c1ffd..72f7ff25726 100644 --- a/packages/opentelemetry-tracing/src/export/SpanExporter.ts +++ b/packages/opentelemetry-tracing/src/export/SpanExporter.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ExportResult } from '@opentelemetry/base'; +import { ExportResult } from '@opentelemetry/core'; import { ReadableSpan } from './ReadableSpan'; /**