From b4bbae09a846140dda81bf5422aa23a8cdaad18f Mon Sep 17 00:00:00 2001 From: John Bley Date: Wed, 10 Feb 2021 10:53:55 -0500 Subject: [PATCH 1/2] chore: lint on shadowing in non-test sources, fix a few of them --- eslint.config.js | 5 ++++- .../src/baggage/propagation/HttpBaggage.ts | 6 +++--- .../src/platform/node/util.ts | 8 ++++---- packages/opentelemetry-instrumentation-http/src/http.ts | 4 ++-- packages/opentelemetry-metrics/src/Meter.ts | 4 ++-- packages/opentelemetry-plugin-http/src/http.ts | 4 ++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index f590ddd90f2..663e6b32adf 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -23,6 +23,8 @@ module.exports = { "leadingUnderscore": "require" } ], + "no-shadow": "off", + "@typescript-eslint/no-shadow": ["warn"], "@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}], "@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }], "arrow-parens": ["error", "as-needed"], @@ -43,7 +45,8 @@ module.exports = { "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-var-requires": "off" + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-shadow": ["off"], } } ] diff --git a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts index 8999af82455..6b40dcf66e8 100644 --- a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts @@ -88,11 +88,11 @@ export class HttpBaggage implements TextMapPropagator { pairs.forEach(entry => { const keyPair = this._parsePairKeyValue(entry); if (keyPair) { - const entry: BaggageEntry = { value: keyPair.value }; + const baggageEntry: BaggageEntry = { value: keyPair.value }; if (keyPair.metadata) { - entry.metadata = keyPair.metadata; + baggageEntry.metadata = keyPair.metadata; } - baggage[keyPair.key] = entry; + baggage[keyPair.key] = baggageEntry; } }); if (Object.entries(baggage).length === 0) { diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/util.ts b/packages/opentelemetry-exporter-collector/src/platform/node/util.ts index 96df8bcccaa..babbe8b094f 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/util.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/util.ts @@ -54,17 +54,17 @@ export function sendWithHttp( const request = parsedUrl.protocol === 'http:' ? http.request : https.request; const req = request(options, (res: http.IncomingMessage) => { - let data = ''; - res.on('data', chunk => (data += chunk)); + let responseData = ''; + res.on('data', chunk => (responseData += chunk)); res.on('end', () => { if (res.statusCode && res.statusCode < 299) { - collector.logger.debug(`statusCode: ${res.statusCode}`, data); + collector.logger.debug(`statusCode: ${res.statusCode}`, responseData); onSuccess(); } else { const error = new collectorTypes.CollectorExporterError( res.statusMessage, res.statusCode, - data + responseData ); onError(error); } diff --git a/packages/opentelemetry-instrumentation-http/src/http.ts b/packages/opentelemetry-instrumentation-http/src/http.ts index f04d7de7e28..dafd375bcc2 100644 --- a/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/packages/opentelemetry-instrumentation-http/src/http.ts @@ -293,11 +293,11 @@ export class HttpInstrumentation extends InstrumentationBase { request.on( 'response', (response: http.IncomingMessage & { aborted?: boolean }) => { - const attributes = utils.getOutgoingRequestAttributesOnResponse( + const responseAttributes = utils.getOutgoingRequestAttributesOnResponse( response, { hostname } ); - span.setAttributes(attributes); + span.setAttributes(responseAttributes); if (this._getConfig().responseHook) { this._callResponseHook(span, response); } diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index 7bd7c22a41f..7b58709ea54 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -298,8 +298,8 @@ export class Meter implements api.Meter { }); await Promise.all(metrics).then(records => { - records.forEach(metrics => { - metrics.forEach(metric => this._processor.process(metric)); + records.forEach(record => { + record.forEach(metric => this._processor.process(metric)); }); }); } diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 665c155bee2..a359e470a19 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -200,11 +200,11 @@ export class HttpPlugin extends BasePlugin { request.on( 'response', (response: IncomingMessage & { aborted?: boolean }) => { - const attributes = utils.getOutgoingRequestAttributesOnResponse( + const responseAttributes = utils.getOutgoingRequestAttributesOnResponse( response, { hostname } ); - span.setAttributes(attributes); + span.setAttributes(responseAttributes); if (this._config.responseHook) { this._callResponseHook(span, response); } From ec2010263294dae03ce8c42d717f55d523cd96b9 Mon Sep 17 00:00:00 2001 From: John Bley Date: Thu, 11 Feb 2021 08:57:33 -0500 Subject: [PATCH 2/2] chore: better names in Meter.ts --- packages/opentelemetry-metrics/src/Meter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index 7b58709ea54..9f8004e00ca 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -293,13 +293,13 @@ export class Meter implements api.Meter { await Promise.all(observations); // after this all remaining metrics can be run - const metrics = Array.from(this._metrics.values()).map(metric => { + const metricsRecords = Array.from(this._metrics.values()).map(metric => { return metric.getMetricRecord(); }); - await Promise.all(metrics).then(records => { - records.forEach(record => { - record.forEach(metric => this._processor.process(metric)); + await Promise.all(metricsRecords).then(records => { + records.forEach(metrics => { + metrics.forEach(metric => this._processor.process(metric)); }); }); }