Skip to content

Commit

Permalink
Merge branch 'main' into lint-warnings-instrumentation-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Sep 4, 2021
2 parents 07e06c5 + 6617573 commit 2d3727b
Show file tree
Hide file tree
Showing 27 changed files with 85 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CollectorMetricExporter
);
}

getDefaultUrl(config: CollectorExporterConfigBase) {
getDefaultUrl(config: CollectorExporterConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export abstract class CollectorExporterNodeBase<

constructor(config: CollectorExporterNodeConfigBase = {}) {
super(config);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((config as any).metadata) {
diag.warn('Metadata cannot be set when using http');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CollectorMetricExporter
);
}

getDefaultUrl(config: CollectorExporterNodeConfigBase) {
getDefaultUrl(config: CollectorExporterNodeConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export namespace opentelemetryProto {
droppedAttributesCount: number;
}

// eslint-disable-next-line @typescript-eslint/no-shadow
export enum SpanKind {
SPAN_KIND_UNSPECIFIED,
SPAN_KIND_INTERNAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class PrometheusExporter implements MetricExporter {
* @param records Metrics to be sent to the prometheus backend
* @param cb result callback to be called on finish
*/
export(records: MetricRecord[], cb: (result: ExportResult) => void) {
export(records: MetricRecord[], cb: (result: ExportResult) => void): void {
if (!this._server) {
// It is conceivable that the _server may not be started as it is an async startup
// However unlikely, if this happens the caller may retry the export
Expand Down Expand Up @@ -180,7 +180,7 @@ export class PrometheusExporter implements MetricExporter {
public getMetricsRequestHandler(
_request: IncomingMessage,
response: ServerResponse
) {
): void {
this._exportMetrics(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ interface BatcherCheckpoint {
export class PrometheusLabelsBatcher {
private _batchMap = new Map<string, BatcherCheckpoint>();

get hasMetric() {
get hasMetric(): boolean {
return this._batchMap.size > 0;
}

process(record: MetricRecord) {
process(record: MetricRecord): void {
const name = record.descriptor.name;
let item = this._batchMap.get(name);
if (item === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as zipkinTypes from '../../types';
* @param headers - headers
* send
*/
export function prepareSend(urlStr: string, headers?: Record<string, string>) {
export function prepareSend(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn {
let xhrHeaders: Record<string, string>;
const useBeacon = typeof navigator.sendBeacon === 'function' && !headers;
if (headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as zipkinTypes from '../../types';
* @param headers - headers
* send
*/
export function prepareSend(urlStr: string, headers?: Record<string, string>) {
export function prepareSend(urlStr: string, headers?: Record<string, string>): zipkinTypes.SendFn {
const urlOpts = url.parse(urlStr);

const reqOpts: http.RequestOptions = Object.assign(
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const ZIPKIN_SPAN_KIND_MAPPING = {
[api.SpanKind.INTERNAL]: undefined,
};

export const statusCodeTagName = 'ot.status_code';
export const statusDescriptionTagName = 'ot.status_description';
export const defaultStatusCodeTagName = 'ot.status_code';
export const defaultStatusDescriptionTagName = 'ot.status_description';

/**
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry-exporter-zipkin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,5 @@ export type SendFunction = (
) => void;

export type GetHeaders = () => Record<string, string> | undefined;

export type SendFn = (zipkinSpans: Span[], done: (result: ExportResult) => void) => void;
10 changes: 5 additions & 5 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { prepareSend } from './platform/index';
import * as zipkinTypes from './types';
import {
toZipkinSpan,
statusCodeTagName,
statusDescriptionTagName,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
} from './transform';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { prepareGetHeaders } from './utils';
Expand All @@ -45,9 +45,9 @@ export class ZipkinExporter implements SpanExporter {
this._urlStr = config.url || getEnv().OTEL_EXPORTER_ZIPKIN_ENDPOINT;
this._send = prepareSend(this._urlStr, config.headers);
this._serviceName = config.serviceName;
this._statusCodeTagName = config.statusCodeTagName || statusCodeTagName;
this._statusCodeTagName = config.statusCodeTagName || defaultStatusCodeTagName;
this._statusDescriptionTagName =
config.statusDescriptionTagName || statusDescriptionTagName;
config.statusDescriptionTagName || defaultStatusDescriptionTagName;
this._isShutdown = false;
if (typeof config.getExportRequestHeaders === 'function') {
this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders);
Expand All @@ -63,7 +63,7 @@ export class ZipkinExporter implements SpanExporter {
export(
spans: ReadableSpan[],
resultCallback: (result: ExportResult) => void
) {
): void {
const serviceName = String(
this._serviceName ||
spans[0].resource.attributes[SemanticResourceAttributes.SERVICE_NAME] ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { BasicTracerProvider, Span } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import {
statusCodeTagName,
statusDescriptionTagName,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
toZipkinSpan,
_toZipkinAnnotations,
_toZipkinTags,
Expand Down Expand Up @@ -78,8 +78,8 @@ describe('transform', () => {
const zipkinSpan = toZipkinSpan(
span,
'my-service',
statusCodeTagName,
statusDescriptionTagName
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -101,7 +101,7 @@ describe('transform', () => {
tags: {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'UNSET',
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand All @@ -124,8 +124,8 @@ describe('transform', () => {
const zipkinSpan = toZipkinSpan(
span,
'my-service',
statusCodeTagName,
statusDescriptionTagName
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: 'SERVER',
Expand All @@ -140,7 +140,7 @@ describe('transform', () => {
name: span.name,
parentId: undefined,
tags: {
[statusCodeTagName]: 'UNSET',
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand Down Expand Up @@ -173,8 +173,8 @@ describe('transform', () => {
const zipkinSpan = toZipkinSpan(
span,
'my-service',
statusCodeTagName,
statusDescriptionTagName
defaultStatusCodeTagName,
defaultStatusDescriptionTagName
);
assert.deepStrictEqual(zipkinSpan, {
kind: item.zipkin,
Expand All @@ -189,7 +189,7 @@ describe('transform', () => {
name: span.name,
parentId: undefined,
tags: {
[statusCodeTagName]: 'UNSET',
[defaultStatusCodeTagName]: 'UNSET',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
'telemetry.sdk.language': language,
'telemetry.sdk.name': 'opentelemetry',
Expand Down Expand Up @@ -219,15 +219,15 @@ describe('transform', () => {
const tags: zipkinTypes.Tags = _toZipkinTags(
span.attributes,
span.status,
statusCodeTagName,
statusDescriptionTagName,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
DUMMY_RESOURCE
);

assert.deepStrictEqual(tags, {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'UNSET',
[defaultStatusCodeTagName]: 'UNSET',
cost: '112.12',
service: 'ui',
version: '1',
Expand All @@ -254,8 +254,8 @@ describe('transform', () => {
const tags: zipkinTypes.Tags = _toZipkinTags(
span.attributes,
span.status,
statusCodeTagName,
statusDescriptionTagName,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand All @@ -266,7 +266,7 @@ describe('transform', () => {
assert.deepStrictEqual(tags, {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'ERROR',
[defaultStatusCodeTagName]: 'ERROR',
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
Expand All @@ -291,8 +291,8 @@ describe('transform', () => {
const tags: zipkinTypes.Tags = _toZipkinTags(
span.attributes,
span.status,
statusCodeTagName,
statusDescriptionTagName,
defaultStatusCodeTagName,
defaultStatusDescriptionTagName,
Resource.empty().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
Expand All @@ -303,8 +303,8 @@ describe('transform', () => {
assert.deepStrictEqual(tags, {
key1: 'value1',
key2: 'value2',
[statusCodeTagName]: 'ERROR',
[statusDescriptionTagName]: status.message,
[defaultStatusCodeTagName]: 'ERROR',
[defaultStatusDescriptionTagName]: status.message,
[SemanticResourceAttributes.SERVICE_NAME]: 'zipkin-test',
});
});
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
return this._config;
}

override setConfig(config: HttpInstrumentationConfig & InstrumentationConfig = {}) {
override setConfig(config: HttpInstrumentationConfig & InstrumentationConfig = {}): void {
this._config = Object.assign({}, config);
}

init() {
init(): [InstrumentationNodeModuleDefinition<Https>, InstrumentationNodeModuleDefinition<Http>] {
return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
* Creates spans for incoming requests, restoring spans' context if applied.
*/
protected _getPatchIncomingRequestFunction(component: 'http' | 'https') {
return (original: (event: string, ...args: unknown[]) => boolean) => {
return (original: (event: string, ...args: unknown[]) => boolean): (this: unknown, event: string, ...args: unknown[]) => boolean => {
return this._incomingRequestFunction(component, original);
};
}
Expand Down Expand Up @@ -305,7 +305,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
if (response.aborted && !response.complete) {
status = { code: SpanStatusCode.ERROR };
} else {
status = utils.parseResponseStatus(response.statusCode!);
status = utils.parseResponseStatus(response.statusCode);
}

span.setStatus(status);
Expand Down Expand Up @@ -351,7 +351,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
) {
const instrumentation = this;
return function incomingRequest(
this: {},
this: unknown,
event: string,
...args: unknown[]
): boolean {
Expand Down Expand Up @@ -488,7 +488,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
): Func<http.ClientRequest> {
const instrumentation = this;
return function outgoingRequest(
this: {},
this: unknown,
options: url.URL | http.RequestOptions | string,
...args: unknown[]
): http.ClientRequest {
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-instrumentation-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const setSpanWithError = (
span: Span,
error: Err,
obj?: IncomingMessage | ClientRequest
) => {
): void => {
const message = error.message;

span.setAttributes({
Expand All @@ -176,7 +176,7 @@ export const setSpanWithError = (

let status: SpanStatus;
if ((obj as IncomingMessage).statusCode) {
status = parseResponseStatus((obj as IncomingMessage).statusCode!);
status = parseResponseStatus((obj as IncomingMessage).statusCode);
} else if ((obj as ClientRequest).aborted) {
status = { code: SpanStatusCode.ERROR };
} else {
Expand All @@ -196,7 +196,7 @@ export const setSpanWithError = (
export const setRequestContentLengthAttribute = (
request: IncomingMessage,
attributes: SpanAttributes
) => {
): void => {
const length = getContentLength(request.headers);
if (length === null) return;

Expand All @@ -217,7 +217,7 @@ export const setRequestContentLengthAttribute = (
export const setResponseContentLengthAttribute = (
response: IncomingMessage,
attributes: SpanAttributes
) => {
): void => {
const length = getContentLength(response.headers);
if (length === null) return;

Expand Down Expand Up @@ -259,7 +259,7 @@ export const isCompressed = (
export const getRequestInfo = (
options: url.URL | RequestOptions | string,
extraOptions?: RequestOptions
) => {
): { origin: string; pathname: string; method: string; optionsParsed: RequestOptions; } => {
let pathname = '/';
let origin = '';
let optionsParsed: RequestOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Packages', () => {
);
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<{}>;
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
}
const spans = memoryExporter.getFinishedSpans();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Packages', () => {
);
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<{}>;
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
}
const spans = memoryExporter.getFinishedSpans();
Expand Down
Loading

0 comments on commit 2d3727b

Please sign in to comment.