Skip to content

Commit f67fefb

Browse files
committed
add noop metrics
1 parent 242e98d commit f67fefb

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

packages/client/lib/opentelemetry/metrics.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import {
1515
HistogramInstrumentConfig,
1616
MetricErrorType,
1717
OTelClientAttributes,
18+
IOTelMetrics,
1819
} from "./types";
1920
import { createNoopMeter } from "./noop-meter";
2021
import { noopFunction } from "./utils";
22+
import { NoopOTelMetrics } from "./noop-metrics";
2123

22-
export class OTelMetrics {
24+
export class OTelMetrics implements IOTelMetrics {
2325
// Create a noop instance by default
24-
static #instance: OTelMetrics = new OTelMetrics({
25-
api: undefined,
26-
config: undefined,
27-
});
26+
static #instance: IOTelMetrics = new NoopOTelMetrics();
2827
static #initialized = false;
2928

3029
readonly #meter: Meter;
@@ -70,6 +69,10 @@ export class OTelMetrics {
7069
OTelMetrics.#initialized = false;
7170
}
7271

72+
public static isInitialized() {
73+
return OTelMetrics.#initialized;
74+
}
75+
7376
static get instance() {
7477
return OTelMetrics.#instance;
7578
}
@@ -196,11 +199,10 @@ export class OTelMetrics {
196199
}
197200

198201
private isCommandExcluded(commandName: string) {
199-
const upperCommandName = commandName?.toUpperCase();
200202
return (
201203
(this.#options.includeCommands.length > 0 &&
202-
!this.#options.includeCommands.includes(upperCommandName)) ||
203-
this.#options.excludeCommands.includes(upperCommandName)
204+
!this.#options.includeCommands.includes(commandName)) ||
205+
this.#options.excludeCommands.includes(commandName)
204206
);
205207
}
206208

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { RedisArgument } from "../..";
2+
import { MetricErrorType, OTelClientAttributes, IOTelMetrics } from "./types";
3+
import { noopFunction } from "./utils";
4+
5+
export class NoopOTelMetrics implements IOTelMetrics {
6+
createRecordOperationDuration(
7+
_args: ReadonlyArray<RedisArgument>,
8+
_clientAttributes?: OTelClientAttributes
9+
): (error?: Error) => void {
10+
return noopFunction;
11+
}
12+
13+
recordConnectionCount(
14+
_value: number,
15+
_clientAttributes?: OTelClientAttributes
16+
) {}
17+
18+
recordConnectionCreateTime(
19+
_durationMs: number,
20+
_clientAttributes?: OTelClientAttributes
21+
) {}
22+
23+
recordConnectionRelaxedTimeout(
24+
_value: number,
25+
_clientAttributes?: OTelClientAttributes
26+
) {}
27+
28+
recordConnectionHandoff(_clientAttributes: OTelClientAttributes) {}
29+
30+
recordClientErrorsHandled(
31+
_type: MetricErrorType,
32+
_clientAttributes?: OTelClientAttributes
33+
) {}
34+
35+
recordMaintenanceNotifications(_clientAttributes: OTelClientAttributes) {}
36+
37+
recordPendingRequests(
38+
_value: number,
39+
_clientAttributes?: OTelClientAttributes
40+
) {}
41+
}

packages/client/lib/opentelemetry/types.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
MeterProvider,
66
UpDownCounter,
77
} from "@opentelemetry/api";
8+
import { RedisArgument } from "../RESP/types";
89

910
export const METRIC_GROUP = {
1011
COMMAND: "command",
@@ -208,3 +209,32 @@ export const METRIC_ERROR_TYPE = {
208209

209210
export type MetricErrorType =
210211
(typeof METRIC_ERROR_TYPE)[keyof typeof METRIC_ERROR_TYPE];
212+
213+
export interface IOTelMetrics {
214+
createRecordOperationDuration(
215+
args: ReadonlyArray<RedisArgument>,
216+
clientAttributes?: OTelClientAttributes
217+
): (error?: Error) => void;
218+
recordConnectionCount(
219+
value: number,
220+
clientAttributes?: OTelClientAttributes
221+
): void;
222+
recordConnectionCreateTime(
223+
durationMs: number,
224+
clientAttributes?: OTelClientAttributes
225+
): void;
226+
recordConnectionRelaxedTimeout(
227+
value: number,
228+
clientAttributes?: OTelClientAttributes
229+
): void;
230+
recordConnectionHandoff(clientAttributes: OTelClientAttributes): void;
231+
recordClientErrorsHandled(
232+
type: MetricErrorType,
233+
clientAttributes?: OTelClientAttributes
234+
): void;
235+
recordMaintenanceNotifications(clientAttributes: OTelClientAttributes): void;
236+
recordPendingRequests(
237+
value: number,
238+
clientAttributes?: OTelClientAttributes
239+
): void;
240+
}

0 commit comments

Comments
 (0)