diff --git a/examples/basic-tracer-node/docker/ot/collector-config.yaml b/examples/basic-tracer-node/docker/ot/collector-config.yaml index b550ca4fa6a..510af56b458 100644 --- a/examples/basic-tracer-node/docker/ot/collector-config.yaml +++ b/examples/basic-tracer-node/docker/ot/collector-config.yaml @@ -3,19 +3,24 @@ receivers: protocols: grpc: http: - cors_allowed_origins: - - http://* - - https://* + cors: + allowed_origins: + - http://* + - https://* exporters: jaeger: endpoint: jaeger-all-in-one:14250 - insecure: true + tls: + insecure: true processors: batch: service: + telemetry: + logs: + level: "debug" pipelines: traces: receivers: [otlp] diff --git a/examples/basic-tracer-node/docker/ot/docker-compose.yaml b/examples/basic-tracer-node/docker/ot/docker-compose.yaml index a2068c155b3..41cc6954699 100644 --- a/examples/basic-tracer-node/docker/ot/docker-compose.yaml +++ b/examples/basic-tracer-node/docker/ot/docker-compose.yaml @@ -3,20 +3,20 @@ services: # Collector otel-collector: - image: otel/opentelemetry-collector:0.27.0 - command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] + image: otel/opentelemetry-collector-contrib:0.42.0 + command: ["--config=/conf/collector-config.yaml"] volumes: - ./collector-config.yaml:/conf/collector-config.yaml ports: - "9464:9464" - "4317:4317" - - "55681:55681" + - "4318:4318" depends_on: - jaeger-all-in-one # Jaeger jaeger-all-in-one: - image: jaegertracing/all-in-one:1.22.0 + image: jaegertracing/all-in-one:1.30.0 ports: - "16686:16686" - "14268:14268" diff --git a/examples/otlp-exporter-node/docker/collector-config.yaml b/examples/otlp-exporter-node/docker/collector-config.yaml index 04d65a6ba2f..61025e4382d 100644 --- a/examples/otlp-exporter-node/docker/collector-config.yaml +++ b/examples/otlp-exporter-node/docker/collector-config.yaml @@ -3,9 +3,10 @@ receivers: protocols: grpc: http: - cors_allowed_origins: - - http://* - - https://* + cors: + allowed_origins: + - http://* + - https://* exporters: zipkin: @@ -17,6 +18,9 @@ processors: batch: service: + telemetry: + logs: + level: "debug" pipelines: traces: receivers: [otlp] diff --git a/examples/otlp-exporter-node/docker/docker-compose.yaml b/examples/otlp-exporter-node/docker/docker-compose.yaml index 1324c33f009..d0b6d62e7c0 100644 --- a/examples/otlp-exporter-node/docker/docker-compose.yaml +++ b/examples/otlp-exporter-node/docker/docker-compose.yaml @@ -2,15 +2,15 @@ version: "3" services: # Collector collector: - image: otel/opentelemetry-collector:0.25.0 -# image: otel/opentelemetry-collector:latest - command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] + image: otel/opentelemetry-collector-contrib:0.42.0 +# image: otel/opentelemetry-collector-contrib:latest + command: ["--config=/conf/collector-config.yaml"] volumes: - ./collector-config.yaml:/conf/collector-config.yaml ports: - "9464:9464" - "4317:4317" - - "55681:55681" + - "4318:4318" depends_on: - zipkin-all-in-one diff --git a/examples/otlp-exporter-node/metrics.js b/examples/otlp-exporter-node/metrics.js index cb901694051..114fd0028a5 100644 --- a/examples/otlp-exporter-node/metrics.js +++ b/examples/otlp-exporter-node/metrics.js @@ -1,7 +1,7 @@ 'use strict'; const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api'); -const { OTLPMetricExporter } = require('@opentelemetry/exporter-otlp-http'); +const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http'); // const { OTLPMetricExporter } = require('@opentelemetry/exporter-otlp-grpc'); // const { OTLPMetricExporter } = require('@opentelemetry/exporter-otlp-proto'); const { MeterProvider } = require('@opentelemetry/sdk-metrics-base'); @@ -12,7 +12,7 @@ const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventi diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); const metricExporter = new OTLPMetricExporter({ - // url: 'http://localhost:55681/v1/metrics', + url: 'http://localhost:4318/v1/metrics', }); const meter = new MeterProvider({ diff --git a/examples/otlp-exporter-node/package.json b/examples/otlp-exporter-node/package.json index 8fb2a32a828..4a3c3aacf4c 100644 --- a/examples/otlp-exporter-node/package.json +++ b/examples/otlp-exporter-node/package.json @@ -1,7 +1,7 @@ { "name": "example-otlp-exporter-node", "private": true, - "version": "0.25.0", + "version": "0.27.0", "description": "Example of using @opentelemetry/collector-exporter in Node.js", "main": "index.js", "scripts": { @@ -29,14 +29,17 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.2", - "@opentelemetry/core": "0.25.0", - "@opentelemetry/exporter-otlp-http": "0.25.0", - "@opentelemetry/exporter-otlp-grpc": "0.25.0", - "@opentelemetry/exporter-otlp-proto": "0.25.0", - "@opentelemetry/resources": "0.25.0", - "@opentelemetry/semantic-conventions": "0.25.0", - "@opentelemetry/sdk-metrics-base": "0.25.0", - "@opentelemetry/sdk-trace-base": "0.25.0" + "@opentelemetry/core": "1.0.1", + "@opentelemetry/exporter-trace-otlp-http": "0.27.0", + "@opentelemetry/exporter-metrics-otlp-http": "0.27.0", + "@opentelemetry/exporter-trace-otlp-grpc": "0.27.0", + "@opentelemetry/exporter-metrics-otlp-grpc": "0.27.0", + "@opentelemetry/exporter-trace-otlp-proto": "0.27.0", + "@opentelemetry/exporter-metrics-otlp-proto": "0.27.0", + "@opentelemetry/resources": "1.0.1", + "@opentelemetry/semantic-conventions": "1.0.1", + "@opentelemetry/sdk-metrics-base": "0.27.0", + "@opentelemetry/sdk-trace-base": "1.0.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme" } diff --git a/examples/otlp-exporter-node/tracing.js b/examples/otlp-exporter-node/tracing.js index 4f718274aa5..661c4193481 100644 --- a/examples/otlp-exporter-node/tracing.js +++ b/examples/otlp-exporter-node/tracing.js @@ -2,7 +2,7 @@ const opentelemetry = require('@opentelemetry/api'); const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base'); -const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-http'); +const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); const { Resource } = require('@opentelemetry/resources'); const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions'); // const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-grpc'); diff --git a/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts b/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts index 35298c6d2fc..3803a633ffd 100644 --- a/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts +++ b/experimental/packages/opentelemetry-api-metrics/src/types/ObservableResult.ts @@ -20,5 +20,13 @@ import { Attributes } from './Metric'; * Interface that is being used in callback function for Observable Metric */ export interface ObservableResult { + /** + * Observe a measurement of the value associated with the given attributes. + * + * @param value The value to be observed. + * @param attributes The attributes associated with the value. If more than + * one values associated with the same attributes values, SDK may pick the + * last one or simply drop the entire observable result. + */ observe(value: number, attributes?: Attributes): void; } diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/README.md b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/README.md index fc7efb77322..fc5ebe33b87 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/README.md +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/README.md @@ -25,7 +25,7 @@ The OTLPMetricExporter in Web expects the endpoint to end in `/v1/metrics`. import { MeterProvider } from '@opentelemetry/sdk-metrics-base'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'; const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics headers: {}, // an optional object containing custom headers to be sent with each request concurrencyLimit: 1, // an optional limit on pending requests }; @@ -49,7 +49,7 @@ counter.add(10, { 'key': 'value' }); const { MeterProvider } = require('@opentelemetry/sdk-metrics-base'); const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http'); const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics concurrencyLimit: 1, // an optional limit on pending requests }; const exporter = new OTLPMetricExporter(collectorOptions); 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..3eb49d96651 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 @@ -20,7 +20,7 @@ import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Metric Exporter for Web 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 2e83ee6be6d..ebc2cc22948 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 @@ -25,7 +25,7 @@ import { toOTLPExportMetricServiceRequest } from '../../transformMetrics'; import { getEnv, baggageUtils } from '@opentelemetry/core'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Metric Exporter for Node diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index f0beecd7955..8bae6eab8cd 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -299,7 +299,7 @@ describe('OTLPMetricExporter - node with json over http', () => { setTimeout(() => { assert.strictEqual( collectorExporter['url'], - 'http://localhost:55681/v1/metrics' + 'http://localhost:4318/v1/metrics' ); done(); }); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/README.md b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/README.md index ff033a00f01..cbf16261e75 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/README.md +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/README.md @@ -23,7 +23,7 @@ To see sample code and documentation for the traces exporter, visit the [Collect const { MeterProvider } = require('@opentelemetry/sdk-metrics-base'); const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto'); const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics }; const exporter = new OTLPMetricExporter(collectorOptions); 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..e7916a34e79 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -25,7 +25,7 @@ import { ServiceClientType, OTLPExporterNodeBase } from '@opentelemetry/exporter import { getEnv, baggageUtils } from '@opentelemetry/core'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * OTLP Metric Exporter for Node with protobuf diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts index a9a3beb5562..7808db28e26 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts @@ -26,6 +26,7 @@ import { MetricData } from './export/MetricData'; import { isNotNullish } from './utils'; import { MetricCollectorHandle } from './state/MetricCollector'; import { HrTime } from '@opentelemetry/api'; +import { AsyncMetricStorage } from './state/AsyncMetricStorage'; // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#meter @@ -62,27 +63,30 @@ export class Meter implements metrics.Meter { } createObservableGauge( - _name: string, - _callback: metrics.ObservableCallback, - _options?: metrics.ObservableGaugeOptions, + name: string, + callback: metrics.ObservableCallback, + options?: metrics.ObservableGaugeOptions, ): void { - throw new Error('Method not implemented.'); + const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_GAUGE, options); + this._registerAsyncMetricStorage(descriptor, callback); } createObservableCounter( - _name: string, - _callback: metrics.ObservableCallback, - _options?: metrics.ObservableCounterOptions, + name: string, + callback: metrics.ObservableCallback, + options?: metrics.ObservableCounterOptions, ): void { - throw new Error('Method not implemented.'); + const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_COUNTER, options); + this._registerAsyncMetricStorage(descriptor, callback); } createObservableUpDownCounter( - _name: string, - _callback: metrics.ObservableCallback, - _options?: metrics.ObservableUpDownCounterOptions, + name: string, + callback: metrics.ObservableCallback, + options?: metrics.ObservableUpDownCounterOptions, ): void { - throw new Error('Method not implemented.'); + const descriptor = createInstrumentDescriptor(name, InstrumentType.OBSERVABLE_UP_DOWN_COUNTER, options); + this._registerAsyncMetricStorage(descriptor, callback); } private _registerMetricStorage(descriptor: InstrumentDescriptor) { @@ -99,6 +103,15 @@ export class Meter implements metrics.Meter { return new MultiMetricStorage(storages); } + private _registerAsyncMetricStorage(descriptor: InstrumentDescriptor, callback: metrics.ObservableCallback) { + const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary); + views.forEach(view => { + const storage = AsyncMetricStorage.create(view, descriptor, callback); + // TODO: handle conflicts + this._metricStorageRegistry.set(descriptor.name, storage); + }); + } + async collect(collector: MetricCollectorHandle, collectionTime: HrTime): Promise { const result = await Promise.all(Array.from(this._metricStorageRegistry.values()).map(metricStorage => { return metricStorage.collect( diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts new file mode 100644 index 00000000000..c10bf7514ed --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/ObservableResult.ts @@ -0,0 +1,26 @@ +/* + * 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 metrics from '@opentelemetry/api-metrics-wip'; +import { AttributeHashMap } from './state/HashMap'; + +export class ObservableResult implements metrics.ObservableResult { + buffer = new AttributeHashMap(); + + observe(value: number, attributes: metrics.Attributes = {}): void { + this.buffer.set(attributes, value); + } +} diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/AsyncMetricStorage.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/AsyncMetricStorage.ts new file mode 100644 index 00000000000..d98ececf7fd --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/AsyncMetricStorage.ts @@ -0,0 +1,100 @@ +/* + * 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 { HrTime } from '@opentelemetry/api'; +import { ObservableCallback } from '@opentelemetry/api-metrics-wip'; +import { Accumulation, Aggregator } from '../aggregator/types'; +import { View } from '../view/View'; +import { createInstrumentDescriptorWithView, InstrumentDescriptor } from '../InstrumentDescriptor'; +import { AttributesProcessor } from '../view/AttributesProcessor'; +import { MetricStorage } from './MetricStorage'; +import { InstrumentationLibrary } from '@opentelemetry/core'; +import { Resource } from '@opentelemetry/resources'; +import { MetricData } from '../export/MetricData'; +import { DeltaMetricProcessor } from './DeltaMetricProcessor'; +import { TemporalMetricProcessor } from './TemporalMetricProcessor'; +import { Maybe } from '../utils'; +import { MetricCollectorHandle } from './MetricCollector'; +import { ObservableResult } from '../ObservableResult'; +import { AttributeHashMap } from './HashMap'; + +/** + * Internal interface. + * + * Stores and aggregates {@link MetricData} for asynchronous instruments. + */ +export class AsyncMetricStorage> implements MetricStorage { + private _deltaMetricStorage: DeltaMetricProcessor; + private _temporalMetricStorage: TemporalMetricProcessor; + + constructor( + private _instrumentDescriptor: InstrumentDescriptor, + aggregator: Aggregator, + private _attributesProcessor: AttributesProcessor, + private _callback: ObservableCallback + ) { + this._deltaMetricStorage = new DeltaMetricProcessor(aggregator); + this._temporalMetricStorage = new TemporalMetricProcessor(aggregator); + } + + private _record(measurements: AttributeHashMap) { + const processed = new AttributeHashMap(); + Array.from(measurements.entries()).forEach(([attributes, value]) => { + processed.set(this._attributesProcessor.process(attributes), value); + }); + this._deltaMetricStorage.batchCumulate(processed); + } + + /** + * Collects the metrics from this storage. The ObservableCallback is invoked + * during the collection. + * + * Note: This is a stateful operation and may reset any interval-related + * state for the MetricCollector. + */ + async collect( + collector: MetricCollectorHandle, + collectors: MetricCollectorHandle[], + resource: Resource, + instrumentationLibrary: InstrumentationLibrary, + sdkStartTime: HrTime, + collectionTime: HrTime, + ): Promise> { + const observableResult = new ObservableResult(); + // TODO: timeout with callback + await this._callback(observableResult); + this._record(observableResult.buffer); + + const accumulations = this._deltaMetricStorage.collect(); + + return this._temporalMetricStorage.buildMetrics( + collector, + collectors, + resource, + instrumentationLibrary, + this._instrumentDescriptor, + accumulations, + sdkStartTime, + collectionTime + ); + } + + static create(view: View, instrument: InstrumentDescriptor, callback: ObservableCallback): AsyncMetricStorage> { + instrument = createInstrumentDescriptorWithView(view, instrument); + const aggregator = view.aggregation.createAggregator(instrument); + return new AsyncMetricStorage(instrument, aggregator, view.attributesProcessor, callback); + } +} diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/DeltaMetricProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/DeltaMetricProcessor.ts index 0e1325ee719..590a78521ee 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/DeltaMetricProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/DeltaMetricProcessor.ts @@ -28,11 +28,12 @@ import { AttributeHashMap } from './HashMap'; * recording to delta data points. */ export class DeltaMetricProcessor> { - private _activeCollectionStorage: AttributeHashMap; + private _activeCollectionStorage = new AttributeHashMap(); + // TODO: find a reasonable mean to clean the memo; + // https://github.com/open-telemetry/opentelemetry-specification/pull/2208 + private _cumulativeMemoStorage = new AttributeHashMap(); - constructor(private _aggregator: Aggregator) { - this._activeCollectionStorage = new AttributeHashMap(); - } + constructor(private _aggregator: Aggregator) {} /** Bind an efficient storage handle for a set of attributes. */ private bind(attributes: Attributes) { @@ -44,6 +45,21 @@ export class DeltaMetricProcessor> { accumulation?.record(value); } + batchCumulate(measurements: AttributeHashMap) { + Array.from(measurements.entries()).forEach(([attributes, value, hashCode]) => { + let accumulation = this._aggregator.createAccumulation(); + accumulation?.record(value); + if (this._cumulativeMemoStorage.has(attributes, hashCode)) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const previous = this._cumulativeMemoStorage.get(attributes, hashCode)!; + accumulation = this._aggregator.diff(previous, accumulation); + } + + this._cumulativeMemoStorage.set(attributes, accumulation, hashCode); + this._activeCollectionStorage.set(attributes, accumulation, hashCode); + }); + } + collect() { const unreportedDelta = this._activeCollectionStorage; this._activeCollectionStorage = new AttributeHashMap(); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/HashMap.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/HashMap.ts index fb8bd4a85a8..879e5db7375 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/HashMap.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/HashMap.ts @@ -53,11 +53,17 @@ export class HashMap { this._valueMap.set(hashCode, value); } + has(key: KeyType, hashCode?: HashCodeType) { + hashCode ??= this._hash(key); + return this._valueMap.has(hashCode); + } + *entries(): IterableIterator<[KeyType, ValueType, HashCodeType]> { const valueIterator = this._valueMap.entries(); let next = valueIterator.next(); while (next.done !== true) { - /** next.value[0] here can not be undefined */ + // next.value[0] here can not be undefined + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion yield [ this._keyMap.get(next.value[0])!, next.value[1], next.value[0]]; next = valueIterator.next(); } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/SyncMetricStorage.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/SyncMetricStorage.ts index cdc1e72b1a4..609f0fc5858 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/SyncMetricStorage.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/SyncMetricStorage.ts @@ -39,7 +39,11 @@ export class SyncMetricStorage> implements Writabl private _deltaMetricStorage: DeltaMetricProcessor; private _temporalMetricStorage: TemporalMetricProcessor; - constructor(private _instrumentDescriptor: InstrumentDescriptor, aggregator: Aggregator, private _attributesProcessor: AttributesProcessor) { + constructor( + private _instrumentDescriptor: InstrumentDescriptor, + aggregator: Aggregator, + private _attributesProcessor: AttributesProcessor + ) { this._deltaMetricStorage = new DeltaMetricProcessor(aggregator); this._temporalMetricStorage = new TemporalMetricProcessor(aggregator); } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts index 1853adc8e5c..9c4936de39a 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts @@ -61,7 +61,7 @@ export class TemporalMetricProcessor { * @param currentAccumulations The current accumulation of metric data from instruments. * @param sdkStartTime The sdk start timestamp. * @param collectionTime The current collection timestamp. - * @returns The {@link MetricData} points or {@code null}. + * @returns The {@link MetricData} points or `null`. */ buildMetrics( collector: MetricCollectorHandle, diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/view/AttributesProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/view/AttributesProcessor.ts index 15b46f53e0d..5ed8d2c0ab5 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/view/AttributesProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/view/AttributesProcessor.ts @@ -23,7 +23,14 @@ import { Attributes } from '@opentelemetry/api-metrics-wip'; * additional dimension(s) from the {@link Context}. */ export abstract class AttributesProcessor { - abstract process(incoming: Attributes, context: Context): Attributes; + /** + * Process the metric instrument attributes. + * + * @param incoming The metric instrument attributes. + * @param context The active context when the instrument is synchronous. + * `undefined` otherwise. + */ + abstract process(incoming: Attributes, context?: Context): Attributes; static Noop() { return NOOP; @@ -31,7 +38,7 @@ export abstract class AttributesProcessor { } export class NoopAttributesProcessor extends AttributesProcessor { - process(incoming: Attributes, _context: Context) { + process(incoming: Attributes, _context?: Context) { return incoming; } } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts index 785d0b56358..fbb1b3b9917 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/Meter.test.ts @@ -14,12 +14,15 @@ * limitations under the License. */ +import { ObservableCallback } from '@opentelemetry/api-metrics-wip'; import * as assert from 'assert'; import { Counter, Histogram, UpDownCounter } from '../src/Instruments'; import { Meter } from '../src/Meter'; import { MeterProviderSharedState } from '../src/state/MeterProviderSharedState'; import { defaultInstrumentationLibrary, defaultResource } from './util'; +const noopObservableCallback: ObservableCallback = _observableResult => {}; + describe('Meter', () => { describe('createCounter', () => { it('should create counter', () => { @@ -44,4 +47,25 @@ describe('Meter', () => { assert(counter instanceof Histogram); }); }); + + describe('createObservableGauge', () => { + it('should create observable gauge', () => { + const meter = new Meter(new MeterProviderSharedState(defaultResource), defaultInstrumentationLibrary); + meter.createObservableGauge('foobar', noopObservableCallback); + }); + }); + + describe('createObservableCounter', () => { + it('should create observable counter', () => { + const meter = new Meter(new MeterProviderSharedState(defaultResource), defaultInstrumentationLibrary); + meter.createObservableCounter('foobar', noopObservableCallback); + }); + }); + + describe('createObservableUpDownCounter', () => { + it('should create observable up-down-counter', () => { + const meter = new Meter(new MeterProviderSharedState(defaultResource), defaultInstrumentationLibrary); + meter.createObservableUpDownCounter('foobar', noopObservableCallback); + }); + }); }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/ObservableResult.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/ObservableResult.test.ts new file mode 100644 index 00000000000..741ee28c55f --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/ObservableResult.test.ts @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as assert from 'assert'; +import { ObservableResult } from '../src/ObservableResult'; +import { commonAttributes, commonValues } from './util'; + +describe('ObservableResult', () => { + describe('observe', () => { + it('should observe', () => { + const observableResult = new ObservableResult(); + for (const value of commonValues) { + for (const attributes of commonAttributes) { + observableResult.observe(value, attributes); + } + } + }); + + it('should deduplicate observations', () => { + const observableResult = new ObservableResult(); + observableResult.observe(1, {}); + observableResult.observe(2, {}); + + assert.strictEqual(observableResult.buffer.size, 1); + assert(observableResult.buffer.has({})); + assert.strictEqual(observableResult.buffer.get({}), 2); + }); + }); +}); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/state/AsyncMetricStorage.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/AsyncMetricStorage.test.ts new file mode 100644 index 00000000000..555d1f50493 --- /dev/null +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/AsyncMetricStorage.test.ts @@ -0,0 +1,198 @@ +/* + * 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 { hrTime } from '@opentelemetry/core'; +import * as assert from 'assert'; + +import { SumAggregator } from '../../src/aggregator'; +import { AggregationTemporality } from '../../src/export/AggregationTemporality'; +import { PointDataType } from '../../src/export/MetricData'; +import { MetricCollectorHandle } from '../../src/state/MetricCollector'; +import { AsyncMetricStorage } from '../../src/state/AsyncMetricStorage'; +import { NoopAttributesProcessor } from '../../src/view/AttributesProcessor'; +import { assertMetricData, assertPointData, defaultInstrumentationLibrary, defaultInstrumentDescriptor, defaultResource } from '../util'; +import { ObservableCallback } from '@opentelemetry/api-metrics-wip'; + +const deltaCollector: MetricCollectorHandle = { + aggregatorTemporality: AggregationTemporality.DELTA, +}; + +const cumulativeCollector: MetricCollectorHandle = { + aggregatorTemporality: AggregationTemporality.CUMULATIVE, +}; + +const sdkStartTime = hrTime(); + +class ObservableCallbackDelegate { + private _delegate?: ObservableCallback; + setDelegate(delegate: ObservableCallback) { + this._delegate = delegate; + } + + getCallback(): ObservableCallback { + return observableResult => { + this._delegate?.(observableResult); + }; + } +} + +describe('AsyncMetricStorage', () => { + describe('collect', () => { + describe('Delta Collector', () => { + const collectors = [deltaCollector]; + it('should collect and reset memos', async () => { + const delegate = new ObservableCallbackDelegate(); + const metricStorage = new AsyncMetricStorage( + defaultInstrumentDescriptor, + new SumAggregator(), + new NoopAttributesProcessor(), + delegate.getCallback(), + ); + + delegate.setDelegate(observableResult => { + observableResult.observe(1, { key: '1' }); + observableResult.observe(2, { key: '2' }); + observableResult.observe(3, { key: '3' }); + }); + { + const metric = await metricStorage.collect( + deltaCollector, + collectors, + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 3); + assertPointData(metric.pointData[0], { key: '1' }, 1); + assertPointData(metric.pointData[1], { key: '2' }, 2); + assertPointData(metric.pointData[2], { key: '3' }, 3); + } + + delegate.setDelegate(observableResult => {}); + // The attributes should not be memorized if no measurement was reported. + { + const metric = await metricStorage.collect( + deltaCollector, + collectors, + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 0); + } + + delegate.setDelegate(observableResult => { + observableResult.observe(4, { key: '1' }); + observableResult.observe(5, { key: '2' }); + observableResult.observe(6, { key: '3' }); + }); + { + const metric = await metricStorage.collect( + deltaCollector, + [deltaCollector], + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 3); + // all values were diffed. + assertPointData(metric.pointData[0], { key: '1' }, 3); + assertPointData(metric.pointData[1], { key: '2' }, 3); + assertPointData(metric.pointData[2], { key: '3' }, 3); + } + }); + }); + + describe('Cumulative Collector', () => { + const collectors = [cumulativeCollector]; + it('should collect cumulative metrics', async () => { + const delegate = new ObservableCallbackDelegate(); + const metricStorage = new AsyncMetricStorage( + defaultInstrumentDescriptor, + new SumAggregator(), + new NoopAttributesProcessor(), + delegate.getCallback(), + ); + + delegate.setDelegate(observableResult => { + observableResult.observe(1, { key: '1' }); + observableResult.observe(2, { key: '2' }); + observableResult.observe(3, { key: '3' }); + }); + { + const metric = await metricStorage.collect( + cumulativeCollector, + collectors, + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 3); + assertPointData(metric.pointData[0], { key: '1' }, 1); + assertPointData(metric.pointData[1], { key: '2' }, 2); + assertPointData(metric.pointData[2], { key: '3' }, 3); + } + + delegate.setDelegate(observableResult => {}); + // The attributes should be memorized even if no measurement was reported. + { + const metric = await metricStorage.collect( + cumulativeCollector, + collectors, + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 3); + assertPointData(metric.pointData[0], { key: '1' }, 1); + assertPointData(metric.pointData[1], { key: '2' }, 2); + assertPointData(metric.pointData[2], { key: '3' }, 3); + } + + delegate.setDelegate(observableResult => { + observableResult.observe(4, { key: '1' }); + observableResult.observe(5, { key: '2' }); + observableResult.observe(6, { key: '3' }); + }); + { + const metric = await metricStorage.collect( + cumulativeCollector, + collectors, + defaultResource, + defaultInstrumentationLibrary, + sdkStartTime, + hrTime()); + + assertMetricData(metric, PointDataType.SINGULAR); + assert.strictEqual(metric.pointData.length, 3); + assertPointData(metric.pointData[0], { key: '1' }, 4); + assertPointData(metric.pointData[1], { key: '2' }, 5); + assertPointData(metric.pointData[2], { key: '3' }, 6); + } + }); + }); + }); +}); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/state/DeltaMetricProcessor.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/DeltaMetricProcessor.test.ts index 8d606d64b9a..73aa735c059 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/state/DeltaMetricProcessor.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/DeltaMetricProcessor.test.ts @@ -18,40 +18,89 @@ import * as api from '@opentelemetry/api'; import * as assert from 'assert'; import { DropAggregator, SumAggregator } from '../../src/aggregator'; import { DeltaMetricProcessor } from '../../src/state/DeltaMetricProcessor'; +import { AttributeHashMap } from '../../src/state/HashMap'; import { commonAttributes, commonValues } from '../util'; describe('DeltaMetricProcessor', () => { describe('record', () => { it('no exceptions on record with DropAggregator', () => { - const metricStorage = new DeltaMetricProcessor(new DropAggregator()); + const metricProcessor = new DeltaMetricProcessor(new DropAggregator()); for (const value of commonValues) { for (const attributes of commonAttributes) { - metricStorage.record(value, attributes, api.context.active()); + metricProcessor.record(value, attributes, api.context.active()); } } }); it('no exceptions on record with no-drop aggregator', () => { - const metricStorage = new DeltaMetricProcessor(new SumAggregator()); + const metricProcessor = new DeltaMetricProcessor(new SumAggregator()); for (const value of commonValues) { for (const attributes of commonAttributes) { - metricStorage.record(value, attributes, api.context.active()); + metricProcessor.record(value, attributes, api.context.active()); } } }); }); + describe('batchCumulate', () => { + it('no exceptions on batchCumulate with DropAggregator', () => { + const metricProcessor = new DeltaMetricProcessor(new DropAggregator()); + + const measurements = new AttributeHashMap(); + for (const value of commonValues) { + for (const attributes of commonAttributes) { + measurements.set(attributes, value); + } + } + metricProcessor.batchCumulate(measurements); + }); + + it('no exceptions on record with no-drop aggregator', () => { + const metricProcessor = new DeltaMetricProcessor(new SumAggregator()); + + const measurements = new AttributeHashMap(); + for (const value of commonValues) { + for (const attributes of commonAttributes) { + measurements.set(attributes, value); + } + } + metricProcessor.batchCumulate(measurements); + }); + + it('should compute the diff of accumulations', () => { + const metricProcessor = new DeltaMetricProcessor(new SumAggregator()); + + { + const measurements = new AttributeHashMap(); + measurements.set({}, 10); + metricProcessor.batchCumulate(measurements); + const accumulations = metricProcessor.collect(); + const accumulation = accumulations.get({}); + assert.strictEqual(accumulation?.toPoint(), 10); + } + + { + const measurements = new AttributeHashMap(); + measurements.set({}, 21); + metricProcessor.batchCumulate(measurements); + const accumulations = metricProcessor.collect(); + const accumulation = accumulations.get({}); + assert.strictEqual(accumulation?.toPoint(), 11); + } + }); + }); + describe('collect', () => { it('should export', () => { - const metricStorage = new DeltaMetricProcessor(new SumAggregator()); + const metricProcessor = new DeltaMetricProcessor(new SumAggregator()); - metricStorage.record(1, { attribute: '1' }, api.ROOT_CONTEXT); - metricStorage.record(2, { attribute: '1' }, api.ROOT_CONTEXT); - metricStorage.record(1, { attribute: '2' }, api.ROOT_CONTEXT); + metricProcessor.record(1, { attribute: '1' }, api.ROOT_CONTEXT); + metricProcessor.record(2, { attribute: '1' }, api.ROOT_CONTEXT); + metricProcessor.record(1, { attribute: '2' }, api.ROOT_CONTEXT); - let accumulations = metricStorage.collect(); + let accumulations = metricProcessor.collect(); assert.strictEqual(accumulations.size, 2); { const accumulation = accumulations.get({ attribute: '1' }); @@ -63,7 +112,7 @@ describe('DeltaMetricProcessor', () => { } /** the accumulations shall be reset. */ - accumulations = metricStorage.collect(); + accumulations = metricProcessor.collect(); assert.strictEqual(accumulations.size, 0); }); }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/state/HashMap.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/HashMap.test.ts index 84224f3d948..94d399d5ab3 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/state/HashMap.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/state/HashMap.test.ts @@ -39,6 +39,23 @@ describe('HashMap', () => { }); }); + describe('has', () => { + it('should return if the key exists in the value map', () => { + const map = new HashMap(hashAttributes); + const hash = hashAttributes({ foo: 'bar' }); + + // with pinned hash code + assert.strictEqual(map.has({}, hash), false); + assert.strictEqual(map.has({ foo: 'bar' }, hash), false); + + map.set({ foo: 'bar' }, 1); + // with pinned hash code + assert.strictEqual(map.has({}, hash), true); + // with attributes object. + assert.strictEqual(map.has({ foo: 'bar' }), true); + }); + }); + describe('entries', () => { it('iterating with entries', () => { const map = new HashMap(hashAttributes); diff --git a/packages/exporter-trace-otlp-http/README.md b/packages/exporter-trace-otlp-http/README.md index e5413d7e528..f03ca83ff58 100644 --- a/packages/exporter-trace-otlp-http/README.md +++ b/packages/exporter-trace-otlp-http/README.md @@ -27,7 +27,7 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/traces + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/traces headers: {}, // an optional object containing custom headers to be sent with each request concurrencyLimit: 10, // an optional limit on pending requests }; @@ -56,7 +56,7 @@ const { BasicTracerProvider, BatchSpanProcessor } = require('@opentelemetry/sdk- const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/traces + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/traces headers: { foo: 'bar' }, // an optional object containing custom headers to be sent with each request will only work with http diff --git a/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts b/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts index e68c5712394..91ee1014234 100644 --- a/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts +++ b/packages/exporter-trace-otlp-http/src/platform/browser/OTLPTraceExporter.ts @@ -23,7 +23,7 @@ import { getEnv, baggageUtils } from '@opentelemetry/core'; import { appendResourcePathToUrlIfNotPresent } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Web diff --git a/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts b/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts index 737980362a8..82bdff3aef9 100644 --- a/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts +++ b/packages/exporter-trace-otlp-http/src/platform/node/OTLPTraceExporter.ts @@ -23,7 +23,7 @@ import { getEnv, baggageUtils } from '@opentelemetry/core'; import { appendResourcePathToUrlIfNotPresent } from '../../util'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Node diff --git a/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts b/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts index 0a709a953f8..a66a7c59d08 100644 --- a/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts +++ b/packages/exporter-trace-otlp-http/test/browser/CollectorTraceExporter.test.ts @@ -294,7 +294,7 @@ describe('OTLPTraceExporter - browser (getDefaultUrl)', () => { setTimeout(() => { assert.strictEqual( collectorExporter['url'], - 'http://localhost:55681/v1/traces' + 'http://localhost:4318/v1/traces' ); done(); }); diff --git a/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts b/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts index 33c9559dc9d..af543bae221 100644 --- a/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts +++ b/packages/exporter-trace-otlp-http/test/node/CollectorTraceExporter.test.ts @@ -325,7 +325,7 @@ describe('OTLPTraceExporter - node with json over http', () => { setTimeout(() => { assert.strictEqual( collectorExporter['url'], - 'http://localhost:55681/v1/traces' + 'http://localhost:4318/v1/traces' ); done(); }); diff --git a/packages/exporter-trace-otlp-proto/README.md b/packages/exporter-trace-otlp-proto/README.md index 81268201ad7..19e91f0f46a 100644 --- a/packages/exporter-trace-otlp-proto/README.md +++ b/packages/exporter-trace-otlp-proto/README.md @@ -24,7 +24,7 @@ const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto'); const collectorOptions = { - url: '', // url is optional and can be omitted - default is http://localhost:55681/v1/traces + url: '', // url is optional and can be omitted - default is http://localhost:4318/v1/traces headers: { foo: 'bar' }, //an optional object containing custom headers to be sent with each request will only work with http diff --git a/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts b/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts index b17e3c0633f..9b3c5a6effc 100644 --- a/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts +++ b/packages/exporter-trace-otlp-proto/src/OTLPTraceExporter.ts @@ -26,7 +26,7 @@ import { ServiceClientType } from './types'; import { getEnv, baggageUtils } from '@opentelemetry/core'; const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces'; -const DEFAULT_COLLECTOR_URL=`http://localhost:55681${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`; /** * Collector Trace Exporter for Node with protobuf