MCPcopy
hub / github.com/redis/node-redis / OTelChannelSubscribers

Class OTelChannelSubscribers

packages/client/lib/opentelemetry/metrics.ts:195–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193// ---------------------------------------------------------------------------
194
195class OTelChannelSubscribers {
196 readonly #instruments: MetricInstruments;
197 readonly #options: MetricOptions;
198 readonly #unsubscribers: Array<() => void> = [];
199
200 constructor(
201 options: MetricOptions,
202 instruments: MetricInstruments,
203 enabledGroups: MetricGroup[],
204 ) {
205 this.#options = options;
206 this.#instruments = instruments;
207
208 const hasBasic = enabledGroups.includes(METRIC_GROUP.CONNECTION_BASIC);
209 const hasAdvanced = enabledGroups.includes(METRIC_GROUP.CONNECTION_ADVANCED);
210 if (hasBasic) {
211 this.#subscribeConnectionBasic();
212 }
213 if (hasAdvanced) {
214 this.#subscribeConnectionAdvanced();
215 }
216 if (hasBasic || hasAdvanced) {
217 this.#subscribeConnectionClosed(hasBasic, hasAdvanced);
218 }
219 if (enabledGroups.includes(METRIC_GROUP.RESILIENCY)) {
220 this.#subscribeResiliency();
221 }
222 if (enabledGroups.includes(METRIC_GROUP.CLIENT_SIDE_CACHING)) {
223 this.#subscribeClientSideCache();
224 }
225 if (enabledGroups.includes(METRIC_GROUP.PUBSUB)) {
226 this.#subscribePubSub();
227 }
228 if (enabledGroups.includes(METRIC_GROUP.PUBSUB) || enabledGroups.includes(METRIC_GROUP.STREAMING)) {
229 this.#subscribeCommandReply(enabledGroups);
230 }
231 }
232
233 #sub(name: string, handler: (ctx: any) => void) {
234 const ch = getChannel(name);
235 if (!ch) return;
236 ch.subscribe(handler);
237 this.#unsubscribers.push(() => ch.unsubscribe(handler));
238 }
239
240 destroy() {
241 this.#unsubscribers.forEach(fn => fn());
242 }
243
244 // -- Connection Basic --
245
246 #subscribeConnectionBasic() {
247 this.#sub(CHANNELS.CONNECTION_READY, (ctx: any) => {
248 const clientAttributes = resolveClientAttributes(ctx.clientId);
249 this.#instruments.dbClientConnectionCreateTime.record(
250 ctx.createTimeMs / 1000,
251 {
252 ...this.#options.attributes,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected