Skip to content

Commit

Permalink
chore: OT dependency upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSeylan committed Feb 19, 2022
1 parent 03696f7 commit a07fc31
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 220 deletions.
231 changes: 53 additions & 178 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
"@nestjs/core": "^8.1.1",
"@nestjs/event-emitter": "^1.0.0",
"@nestjs/microservices": "^8.1.1",
"@nestjs/schedule": "^1.0.1",
"@opentelemetry/api": "^1.0.3",
"@nestjs/schedule": "^1.0.2",
"@opentelemetry/api": "^1.0.4",
"@opentelemetry/context-async-hooks": "^1.0.1",
"@opentelemetry/core": "^1.0.1",
"@opentelemetry/host-metrics": "^0.26.0",
"@opentelemetry/host-metrics": "^0.27.1",
"@opentelemetry/instrumentation-http": "^0.27.0",
"@opentelemetry/propagator-b3": "^1.0.1",
"@opentelemetry/propagator-jaeger": "^1.0.1",
"@opentelemetry/resource-detector-aws": "^1.0.1",
"@opentelemetry/resource-detector-aws": "^1.0.3",
"@opentelemetry/resources": "^1.0.1",
"@opentelemetry/sdk-node": "^0.27.0",
"@opentelemetry/sdk-trace-base": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Metric/Injectors/DecoratorObserverMetricInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class DecoratorObserverMetricInjector extends BaseMetricInjector {
private generateMetric(name: string, metricOptions: MetricOptions) {
const metric = this.metricService
.getMeter()
.createValueRecorder(name, metricOptions);
.createHistogram(name, metricOptions);

return (time) => {
metric.record(time, this.metricService.getLabels());
Expand Down
9 changes: 4 additions & 5 deletions src/Metric/Metrics/ActiveHandlesMetric.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseMetric } from './BaseMetric';
import { MetricService } from '../MetricService';
import { Injectable } from '@nestjs/common';
import { ValueObserver } from '@opentelemetry/api-metrics';
import { ObservableGauge } from '@opentelemetry/api-metrics';

@Injectable()
export class ActiveHandlesMetric implements BaseMetric {
name = 'nodejs_active_handles';
description =
'Number of active libuv handles grouped by handle type. Every handle type is C++ class name.';

private valueObserver: ValueObserver;
private observableGauge: ObservableGauge;

constructor(private readonly metricService: MetricService) {}

Expand All @@ -18,10 +18,10 @@ export class ActiveHandlesMetric implements BaseMetric {
return;
}

this.valueObserver = this.metricService
this.observableGauge = this.metricService
.getProvider()
.getMeter('default')
.createValueObserver(
.createObservableGauge(
this.name,
{
description: this.description,
Expand All @@ -31,7 +31,6 @@ export class ActiveHandlesMetric implements BaseMetric {
}

private observerCallback(observerResult) {
this.valueObserver.clear();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const handles = process._getActiveHandles();
Expand Down
9 changes: 4 additions & 5 deletions src/Metric/Metrics/ActiveHandlesTotalMetric.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BaseMetric } from './BaseMetric';
import { MetricService } from '../MetricService';
import { Injectable } from '@nestjs/common';
import { ValueObserver } from '@opentelemetry/api-metrics';
import { ObservableGauge } from '@opentelemetry/api-metrics';

@Injectable()
export class ActiveHandlesTotalMetric implements BaseMetric {
name = 'nodejs_active_handles_total';
description = 'Total number of active handles.';

private valueObserver: ValueObserver;
private observableBase: ObservableGauge;

constructor(private readonly metricService: MetricService) {}

Expand All @@ -17,10 +17,10 @@ export class ActiveHandlesTotalMetric implements BaseMetric {
return;
}

this.valueObserver = this.metricService
this.observableBase = this.metricService
.getProvider()
.getMeter('default')
.createValueObserver(
.createObservableGauge(
this.name,
{
description: this.description,
Expand All @@ -30,7 +30,6 @@ export class ActiveHandlesTotalMetric implements BaseMetric {
}

private observerCallback(observerResult) {
this.valueObserver.clear();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const handles = process._getActiveHandles();
Expand Down
10 changes: 5 additions & 5 deletions src/Metric/Metrics/Grpc/GrpcRequestDurationSeconds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MetricService } from '../../MetricService';
import { Injectable } from '@nestjs/common';
import {
MetricOptions,
ValueRecorder,
Histogram,
ValueType,
} from '@opentelemetry/api-metrics';
import { OnEvent } from '@nestjs/event-emitter';
Expand All @@ -20,23 +20,23 @@ export class GrpcRequestDurationSeconds implements BaseMetric {
name = 'grpc_request_duration_seconds';
description = 'grpc_request_duration_seconds';

private valueRecorder: ValueRecorder;
private histogram: Histogram;

constructor(private readonly metricService: MetricService) {}

async inject(): Promise<void> {
this.valueRecorder = this.metricService
this.histogram = this.metricService
.getProvider()
.getMeter('default')
.createValueRecorder(this.name, {
.createHistogram(this.name, {
...GrpcRequestDurationSeconds.metricOptions,
description: this.description,
});
}

@OnEvent(ProducerEvent.GRPC)
onResult(event: ProducerGrpcEvent) {
this.valueRecorder.record(
this.histogram.record(
event.time,
Object.assign(event.labels, this.metricService.getLabels()),
);
Expand Down
10 changes: 5 additions & 5 deletions src/Metric/Metrics/Http/HttpRequestDurationSeconds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseMetric } from '../BaseMetric';
import { MetricService } from '../../MetricService';
import { Injectable } from '@nestjs/common';
import { ValueRecorder, ValueType } from '@opentelemetry/api-metrics';
import { Histogram, ValueType } from '@opentelemetry/api-metrics';
import { OnEvent } from '@nestjs/event-emitter';
import { ProducerEvent } from '../../Interceptors/ProducerEvent';
import { ProducerHttpEvent } from '../../Interceptors/Http/ProducerHttpEvent';
Expand All @@ -17,23 +17,23 @@ export class HttpRequestDurationSeconds implements BaseMetric {
name = 'http_request_duration_seconds';
description = 'http_request_duration_seconds';

private valueRecorder: ValueRecorder;
private histogram: Histogram;

constructor(private readonly metricService: MetricService) {}

async inject(): Promise<void> {
this.valueRecorder = this.metricService
this.histogram = this.metricService
.getProvider()
.getMeter('default')
.createValueRecorder(this.name, {
.createHistogram(this.name, {
...HttpRequestDurationSeconds.metricOptions,
description: this.description,
});
}

@OnEvent(ProducerEvent.HTTP)
onResult(event: ProducerHttpEvent) {
this.valueRecorder.record(
this.histogram.record(
event.time,
Object.assign(event.labels, this.metricService.getLabels()),
);
Expand Down
8 changes: 4 additions & 4 deletions src/Metric/Metrics/ProcessMaxFdsMetric.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseMetric } from './BaseMetric';
import { MetricService } from '../MetricService';
import { Injectable } from '@nestjs/common';
import { ValueObserver } from '@opentelemetry/api-metrics';
import { ObservableGauge } from '@opentelemetry/api-metrics';
import * as fs from 'fs';

@Injectable()
export class ProcessMaxFdsMetric implements BaseMetric {
name = 'process_max_fds';
description = 'Maximum number of open file descriptors.';

private valueObserver: ValueObserver;
private observableBase: ObservableGauge;
private maxFds;

constructor(private readonly metricService: MetricService) {}
Expand All @@ -33,10 +33,10 @@ export class ProcessMaxFdsMetric implements BaseMetric {

if (this.maxFds === undefined) return;

this.valueObserver = this.metricService
this.observableBase = this.metricService
.getProvider()
.getMeter('default')
.createValueObserver(
.createObservableGauge(
this.name,
{
description: this.description,
Expand Down
8 changes: 4 additions & 4 deletions src/Metric/Metrics/ProcessOpenFdsMetric.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseMetric } from './BaseMetric';
import { MetricService } from '../MetricService';
import { Injectable } from '@nestjs/common';
import { ValueObserver } from '@opentelemetry/api-metrics';
import { ObservableGauge } from '@opentelemetry/api-metrics';
import * as fs from 'fs';

@Injectable()
export class ProcessOpenFdsMetric implements BaseMetric {
name = 'process_open_fds';
description = 'Number of open file descriptors.';

private valueObserver: ValueObserver;
private observableBase: ObservableGauge;

constructor(private readonly metricService: MetricService) {}

Expand All @@ -18,10 +18,10 @@ export class ProcessOpenFdsMetric implements BaseMetric {
return;
}

this.valueObserver = this.metricService
this.observableBase = this.metricService
.getProvider()
.getMeter('default')
.createValueObserver(
.createObservableGauge(
this.name,
{
description: this.description,
Expand Down
8 changes: 4 additions & 4 deletions src/Metric/Metrics/ProcessStartTimeMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { MetricService } from '../MetricService';
import { Injectable } from '@nestjs/common';
import {
AggregationTemporality,
ValueObserver,
ObservableGauge,
} from '@opentelemetry/api-metrics';

@Injectable()
export class ProcessStartTimeMetric implements BaseMetric {
name = 'process_start_time_seconds';
description = 'Start time of the process since unix epoch in seconds.';

private valueObserver: ValueObserver;
private observableGauge: ObservableGauge;
private readonly uptimeInSecond = Math.round(
Date.now() / 1000 - process.uptime(),
);

constructor(private readonly metricService: MetricService) {}

async inject(): Promise<void> {
this.valueObserver = this.metricService
this.observableGauge = this.metricService
.getProvider()
.getMeter('default')
.createValueObserver(
.createObservableGauge(
this.name,
{
description: this.description,
Expand Down
10 changes: 5 additions & 5 deletions src/Metric/Metrics/RabbitMQ/GrpcRequestDurationSeconds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MetricService } from '../../MetricService';
import { Injectable } from '@nestjs/common';
import {
MetricOptions,
ValueRecorder,
Histogram,
ValueType,
} from '@opentelemetry/api-metrics';
import { OnEvent } from '@nestjs/event-emitter';
Expand All @@ -20,23 +20,23 @@ export class RabbitMqRequestDurationSeconds implements BaseMetric {
name = 'rmq_request_duration_seconds';
description = 'rmq_request_duration_seconds';

private valueRecorder: ValueRecorder;
private histogram: Histogram;

constructor(private readonly metricService: MetricService) {}

async inject(): Promise<void> {
this.valueRecorder = this.metricService
this.histogram = this.metricService
.getProvider()
.getMeter('default')
.createValueRecorder(this.name, {
.createHistogram(this.name, {
...RabbitMqRequestDurationSeconds.metricOptions,
description: this.description,
});
}

@OnEvent(ProducerEvent.RMQ)
onResult(event: ProducerGrpcEvent) {
this.valueRecorder.record(
this.histogram.record(
event.time,
Object.assign(event.labels, this.metricService.getLabels()),
);
Expand Down

0 comments on commit a07fc31

Please sign in to comment.