diff --git a/src/interfaces/opentelemetry-options.interface.ts b/src/interfaces/opentelemetry-options.interface.ts index 821980d..505386b 100644 --- a/src/interfaces/opentelemetry-options.interface.ts +++ b/src/interfaces/opentelemetry-options.interface.ts @@ -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 = { @@ -45,7 +45,7 @@ export type OpenTelemetryMetrics = { hostMetrics?: boolean; apiMetrics?: { enable?: boolean; - defaultAttributes?: MetricAttributes; + defaultAttributes?: Attributes; ignoreRoutes?: (string | RouteInfo)[]; ignoreUndefinedRoutes?: boolean; }; diff --git a/src/middleware/api-metrics.middleware.ts b/src/middleware/api-metrics.middleware.ts index 83cf9a1..6e8997f 100644 --- a/src/middleware/api-metrics.middleware.ts +++ b/src/middleware/api-metrics.middleware.ts @@ -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; @@ -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 @@ -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);