Skip to content

Commit

Permalink
Merge branch 'main' into karma-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Jan 20, 2022
2 parents b651cf6 + e32879a commit 78ada97
Show file tree
Hide file tree
Showing 34 changed files with 595 additions and 73 deletions.
13 changes: 9 additions & 4 deletions examples/basic-tracer-node/docker/ot/collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions examples/basic-tracer-node/docker/ot/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions examples/otlp-exporter-node/docker/collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ receivers:
protocols:
grpc:
http:
cors_allowed_origins:
- http://*
- https://*
cors:
allowed_origins:
- http://*
- https://*

exporters:
zipkin:
Expand All @@ -17,6 +18,9 @@ processors:
batch:

service:
telemetry:
logs:
level: "debug"
pipelines:
traces:
receivers: [otlp]
Expand Down
8 changes: 4 additions & 4 deletions examples/otlp-exporter-node/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/otlp-exporter-node/metrics.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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({
Expand Down
21 changes: 12 additions & 9 deletions examples/otlp-exporter-node/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion examples/otlp-exporter-node/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics
url: '<opentelemetry-collector-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
};
Expand All @@ -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: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics
url: '<opentelemetry-collector-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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics
url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics
};
const exporter = new OTLPMetricExporter(collectorOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 25 additions & 12 deletions experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand All @@ -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<MetricData[]> {
const result = await Promise.all(Array.from(this._metricStorageRegistry.values()).map(metricStorage => {
return metricStorage.collect(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<number>();

observe(value: number, attributes: metrics.Attributes = {}): void {
this.buffer.set(attributes, value);
}
}
Loading

0 comments on commit 78ada97

Please sign in to comment.