Skip to content

Commit

Permalink
Merge pull request #480 from pragmaticivan/replace-MetricAttributes
Browse files Browse the repository at this point in the history
chore: replace deprecated MetricAttributes
  • Loading branch information
pragmaticivan authored May 8, 2024
2 parents 54c4a7e + c3e2409 commit 1531c83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/interfaces/opentelemetry-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModuleMetadata, Type, Abstract } from '@nestjs/common';
import { MetricAttributes } from '@opentelemetry/api';
import { Attributes } from '@opentelemetry/api';
import { RouteInfo } from '@nestjs/common/interfaces';

export type OpenTelemetryModuleOptions = {
Expand Down Expand Up @@ -45,7 +45,7 @@ export type OpenTelemetryMetrics = {
hostMetrics?: boolean;
apiMetrics?: {
enable?: boolean;
defaultAttributes?: MetricAttributes;
defaultAttributes?: Attributes;
ignoreRoutes?: (string | RouteInfo)[];
ignoreUndefinedRoutes?: boolean;
};
Expand Down
10 changes: 5 additions & 5 deletions src/middleware/api-metrics.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Inject, Injectable, NestMiddleware } from '@nestjs/common';
import responseTime from 'response-time';
import * as urlParser from 'url';
import { Counter, MetricAttributes, Histogram, UpDownCounter } from '@opentelemetry/api';
import { Counter, Attributes, Histogram, UpDownCounter } from '@opentelemetry/api';
import { OpenTelemetryModuleOptions } from '../interfaces';
import { MetricService } from '../metrics/metric.service';
import { OPENTELEMETRY_MODULE_OPTIONS } from '../opentelemetry.constants';

@Injectable()
export class ApiMetricsMiddleware implements NestMiddleware {
private defaultMetricAttributes: MetricAttributes;
private defaultAttributes: Attributes;

private httpServerRequestCount: Counter;

Expand Down Expand Up @@ -37,7 +37,7 @@ export class ApiMetricsMiddleware implements NestMiddleware {
const { defaultAttributes = {}, ignoreUndefinedRoutes = false } =
options?.metrics?.apiMetrics ?? {};

this.defaultMetricAttributes = defaultAttributes;
this.defaultAttributes = defaultAttributes;
this.ignoreUndefinedRoutes = ignoreUndefinedRoutes;

// Semantic Convention
Expand Down Expand Up @@ -114,11 +114,11 @@ export class ApiMetricsMiddleware implements NestMiddleware {
const responseLength: number = parseInt(res.getHeader('Content-Length'), 10) || 0;

const status = res.statusCode || 500;
const attributes: MetricAttributes = {
const attributes: Attributes = {
method,
status,
path,
...this.defaultMetricAttributes,
...this.defaultAttributes,
};

this.httpServerRequestSize.record(requestLength, attributes);
Expand Down

0 comments on commit 1531c83

Please sign in to comment.