Skip to content

Commit

Permalink
Merge branch 'main' into doc-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Mar 5, 2022
2 parents 6d6cc8d + a0c1236 commit e9633fd
Show file tree
Hide file tree
Showing 34 changed files with 749 additions and 99 deletions.
73 changes: 25 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ This is the JavaScript version of [OpenTelemetry](https://opentelemetry.io/), a

## Compatibility Matrix

| API Version | Core version | Experimental Packages | Contrib Version |
| ----------- |--------------| --------------------- |-------------------------|
| 1.0.x | 1.x | 0.26.x | 0.26.x |
| 1.0.x | 0.26.x | ----- | ------ |
| 1.0.x | 0.25.x | ----- | ------ |
| 1.0.x | 0.24.x | ----- | 0.24.x |
| 1.0.x | 0.23.x | ----- | 0.23.x |
| 1.0.x | 0.22.x | ----- | 0.22.x |
| 0.21.x | 0.21.x | ----- | 0.21.x |
| 0.20.x | 0.20.x | ----- | 0.20.x |
| v1.0.0-rc.3 | 0.19.x | ----- | 0.16.x |
| 0.18.x | 0.18.x | ----- | 0.14.x |
| | 0.17.x | ----- | ------ |
| | 0.16.x | ----- | ------ |
| | 0.15.x | ----- | 0.13.x |
| | 0.14.x | ----- | 0.12.x |
| | 0.13.x | ----- | ------ |
| | 0.12.x | ----- | 0.11.x |
| | 0.11.x | ----- | 0.10.x |
| API Version | Core version | Experimental Packages |
| ----------- |--------------| --------------------- |
| 1.0.x | 1.x | 0.26.x |
| 1.0.x | 0.26.x | ----- |
| 1.0.x | 0.25.x | ----- |
| 1.0.x | 0.24.x | ----- |
| 1.0.x | 0.23.x | ----- |
| 1.0.x | 0.22.x | ----- |
| 0.21.x | 0.21.x | ----- |
| 0.20.x | 0.20.x | ----- |
| v1.0.0-rc.3 | 0.19.x | ----- |
| 0.18.x | 0.18.x | ----- |
| | 0.17.x | ----- |
| | 0.16.x | ----- |
| | 0.15.x | ----- |
| | 0.14.x | ----- |
| | 0.13.x | ----- |
| | 0.12.x | ----- |
| | 0.11.x | ----- |

## Versioning

Expand Down Expand Up @@ -239,7 +239,11 @@ See the [OpenTelemetry registry](https://opentelemetry.io/registry/?language=js&

### Instrumentations

OpenTelemetry can collect tracing data automatically using instrumentations. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for:
OpenTelemetry can collect tracing data automatically using instrumentations.

To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, Vendor/Users can [write an instrumentation yourself](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/instrumentation-guide.md).

Currently, OpenTelemetry supports automatic tracing for:

#### Node Instrumentations

Expand All @@ -250,17 +254,7 @@ OpenTelemetry can collect tracing data automatically using instrumentations. Ven

##### Contrib

These plugins are hosted at <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/node>

- [@opentelemetry/instrumentation-mongodb][otel-contrib-instrumentation-mongodb]
- [@opentelemetry/instrumentation-mysql][otel-contrib-instrumentation-mysql]
- [@opentelemetry/instrumentation-pg][otel-contrib-instrumentation-pg]
- [@opentelemetry/instrumentation-redis][otel-contrib-instrumentation-redis]
- [@opentelemetry/instrumentation-ioredis][otel-contrib-instrumentation-ioredis]
- [@opentelemetry/instrumentation-express][otel-contrib-instrumentation-express]
- [@opentelemetry/instrumentation-dns][otel-contrib-instrumentation-dns]
- [@opentelemetry/instrumentation-hapi][otel-contrib-instrumentation-hapi]
- [@opentelemetry/instrumentation-koa][otel-contrib-instrumentation-koa]
These instrumentations are hosted at <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/node>

#### Web Instrumentations

Expand All @@ -273,11 +267,6 @@ These plugins are hosted at <https://github.com/open-telemetry/opentelemetry-js-

These instrumentations are hosted at <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/web>

- [@opentelemetry/instrumentation-document-load][otel-contrib-instrumentation-document-load]
- [@opentelemetry/instrumentation-user-interaction][otel-contrib-instrumentation-user-interaction]

To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, you can [write an instrumentation yourself](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/instrumentation-guide.md).

### Shims

| Package | Description |
Expand Down Expand Up @@ -557,16 +546,4 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[otel-propagator-b3]: https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-propagator-b3
[generate-api-documentation]: https://github.com/open-telemetry/opentelemetry-js/blob/main/CONTRIBUTING.md#generating-api-documentation

[otel-contrib-instrumentation-dns]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns
[otel-contrib-instrumentation-ioredis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis
[otel-contrib-instrumentation-mongodb]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb
[otel-contrib-instrumentation-mysql]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql
[otel-contrib-instrumentation-pg]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg
[otel-contrib-instrumentation-redis]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis
[otel-contrib-instrumentation-express]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express
[otel-contrib-instrumentation-user-interaction]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-user-interaction
[otel-contrib-instrumentation-document-load]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/web/opentelemetry-instrumentation-document-load
[otel-contrib-instrumentation-hapi]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi
[otel-contrib-instrumentation-koa]: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa

[spec-versioning]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@types/webpack-env": "1.16.3",
"codecov": "3.8.3",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"codecov": "3.8.3",
"cpx": "1.5.0",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"babel-loader": "8.2.3",
"codecov": "3.8.3",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"babel-loader": "8.2.3",
"codecov": "3.8.3",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"codecov": "3.8.3",
"cpx": "1.5.0",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@types/node": "14.17.33",
"@types/sinon": "10.0.6",
"codecov": "3.8.3",
"karma": "6.3.14",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { View } from './view/View';
/**
* Supported types of metric instruments.
*/
export enum InstrumentType {
export enum InstrumentType {
COUNTER = 'COUNTER',
HISTOGRAM = 'HISTOGRAM',
UP_DOWN_COUNTER = 'UP_DOWN_COUNTER',
Expand Down Expand Up @@ -56,3 +56,10 @@ export function createInstrumentDescriptorWithView(view: View, instrument: Instr
valueType: instrument.valueType,
};
}

export function isDescriptorCompatibleWith(descriptor: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor) {
return descriptor.name === otherDescriptor.name
&& descriptor.unit === otherDescriptor.unit
&& descriptor.type === otherDescriptor.type
&& descriptor.valueType === otherDescriptor.valueType;
}
26 changes: 12 additions & 14 deletions experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import { Counter, Histogram, UpDownCounter } from './Instruments';
import { MeterProviderSharedState } from './state/MeterProviderSharedState';
import { MultiMetricStorage } from './state/MultiWritableMetricStorage';
import { SyncMetricStorage } from './state/SyncMetricStorage';
import { MetricStorage } from './state/MetricStorage';
import { MetricData } from './export/MetricData';
import { isNotNullish } from './utils';
import { MetricCollectorHandle } from './state/MetricCollector';
import { HrTime } from '@opentelemetry/api';
import { AsyncMetricStorage } from './state/AsyncMetricStorage';
import { WritableMetricStorage } from './state/WritableMetricStorage';
import { MetricStorageRegistry } from './state/MetricStorageRegistry';

/**
* This class implements the {@link metrics.Meter} interface.
*/
export class Meter implements metrics.Meter {
private _metricStorageRegistry = new Map<string, MetricStorage>();
private _metricStorageRegistry = new MetricStorageRegistry();

constructor(private _meterProviderSharedState: MeterProviderSharedState, private _instrumentationLibrary: InstrumentationLibrary) {
this._meterProviderSharedState.meters.push(this);
Expand Down Expand Up @@ -101,26 +102,23 @@ export class Meter implements metrics.Meter {
this._registerAsyncMetricStorage(descriptor, callback);
}

private _registerMetricStorage(descriptor: InstrumentDescriptor) {
private _registerMetricStorage(descriptor: InstrumentDescriptor): WritableMetricStorage {
const views = this._meterProviderSharedState.viewRegistry.findViews(descriptor, this._instrumentationLibrary);
const storages = views.map(view => {
const storage = SyncMetricStorage.create(view, descriptor);
// TODO: handle conflicts
this._metricStorageRegistry.set(descriptor.name, storage);
return storage;
});
if (storages.length === 1) {
const storages = views.map(view => this._metricStorageRegistry.register(SyncMetricStorage.create(view, descriptor)))
.filter(isNotNullish);

if (storages.length === 1) {
return storages[0];
}

// This will be a no-op WritableMetricStorage when length is null.
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);
this._metricStorageRegistry.register(AsyncMetricStorage.create(view, descriptor, callback));
});
}

Expand All @@ -131,7 +129,7 @@ export class Meter implements metrics.Meter {
* @returns the list of {@link MetricData} collected.
*/
async collect(collector: MetricCollectorHandle, collectionTime: HrTime): Promise<MetricData[]> {
const result = await Promise.all(Array.from(this._metricStorageRegistry.values()).map(metricStorage => {
const result = await Promise.all(this._metricStorageRegistry.getStorages().map(metricStorage => {
return metricStorage.collect(
collector,
this._meterProviderSharedState.metricCollectors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ 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 {
createInstrumentDescriptorWithView,
InstrumentDescriptor
} from '../InstrumentDescriptor';
import { AttributesProcessor } from '../view/AttributesProcessor';
import { MetricStorage } from './MetricStorage';
import { InstrumentationLibrary } from '@opentelemetry/core';
Expand All @@ -36,16 +39,17 @@ import { AttributeHashMap } from './HashMap';
*
* Stores and aggregates {@link MetricData} for asynchronous instruments.
*/
export class AsyncMetricStorage<T extends Maybe<Accumulation>> implements MetricStorage {
export class AsyncMetricStorage<T extends Maybe<Accumulation>> extends MetricStorage {
private _deltaMetricStorage: DeltaMetricProcessor<T>;
private _temporalMetricStorage: TemporalMetricProcessor<T>;

constructor(
private _instrumentDescriptor: InstrumentDescriptor,
_instrumentDescriptor: InstrumentDescriptor,
aggregator: Aggregator<T>,
private _attributesProcessor: AttributesProcessor,
private _callback: ObservableCallback
) {
super(_instrumentDescriptor);
this._deltaMetricStorage = new DeltaMetricProcessor(aggregator);
this._temporalMetricStorage = new TemporalMetricProcessor(aggregator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,44 @@ import { Resource } from '@opentelemetry/resources';
import { MetricData } from '../export/MetricData';
import { Maybe } from '../utils';
import { MetricCollectorHandle } from './MetricCollector';
import { createInstrumentDescriptor, InstrumentDescriptor } from '../InstrumentDescriptor';

/**
* Internal interface.
*
* Represents a storage from which we can collect metrics.
*/
export interface MetricStorage {
export abstract class MetricStorage {
constructor(protected _instrumentDescriptor: InstrumentDescriptor) {
}

/**
* Collects the metrics from this storage.
*
* Note: This is a stateful operation and may reset any interval-related
* state for the MetricCollector.
*/
collect(
abstract collect(
collector: MetricCollectorHandle,
collectors: MetricCollectorHandle[],
resource: Resource,
instrumentationLibrary: InstrumentationLibrary,
sdkStartTime: HrTime,
collectionTime: HrTime,
): Promise<Maybe<MetricData>>;

getInstrumentDescriptor(): InstrumentDescriptor{
return this._instrumentDescriptor;
}

updateDescription(description: string): void{
this._instrumentDescriptor = createInstrumentDescriptor(
this._instrumentDescriptor.name,
this._instrumentDescriptor.type,
{
description: description,
valueType: this._instrumentDescriptor.valueType,
unit: this._instrumentDescriptor.unit
});
}
}
Loading

0 comments on commit e9633fd

Please sign in to comment.