Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix lint warnings in propagator-jaeger, propagator-b3, resources, and sdk-metrics-base packages #2406

Merged
merged 6 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function isValidSampledValue(sampled: TraceFlags | undefined): boolean {
return sampled === TraceFlags.SAMPLED || sampled === TraceFlags.NONE;
}

export function parseHeader(header: unknown) {
function parseHeader(header: unknown) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed export by intuition. Let me know if I did wrong here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the tests pass it's probably fine. It might have been exported for those

return Array.isArray(header) ? header[0] : header;
}

Expand Down Expand Up @@ -93,7 +93,7 @@ function getTraceFlags(
* Based on: https://github.com/openzipkin/b3-propagation
*/
export class B3MultiPropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
const spanContext = trace.getSpanContext(context);
if (
!spanContext ||
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-propagator-b3/src/B3Propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class B3Propagator implements TextMapPropagator {
}
}

inject(context: Context, carrier: unknown, setter: TextMapSetter) {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
if (isTracingSuppressed(context)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function convertToTraceFlags(samplingState: string | undefined): TraceFlags {
* Based on: https://github.com/openzipkin/b3-propagation
*/
export class B3SinglePropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
const spanContext = trace.getSpanContext(context);
if (
!spanContext ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class JaegerPropagator implements TextMapPropagator {
this._jaegerTraceHeader = customTraceHeader || UBER_TRACE_ID_HEADER;
}

inject(context: Context, carrier: unknown, setter: TextMapSetter) {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
const spanContext = trace.getSpanContext(context);
const baggage = propagation.getBaggage(context);
if (spanContext && isTracingSuppressed(context) === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

export function defaultServiceName() {
export function defaultServiceName(): string {
return 'unknown_service';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

export function defaultServiceName() {
export function defaultServiceName(): string {
return `unknown_service:${process.argv0}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import * as api from '@opentelemetry/api-metrics';
import { Observation } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { BoundObserver } from './BoundInstrument';
Expand Down Expand Up @@ -64,14 +65,14 @@ export abstract class BaseObserverMetric
return super.getMetricRecord();
}

protected _processResults(observerResult: ObserverResult) {
protected _processResults(observerResult: ObserverResult): void {
observerResult.values.forEach((value, labels) => {
const instrument = this.bind(labels);
instrument.update(value);
});
}

observation(value: number) {
observation(value: number): Observation {
return {
value,
observer: this as BaseObserverMetric,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BatchObserverResult implements api.BatchObserverResult {
* updated
* @param [callback]
*/
onObserveCalled(callback?: () => void) {
onObserveCalled(callback?: () => void): void {
this._callback = callback;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class CounterMetric extends Metric<BoundCounter> implements api.Counter {
* @param [labels = {}] key-values pairs that are associated with a specific metric
* that you want to record.
*/
add(value: number, labels: api.Labels = {}) {
add(value: number, labels: api.Labels = {}): void {
this.bind(labels).add(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class MeterProvider implements api.MeterProvider {
);
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this._meters.get(key)!;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-sdk-metrics-base/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
*/
bind(labels: api.Labels): T {
const hash = hashLabels(labels);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (this._instruments.has(hash)) return this._instruments.get(hash)!;

const instrument = this._makeInstrument(labels);
Expand Down Expand Up @@ -88,7 +89,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
return this._kind;
}

getAggregationTemporality() {
getAggregationTemporality(): api.AggregationTemporality {
return this._aggregationTemporality;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SumObserverMetric
);
}

protected override _processResults(observerResult: ObserverResult) {
protected override _processResults(observerResult: ObserverResult): void {
observerResult.values.forEach((value, labels) => {
const instrument = this.bind(labels);
// SumObserver is monotonic which means it should only accept values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class UpDownCounterMetric
* @param [labels = {}] key-values pairs that are associated with a specific
* metric that you want to record.
*/
add(value: number, labels: api.Labels = {}) {
add(value: number, labels: api.Labels = {}): void {
this.bind(labels).add(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ValueRecorderMetric
);
}

record(value: number, labels: api.Labels = {}) {
record(value: number, labels: api.Labels = {}): void {
this.bind(labels).record(value);
}
}