Skip to content

Commit

Permalink
Merge branch 'main' into add-exporter-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed May 11, 2022
2 parents 5da6ce2 + ac578e9 commit 6ee89b0
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 182 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
* feat: warn when hooked module is already loaded [#2926](https://github.com/open-telemetry/opentelemetry-js/pull/2926) @nozik
* feat: implement OSDetector [#2927](https://github.com/open-telemetry/opentelemetry-js/pull/2927) @rauno56
* feat: implement HostDetector [#2921](https://github.com/open-telemetry/opentelemetry-js/pull/2921) @rauno56
* feat(opentelemetry-core): add InstrumentationScope [#2959](https://github.com/open-telemetry/opentelemetry-js/pull/2959) @pichlermarc

### :bug: (Bug Fix)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry

- [Gerhard Stöbich](https://github.com/Flarna), Dynatrace
- [John Bley](https://github.com/johnbley), Splunk
- [Marc Pichler](https://github.com/pichlermarc), Dynatrace
- [Mark Wolff](https://github.com/markwolff), Microsoft
- [Matthew Wear](https://github.com/mwear), LightStep
- [Naseem K. Ullah](https://github.com/naseemkullah), Transit
Expand Down
3 changes: 3 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* refactor(metrics-sdk): rename InstrumentationLibrary -> InstrumentationScope #2959 @pichlermarc

### :rocket: (Enhancement)

* feat(exporters): update proto version and use otlp-transformer #2929 @pichlermarc

### :bug: (Bug Fix)

* fix(opentelemetry-instrumentation-http): use correct origin when port is `null` #2948 @danielgblanco
* fix(otlp-exporter-base): include esm and esnext in package files #2952 @dyladan

### :books: (Refine Doc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe('OTLPMetricExporter - web', () => {

ensureCounterIsCorrect(
metric1,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].startTime)
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].startTime)
);


Expand All @@ -126,8 +126,8 @@ describe('OTLPMetricExporter - web', () => {
);
ensureObservableGaugeIsCorrect(
metric2,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].startTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].startTime),
6,
'double-observable-gauge2'
);
Expand All @@ -138,8 +138,8 @@ describe('OTLPMetricExporter - web', () => {
);
ensureHistogramIsCorrect(
metric3,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[2].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[2].dataPoints[0].startTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[2].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[2].dataPoints[0].startTime),
[0, 100],
[0, 2, 0]
);
Expand Down Expand Up @@ -221,8 +221,8 @@ describe('OTLPMetricExporter - web', () => {
assert.ok(typeof metric1 !== 'undefined', "metric doesn't exist");
ensureCounterIsCorrect(
metric1,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].startTime)
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].startTime)
);

assert.ok(
Expand All @@ -231,8 +231,8 @@ describe('OTLPMetricExporter - web', () => {
);
ensureObservableGaugeIsCorrect(
metric2,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].startTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].startTime),
6,
'double-observable-gauge2'
);
Expand All @@ -243,8 +243,8 @@ describe('OTLPMetricExporter - web', () => {
);
ensureHistogramIsCorrect(
metric3,
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[2].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[2].dataPoints[0].startTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[2].dataPoints[0].endTime),
hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[2].dataPoints[0].startTime),
[0, 100],
[0, 2, 0]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@opentelemetry/api-metrics';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import { InstrumentationLibrary, VERSION } from '@opentelemetry/core';
import { InstrumentationScope, VERSION } from '@opentelemetry/core';
import {
AggregationTemporality,
ExplicitBucketHistogramAggregation,
Expand Down Expand Up @@ -171,7 +171,7 @@ export const mockedResources: Resource[] = [
new Resource({ name: 'resource 2' }),
];

export const mockedInstrumentationLibraries: InstrumentationLibrary[] = [
export const mockedInstrumentationLibraries: InstrumentationScope[] = [
{
name: 'lib1',
version: '0.0.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,22 @@ describe('OTLPMetricExporter - node with json over http', () => {
assert.ok(typeof metric1 !== 'undefined', "counter doesn't exist");
ensureCounterIsCorrect(
metric1,
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[0].dataPoints[0].startTime)
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[0].dataPoints[0].startTime)
);
assert.ok(typeof metric2 !== 'undefined', "observable gauge doesn't exist");
ensureObservableGaugeIsCorrect(
metric2,
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].startTime),
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].startTime),
6,
'double-observable-gauge2'
);
assert.ok(typeof metric3 !== 'undefined', "histogram doesn't exist");
ensureHistogramIsCorrect(
metric3,
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.instrumentationLibraryMetrics[0].metrics[1].dataPoints[0].startTime),
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].endTime),
core.hrTimeToNanoseconds(metrics.scopeMetrics[0].metrics[1].dataPoints[0].startTime),
[0, 100],
[0, 2, 0]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ResourceMetrics,
InstrumentType,
DataPointType,
InstrumentationLibraryMetrics,
ScopeMetrics,
MetricData,
DataPoint,
Histogram,
Expand Down Expand Up @@ -178,15 +178,15 @@ export class PrometheusSerializer {

serialize(resourceMetrics: ResourceMetrics): string {
let str = '';
for (const instrumentationLibraryMetrics of resourceMetrics.instrumentationLibraryMetrics) {
str += this.serializeInstrumentationLibraryMetrics(instrumentationLibraryMetrics);
for (const scopeMetrics of resourceMetrics.scopeMetrics) {
str += this.serializeScopeMetrics(scopeMetrics);
}
return str;
}

serializeInstrumentationLibraryMetrics(instrumentationLibraryMetrics: InstrumentationLibraryMetrics) {
serializeScopeMetrics(scopeMetrics: ScopeMetrics) {
let str = '';
for (const metric of instrumentationLibraryMetrics.metrics) {
for (const metric of scopeMetrics.metrics) {
str += this.serializeMetricData(metric) + '\n';
}
return str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const metric = resourceMetrics.instrumentationLibraryMetrics[0].metrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const metric = resourceMetrics.scopeMetrics[0].metrics[0];
assert.strictEqual(metric.dataPointType, DataPointType.SINGULAR);
const pointData = metric.dataPoints as DataPoint<number>[];
assert.strictEqual(pointData.length, 1);
Expand Down Expand Up @@ -122,9 +122,9 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const metric = resourceMetrics.instrumentationLibraryMetrics[0].metrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const metric = resourceMetrics.scopeMetrics[0].metrics[0];
assert.strictEqual(metric.dataPointType, DataPointType.HISTOGRAM);
const pointData = metric.dataPoints as DataPoint<Histogram>[];
assert.strictEqual(pointData.length, 1);
Expand Down Expand Up @@ -180,11 +180,11 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const instrumentationLibraryMetrics = resourceMetrics.instrumentationLibraryMetrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const scopeMetrics = resourceMetrics.scopeMetrics[0];

const result = serializer.serializeInstrumentationLibraryMetrics(instrumentationLibraryMetrics);
const result = serializer.serializeScopeMetrics(scopeMetrics);
return result;
}

Expand Down Expand Up @@ -232,11 +232,11 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const instrumentationLibraryMetrics = resourceMetrics.instrumentationLibraryMetrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const scopeMetrics = resourceMetrics.scopeMetrics[0];

const result = serializer.serializeInstrumentationLibraryMetrics(instrumentationLibraryMetrics);
const result = serializer.serializeScopeMetrics(scopeMetrics);
return result;
}

Expand Down Expand Up @@ -277,9 +277,9 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const metric = resourceMetrics.instrumentationLibraryMetrics[0].metrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const metric = resourceMetrics.scopeMetrics[0].metrics[0];
assert.strictEqual(metric.dataPointType, DataPointType.SINGULAR);
const pointData = metric.dataPoints as DataPoint<number>[];
assert.strictEqual(pointData.length, 1);
Expand Down Expand Up @@ -316,9 +316,9 @@ describe('PrometheusSerializer', () => {

const resourceMetrics = await reader.collect();
assert(resourceMetrics != null);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics.length, 1);
assert.strictEqual(resourceMetrics.instrumentationLibraryMetrics[0].metrics.length, 1);
const metric = resourceMetrics.instrumentationLibraryMetrics[0].metrics[0];
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1);
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1);
const metric = resourceMetrics.scopeMetrics[0].metrics[0];
assert.strictEqual(metric.dataPointType, DataPointType.SINGULAR);
const pointData = metric.dataPoints as DataPoint<number>[];
assert.strictEqual(pointData.length, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ export const getRequestInfo = (
if (!pathname && optionsParsed.path) {
pathname = url.parse(optionsParsed.path).pathname || '/';
}
origin = `${optionsParsed.protocol || 'http:'}//${
optionsParsed.host || `${optionsParsed.hostname}:${optionsParsed.port}`
}`;
const hostname = optionsParsed.host || (optionsParsed.port != null ? `${optionsParsed.hostname}${optionsParsed.port}` : optionsParsed.hostname);
origin = `${optionsParsed.protocol || 'http:'}//${hostname}`;
}

const headers = optionsParsed.headers ?? {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ describe('Utility', () => {
...urlParsed,
pathname: undefined,
};
const urlParsedWithUndefinedHostAndPort = {
...urlParsed,
host: undefined,
port: undefined,
};
const urlParsedWithUndefinedHostAndNullPort = {
...urlParsed,
host: undefined,
port: null,
};
const whatWgUrl = new url.URL(webUrl);
for (const param of [
webUrl,
urlParsed,
urlParsedWithoutPathname,
urlParsedWithUndefinedHostAndPort,
urlParsedWithUndefinedHostAndNullPort,
whatWgUrl,
]) {
const result = utils.getRequestInfo(param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { HrTime } from '@opentelemetry/api';
import { MetricAttributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Histogram } from '../aggregator/types';
Expand Down Expand Up @@ -56,14 +56,14 @@ export interface HistogramMetricData extends BaseMetricData {
*/
export type MetricData = SingularMetricData | HistogramMetricData;

export interface InstrumentationLibraryMetrics {
instrumentationLibrary: InstrumentationLibrary;
export interface ScopeMetrics {
scope: InstrumentationScope;
metrics: MetricData[];
}

export interface ResourceMetrics {
resource: Resource;
instrumentationLibraryMetrics: InstrumentationLibraryMetrics[];
scopeMetrics: ScopeMetrics[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import { HrTime } from '@opentelemetry/api';
import { hrTime, InstrumentationLibrary } from '@opentelemetry/core';
import { hrTime, InstrumentationScope } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { instrumentationLibraryId } from '../utils';
import { instrumentationScopeId } from '../utils';
import { ViewRegistry } from '../view/ViewRegistry';
import { MeterSharedState } from './MeterSharedState';
import { MetricCollector } from './MetricCollector';
Expand All @@ -35,11 +35,11 @@ export class MeterProviderSharedState {

constructor(public resource: Resource) {}

getMeterSharedState(instrumentationLibrary: InstrumentationLibrary) {
const id = instrumentationLibraryId(instrumentationLibrary);
getMeterSharedState(instrumentationScope: InstrumentationScope) {
const id = instrumentationScopeId(instrumentationScope);
let meterSharedState = this.meterSharedStates.get(id);
if (meterSharedState == null) {
meterSharedState = new MeterSharedState(this, instrumentationLibrary);
meterSharedState = new MeterSharedState(this, instrumentationScope);
this.meterSharedStates.set(id, meterSharedState);
}
return meterSharedState;
Expand Down
Loading

0 comments on commit 6ee89b0

Please sign in to comment.