Skip to content

Commit

Permalink
Merge branch 'main' into metrics-ff/browser
Browse files Browse the repository at this point in the history
# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/test/export/PeriodicExportingMetricReader.test.ts
  • Loading branch information
legendecas committed Jan 13, 2022
2 parents c5193b7 + d315b0a commit 453dd73
Show file tree
Hide file tree
Showing 65 changed files with 316 additions and 384 deletions.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
"project": "./tsconfig.json"
},
rules: {
"no-trailing-spaces": "error",
"eol-last": "error",
"quotes": [2, "single", { "avoidEscape": true }],
"@typescript-eslint/no-floating-promises": 2,
"@typescript-eslint/no-this-alias": "off",
Expand Down Expand Up @@ -40,6 +42,7 @@ module.exports = {
}
}],
"@typescript-eslint/no-shadow": ["warn"],
"@typescript-eslint/semi": "error",
"arrow-parens": ["error", "as-needed"],
"node/no-deprecated-api": ["warn"],
"header/header": [2, "block", [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'
import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http';
import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base';
import {
OTLPExporterConfigNode,
Expand Down Expand Up @@ -45,7 +45,7 @@ export class OTLPMetricExporter
const headers = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS);
this.metadata ||= new Metadata();
for (const [k, v] of Object.entries(headers)) {
this.metadata.set(k, v)
this.metadata.set(k, v);
}
}

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

import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base';
import {
import {
OTLPExporterNodeBase,
OTLPExporterNodeConfigBase,
otlpTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,6 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
captureRequestHeaders: utils.headerCapture('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),
captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
import {
Span,
SpanAttributes,
} from '@opentelemetry/api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export function headerCapture(type: 'request' | 'response', headers: string[]) {
return (span: Span, getHeader: (key: string) => undefined | string | string[] | number) => {
for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {
const value = getHeader(capturedHeader);

if (value === undefined) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('HttpInstrumentation', () => {
describe('disable()', () => {
let provider: TracerProvider;
let startSpanStub: sinon.SinonStub;

before(() => {
provider = {
getTracer: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
context,
propagation,
Span as ISpan,
SpanKind,
SpanKind,
trace,
SpanAttributes,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -100,13 +100,13 @@ export const responseHookFunction = (
export const startIncomingSpanHookFunction = (
request: IncomingMessage
): SpanAttributes => {
return {guid: request.headers?.guid}
return {guid: request.headers?.guid};
};

export const startOutgoingSpanHookFunction = (
request: RequestOptions
): SpanAttributes => {
return {guid: request.headers?.guid}
return {guid: request.headers?.guid};
};

describe('HttpInstrumentation', () => {
Expand Down Expand Up @@ -507,12 +507,12 @@ describe('HttpInstrumentation', () => {
hostname: 'localhost',
pathname: '/',
forceStatus: {
code: SpanStatusCode.ERROR,
code: SpanStatusCode.ERROR,
message: err.message,
},
component: 'http',
noNetPeer: true,
}
};
assertSpan(spans[0], SpanKind.CLIENT, validations);
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('HttpsInstrumentation', () => {
describe('disable()', () => {
let provider: TracerProvider;
let startSpanStub: sinon.SinonStub;

before(() => {
provider = {
getTracer: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ describe('Utility', () => {
request.headers = {
'user-agent': 'chrome',
'x-forwarded-for': '<client>, <proxy1>, <proxy2>'
}
const attributes = utils.getIncomingRequestAttributes(request, { component: 'http'})
assert.strictEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined)
};
const attributes = utils.getIncomingRequestAttributes(request, { component: 'http'});
assert.strictEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined);
});
});

describe('headers to span attributes capture', () => {
let span: Span;

Expand Down Expand Up @@ -539,6 +539,6 @@ describe('Utility', () => {

assert.deepStrictEqual(span.attributes['http.request.header.origin'], ['localhost']);
assert.deepStrictEqual(span.attributes['http.request.header.accept'], undefined);
})
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const assertSpan = (
assert.ok(
span.attributes[SemanticAttributes.NET_PEER_PORT],
'must have PEER_PORT'
);
);
}
assert.ok(
(span.attributes[SemanticAttributes.HTTP_URL] as string).indexOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export abstract class InstrumentationBase<T = any>
} catch (error) {
diag.warn('Failed extracting version', baseDir);
}

return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ describe('InstrumentationBase', () => {

let instrumentation: TestInstrumentation;
let modulePatchSpy: sinon.SinonSpy;

beforeEach(() => {
instrumentation = new TestInstrumentation();
// @ts-expect-error access internal property for testing
instrumentation._enabled = true;
modulePatchSpy = sinon.spy();
});

describe('when patching a module', () => {
describe('AND there is no wildcard supported version', () => {
it('should not patch module', () => {
Expand All @@ -56,15 +56,15 @@ describe('InstrumentationBase', () => {
name: MODULE_NAME,
patch: modulePatchSpy as unknown,
} as InstrumentationModuleDefinition<unknown>;

// @ts-expect-error access internal property for testing
instrumentation._onRequire<unknown>(
instrumentationModule,
moduleExports,
MODULE_NAME,
MODULE_DIR
);

assert.strictEqual(instrumentationModule.moduleVersion, undefined);
assert.strictEqual(instrumentationModule.moduleExports, undefined);
sinon.assert.notCalled(modulePatchSpy);
Expand All @@ -79,28 +79,28 @@ describe('InstrumentationBase', () => {
name: MODULE_NAME,
patch: modulePatchSpy as unknown,
} as InstrumentationModuleDefinition<unknown>;

// @ts-expect-error access internal property for testing
instrumentation._onRequire<unknown>(
instrumentationModule,
moduleExports,
MODULE_NAME,
MODULE_DIR
);

assert.strictEqual(instrumentationModule.moduleVersion, undefined);
assert.strictEqual(instrumentationModule.moduleExports, moduleExports);
sinon.assert.calledOnceWithExactly(modulePatchSpy, moduleExports, undefined);
});
});
});

describe('when patching module files', () => {
let filePatchSpy: sinon.SinonSpy;

beforeEach(() => {
filePatchSpy = sinon.spy();
})
});

describe('AND there is no wildcard supported version', () => {
it('should not patch module file', () => {
Expand All @@ -116,15 +116,15 @@ describe('InstrumentationBase', () => {
patch: filePatchSpy as unknown
}]
} as InstrumentationModuleDefinition<unknown>;

// @ts-expect-error access internal property for testing
instrumentation._onRequire<unknown>(
instrumentationModule,
moduleExports,
MODULE_FILE_NAME,
MODULE_DIR
);

assert.strictEqual(instrumentationModule.moduleVersion, undefined);
assert.strictEqual(instrumentationModule.moduleExports, undefined);
sinon.assert.notCalled(modulePatchSpy);
Expand All @@ -146,15 +146,15 @@ describe('InstrumentationBase', () => {
patch: filePatchSpy as unknown
}]
} as InstrumentationModuleDefinition<unknown>;

// @ts-expect-error access internal property for testing
instrumentation._onRequire<unknown>(
instrumentationModule,
moduleExports,
MODULE_FILE_NAME,
MODULE_DIR
);

assert.strictEqual(instrumentationModule.moduleVersion, undefined);
assert.strictEqual(instrumentationModule.files[0].moduleExports, moduleExports);
sinon.assert.notCalled(modulePatchSpy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import * as api from '@opentelemetry/api'
import { Attributes } from '@opentelemetry/api-metrics-wip'
import * as api from '@opentelemetry/api';
import { Attributes } from '@opentelemetry/api-metrics-wip';

// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#measurement

Expand All @@ -24,4 +24,4 @@ export type Measurement = {
// TODO use common attributes
attributes: Attributes
context?: api.Context;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { MetricCollector } from './state/MetricCollector';

export type MeterProviderOptions = {
resource?: Resource;
}
};

export class MeterProvider {
private _sharedState: MeterProviderSharedState;
Expand All @@ -42,7 +42,7 @@ export class MeterProvider {
getMeter(name: string, version = '', options: metrics.MeterOptions = {}): metrics.Meter {
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#meter-creation
if (this._shutdown) {
api.diag.warn('A shutdown MeterProvider cannot provide a Meter')
api.diag.warn('A shutdown MeterProvider cannot provide a Meter');
return metrics.NOOP_METER;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ export class MeterProvider {
} catch (e) {
// Log all Errors.
if (e instanceof Error) {
api.diag.error(`Error shutting down: ${e.message}`)
api.diag.error(`Error shutting down: ${e.message}`);
}
}
}
Expand All @@ -103,7 +103,7 @@ export class MeterProvider {

// do not flush after shutdown
if (this._shutdown) {
api.diag.warn('invalid attempt to force flush after shutdown')
api.diag.warn('invalid attempt to force flush after shutdown');
return;
}

Expand All @@ -113,7 +113,7 @@ export class MeterProvider {
} catch (e) {
// Log all Errors.
if (e instanceof Error) {
api.diag.error(`Error flushing: ${e.message}`)
api.diag.error(`Error flushing: ${e.message}`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { HrTime } from '@opentelemetry/api';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { MetricData } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
Expand Down Expand Up @@ -48,10 +47,8 @@ export class DropAggregator implements Aggregator<undefined> {
_instrumentationLibrary: InstrumentationLibrary,
_instrumentDescriptor: InstrumentDescriptor,
_accumulationByAttributes: AccumulationRecord<undefined>[],
_temporality: AggregationTemporality,
_sdkStartTime: HrTime,
_lastCollectionTime: HrTime,
_collectionTime: HrTime): Maybe<MetricData> {
_startTime: HrTime,
_endTime: HrTime): Maybe<MetricData> {
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { HistogramMetricData, PointDataType } from '../export/MetricData';
import { Resource } from '@opentelemetry/resources';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { HrTime } from '@opentelemetry/api';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';

Expand Down Expand Up @@ -143,10 +142,8 @@ export class HistogramAggregator implements Aggregator<HistogramAccumulation> {
instrumentationLibrary: InstrumentationLibrary,
metricDescriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[],
temporality: AggregationTemporality,
sdkStartTime: HrTime,
lastCollectionTime: HrTime,
collectionTime: HrTime): Maybe<HistogramMetricData> {
startTime: HrTime,
endTime: HrTime): Maybe<HistogramMetricData> {
return {
resource,
instrumentationLibrary,
Expand All @@ -155,11 +152,11 @@ export class HistogramAggregator implements Aggregator<HistogramAccumulation> {
pointData: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime: temporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime,
endTime: collectionTime,
startTime,
endTime,
point: accumulation.toPoint(),
}
};
})
}
};
}
}
Loading

0 comments on commit 453dd73

Please sign in to comment.