Skip to content

Commit

Permalink
build(dev-deps): prettier fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pragmaticivan committed May 8, 2024
1 parent 3684486 commit 23a13ae
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 85 deletions.
39 changes: 18 additions & 21 deletions src/interfaces/opentelemetry-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,35 @@ export interface OpenTelemetryOptionsFactory {
*
* @publicApi
*/
export interface OpenTelemetryModuleAsyncOptions
extends Pick<ModuleMetadata, 'imports'> {
export interface OpenTelemetryModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
/**
* The name of the module
*/
* The name of the module
*/
name?: string;
/**
* The class which should be used to provide the Terminus options
*/
* The class which should be used to provide the Terminus options
*/
useClass?: Type<OpenTelemetryOptionsFactory>;
/**
* Import existing providers from other module
*/
* Import existing providers from other module
*/
useExisting?: Type<OpenTelemetryOptionsFactory>;
/**
* The factory which should be used to provide the Terminus options
*/
useFactory?: (
...args: any[]
) => Promise<OpenTelemetryModuleOptions> | OpenTelemetryModuleOptions;
* The factory which should be used to provide the Terminus options
*/
useFactory?: (...args: any[]) => Promise<OpenTelemetryModuleOptions> | OpenTelemetryModuleOptions;
/**
* The providers which should get injected
*/
* The providers which should get injected
*/
inject?: (string | symbol | Function | Type<any> | Abstract<any>)[];
}

export type OpenTelemetryMetrics = {
hostMetrics?: boolean,
hostMetrics?: boolean;
apiMetrics?: {
enable?: boolean,
defaultAttributes?: MetricAttributes,
ignoreRoutes?: (string | RouteInfo)[],
ignoreUndefinedRoutes?: boolean,
},
enable?: boolean;
defaultAttributes?: MetricAttributes;
ignoreRoutes?: (string | RouteInfo)[];
ignoreUndefinedRoutes?: boolean;
};
};
10 changes: 7 additions & 3 deletions src/metrics/decorators/observable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { createParamDecorator } from '@nestjs/common';
import { MetricOptions } from '@opentelemetry/api';
import { getOrCreateObservableCounter, getOrCreateObservableGauge, getOrCreateObservableUpDownCounter } from '../metric-data';
import {
getOrCreateObservableCounter,
getOrCreateObservableGauge,
getOrCreateObservableUpDownCounter,
} from '../metric-data';

export const OtelObservableGauge = createParamDecorator((name: string, options?: MetricOptions) => {
if (!name || name.length === 0) {
Expand All @@ -15,7 +19,7 @@ export const OtelObservableCounter = createParamDecorator(
throw new Error('OtelObservableCounter need a name argument');
}
return getOrCreateObservableCounter(name, options);
},
}
);

export const OtelObservableUpDownCounter = createParamDecorator(
Expand All @@ -24,5 +28,5 @@ export const OtelObservableUpDownCounter = createParamDecorator(
throw new Error('OtelObservableUpDownCounter need a name argument');
}
return getOrCreateObservableUpDownCounter(name, options);
},
}
);
8 changes: 2 additions & 6 deletions src/metrics/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { Inject } from '@nestjs/common';
import { getToken } from './utils';

export function InjectMetric(
name: string,
): (
target: Record<string, unknown>,
key: string | symbol,
index?: number | undefined,
) => void {
name: string
): (target: Record<string, unknown>, key: string | symbol, index?: number | undefined) => void {
const token = getToken(name);

return Inject(token);
Expand Down
42 changes: 19 additions & 23 deletions src/metrics/metric-data.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import {
Counter, MetricOptions, UpDownCounter,
Histogram, ObservableGauge, ObservableCounter, ObservableUpDownCounter,
Counter,
MetricOptions,
UpDownCounter,
Histogram,
ObservableGauge,
ObservableCounter,
ObservableUpDownCounter,
metrics,
} from '@opentelemetry/api';
import { OTEL_METER_NAME } from '../opentelemetry.constants';

export type GenericMetric =
Counter |
UpDownCounter |
Histogram |
ObservableGauge |
ObservableCounter |
ObservableUpDownCounter;
| Counter
| UpDownCounter
| Histogram
| ObservableGauge
| ObservableCounter
| ObservableUpDownCounter;

export enum MetricType {
'Counter' = 'Counter',
Expand All @@ -24,10 +29,7 @@ export enum MetricType {

export const meterData: Map<string, GenericMetric> = new Map();

export function getOrCreateHistogram(
name: string,
options: MetricOptions = {},
): Histogram {
export function getOrCreateHistogram(name: string, options: MetricOptions = {}): Histogram {
if (meterData.has(name)) {
return meterData.get(name) as Histogram;
}
Expand All @@ -38,10 +40,7 @@ export function getOrCreateHistogram(
return histogram;
}

export function getOrCreateCounter(
name: string,
options: MetricOptions = {},
): Counter {
export function getOrCreateCounter(name: string, options: MetricOptions = {}): Counter {
if (meterData.has(name)) {
return meterData.get(name) as Counter;
}
Expand All @@ -53,10 +52,7 @@ export function getOrCreateCounter(
return counter;
}

export function getOrCreateUpDownCounter(
name: string,
options: MetricOptions = {},
): UpDownCounter {
export function getOrCreateUpDownCounter(name: string, options: MetricOptions = {}): UpDownCounter {
if (meterData.has(name)) {
return meterData.get(name) as UpDownCounter;
}
Expand All @@ -70,7 +66,7 @@ export function getOrCreateUpDownCounter(

export function getOrCreateObservableGauge(
name: string,
options: MetricOptions = {},
options: MetricOptions = {}
): ObservableGauge {
if (meterData.has(name)) {
return meterData.get(name) as ObservableGauge;
Expand All @@ -85,7 +81,7 @@ export function getOrCreateObservableGauge(

export function getOrCreateObservableCounter(
name: string,
options: MetricOptions = {},
options: MetricOptions = {}
): ObservableCounter {
if (meterData.has(name)) {
return meterData.get(name) as ObservableCounter;
Expand All @@ -100,7 +96,7 @@ export function getOrCreateObservableCounter(

export function getOrCreateObservableUpDownCounter(
name: string,
options: MetricOptions = {},
options: MetricOptions = {}
): ObservableUpDownCounter {
if (meterData.has(name)) {
return meterData.get(name) as ObservableUpDownCounter;
Expand Down
28 changes: 10 additions & 18 deletions src/metrics/metric.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Injectable } from '@nestjs/common';
import { MetricOptions } from '@opentelemetry/api';
import {
MetricOptions,
} from '@opentelemetry/api';
import {
getOrCreateCounter, getOrCreateHistogram,
getOrCreateObservableCounter, getOrCreateObservableGauge,
getOrCreateObservableUpDownCounter, getOrCreateUpDownCounter,
getOrCreateCounter,
getOrCreateHistogram,
getOrCreateObservableCounter,
getOrCreateObservableGauge,
getOrCreateObservableUpDownCounter,
getOrCreateUpDownCounter,
} from './metric-data';

@Injectable()
Expand All @@ -22,24 +23,15 @@ export class MetricService {
return getOrCreateHistogram(name, options);
}

getObservableCounter(
name: string,
options?: MetricOptions,
) {
getObservableCounter(name: string, options?: MetricOptions) {
return getOrCreateObservableCounter(name, options);
}

getObservableGauge(
name: string,
options?: MetricOptions,
) {
getObservableGauge(name: string, options?: MetricOptions) {
return getOrCreateObservableGauge(name, options);
}

getObservableUpDownCounter(
name: string,
options?: MetricOptions,
) {
getObservableUpDownCounter(name: string, options?: MetricOptions) {
return getOrCreateObservableUpDownCounter(name, options);
}
}
14 changes: 9 additions & 5 deletions src/tracing/decorators/span.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'reflect-metadata';
import { SpanKind, SpanStatusCode } from '@opentelemetry/api';
import { InMemorySpanExporter, NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
import {
InMemorySpanExporter,
NodeTracerProvider,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-node';
import { SetMetadata } from '@nestjs/common';
import { Span } from './span';

Expand All @@ -10,15 +14,15 @@ const symbol = Symbol('testSymbol');

class TestSpan {
@Span()
singleSpan() { }
singleSpan() {}

@Span()
doubleSpan() {
return this.singleSpan();
}

@Span('foo', { kind: SpanKind.PRODUCER })
fooProducerSpan() { }
fooProducerSpan() {}

@Span()
error() {
Expand All @@ -27,10 +31,10 @@ class TestSpan {

@Span()
@TestDecoratorThatSetsMetadata()
metadata() { }
metadata() {}

@Span()
[symbol]() { }
[symbol]() {}
}

describe('Span', () => {
Expand Down
16 changes: 10 additions & 6 deletions tests/e2e/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ describe('OpenTelemetryModule', () => {
describe('#forRootAsync', () => {
describe('default options with factory', () => {
beforeEach(async () => {
({ app } = await createOpenTelemetryModule(OpenTelemetryModule.forRootAsync({
useFactory: () => ({}),
})));
({ app } = await createOpenTelemetryModule(
OpenTelemetryModule.forRootAsync({
useFactory: () => ({}),
})
));
});

it('should load module with default configs', async () => {
Expand All @@ -47,9 +49,11 @@ describe('OpenTelemetryModule', () => {
}
}

({ app } = await createOpenTelemetryModule(OpenTelemetryModule.forRootAsync({
useClass: OpenTelemetryService,
})));
({ app } = await createOpenTelemetryModule(
OpenTelemetryModule.forRootAsync({
useClass: OpenTelemetryService,
})
));
});

it('should load module with default configs', async () => {
Expand Down
4 changes: 1 addition & 3 deletions tests/fixture-app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
Get, Controller,
} from '@nestjs/common';
import { Get, Controller } from '@nestjs/common';
import { OtelInstanceCounter, OtelMethodCounter } from '../../src/metrics/decorators/common';

@OtelInstanceCounter()
Expand Down

0 comments on commit 23a13ae

Please sign in to comment.